Added attribute sugar for object attributes

This commit is contained in:
Jonathan Turner
2009-06-20 15:43:31 +00:00
parent e3db4d3595
commit 975d8c9618
3 changed files with 13 additions and 5 deletions

View File

@@ -26,7 +26,7 @@ namespace chaiscript
"Square_Open", "Square_Close", "Curly_Open", "Curly_Close", "Comma", "Quoted_String", "Single_Quoted_String", "Carriage_Return", "Semicolon",
"Function_Def", "Lambda_Def", "Scoped_Block", "Statement", "Equation", "Return", "Expression", "Term", "Factor", "Negate", "Not", "Comment",
"Value", "Fun_Call", "Method_Call", "Comparison", "If_Block", "While_Block", "Boolean", "Real Number", "Array_Call", "Variable_Decl", "Array_Init", "Map_Init",
"For_Block", "Prefix", "Break", "Map_Pair" };
"For_Block", "Prefix", "Break", "Map_Pair"};
return token_types[tokentype];
}

View File

@@ -173,7 +173,7 @@ namespace chaiscript
Id(TokenType::Single_Quoted_String) ;
funcall = Id(TokenType::Identifier) >> Ign(Id(TokenType::Parens_Open)) >> ~(boolean >> *(Ign(Str("," )) >> boolean)) >> Ign(Id(TokenType::Parens_Close));
methodcall = value >> +(Ign(Str(".")) >> funcall);
methodcall = value >> +(Ign(Str(".")) >> (funcall | Id(TokenType::Identifier)));
negate = (Str("-") >> (boolean | arraycall));
boolean_not = (Str("!") >> (boolean | arraycall));
prefix = (Str("++") >> (boolean | arraycall)) | (Str("--") >> (boolean | arraycall));

View File

@@ -274,19 +274,27 @@ namespace chaiscript
plb << eval_token(ss, node->children[i]->children[j]);
}
std::string fun_name;
if (node->children[i]->identifier == TokenType::Fun_Call) {
fun_name = node->children[i]->children[0]->text;
}
else {
fun_name = node->children[i]->text;
}
try {
fn = ss.get_function(node->children[i]->children[0]->text);
fn = ss.get_function(fun_name);
ss.set_stack(new_stack);
retval = dispatch(fn, plb);
ss.set_stack(prev_stack);
}
catch(EvalError &ee) {
ss.set_stack(prev_stack);
throw EvalError(ee.reason, node->children[0]);
throw EvalError(ee.reason, node);
}
catch(std::exception &e){
ss.set_stack(prev_stack);
throw EvalError("Can not find appropriate '" + node->children[i]->children[0]->text + "'", node->children[0]);
throw EvalError("Can not find appropriate '" + fun_name + "'", node);
}
catch(ReturnValue &rv) {
ss.set_stack(prev_stack);