mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-07 17:26:55 +08:00
Added short form lambda: (x) : { x + 10 }. Fixed eval sample
This commit is contained in:
parent
9f13858482
commit
75431a052b
@ -19,7 +19,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}; };
|
||||
|
||||
const char *tokentype_to_string(int tokentype) {
|
||||
const char *token_types[] = {"File", "Whitespace", "Identifier", "Integer", "Operator", "Parens_Open", "Parens_Close",
|
||||
|
||||
@ -168,7 +168,7 @@ namespace chaiscript
|
||||
expression = term >> *((Str("+") >> term) | (Str("-") >> term));
|
||||
term = factor >> *((Str("*") >> factor) | (Str("/") >> factor));
|
||||
factor = methodcall | arraycall | value | negate | boolean_not | prefix | (Ign(Str("+")) >> value);
|
||||
value = vardecl | mapinit | arrayinit | block | paren_block | lambda_def | return_statement | break_statement |
|
||||
value = vardecl | mapinit | arrayinit | block | lambda_def | paren_block | return_statement | break_statement |
|
||||
funcall | Id(TokenType::Identifier) | Id(TokenType::Real_Number) | Id(TokenType::Integer) | Id(TokenType::Quoted_String) |
|
||||
Id(TokenType::Single_Quoted_String) ;
|
||||
|
||||
@ -187,7 +187,7 @@ namespace chaiscript
|
||||
return_statement = Ign(Str("return")) >> ~boolean;
|
||||
break_statement = Wrap(Ign(Str("break")));
|
||||
paren_block = (Ign(Id(TokenType::Parens_Open)) >> equation >> Ign(Id(TokenType::Parens_Close)));
|
||||
lambda_def = Ign(Str("function")) >> ~(Ign(Id(TokenType::Parens_Open)) >> ~params >> Ign(Id(TokenType::Parens_Close))) >> block;
|
||||
lambda_def = (Ign(Str("function")) >> ~(Ign(Id(TokenType::Parens_Open)) >> ~params >> Ign(Id(TokenType::Parens_Close))) >> block) | (Ign(Id(TokenType::Parens_Open)) >> ~params >> Ign(Id(TokenType::Parens_Close)) >> Ign(Str(":")) >> block);
|
||||
|
||||
return rule;
|
||||
}
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
var i = 1
|
||||
var j = eval("i + 4")
|
||||
var j = eval("5 + 4")
|
||||
print(j)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user