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

@@ -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);