diff --git a/chaiscript/chaiscript.hpp b/chaiscript/chaiscript.hpp index a3de3b0..7bae7c9 100644 --- a/chaiscript/chaiscript.hpp +++ b/chaiscript/chaiscript.hpp @@ -39,12 +39,12 @@ namespace chaiscript */ class Token_Type { public: enum Type { Error, Int, Float, Id, Char, Str, Eol, Fun_Call, Arg_List, Variable, Equation, Var_Decl, Expression, Comparison, Additive, Multiplicative, Negate, Not, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String, - Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File }; }; + Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix }; }; const char *token_type_to_string(int tokentype) { const char *token_types[] = { "Internal Parser Error", "Int", "Float", "Id", "Char", "Str", "Eol", "Fun_Call", "Arg_List", "Variable", "Equation", "Var_Decl", "Expression", "Comparison", "Additive", "Multiplicative", "Negate", "Not", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String", - "Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File" }; + "Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix" }; return token_types[tokentype]; } diff --git a/chaiscript/chaiscript_eval.hpp b/chaiscript/chaiscript_eval.hpp index 768a330..413e237 100644 --- a/chaiscript/chaiscript_eval.hpp +++ b/chaiscript/chaiscript_eval.hpp @@ -153,7 +153,6 @@ namespace chaiscript retval = dispatchkit::Boxed_Value(!cond); } break; - /* case (Token_Type::Prefix) : { retval = eval_token(ss, node->children[1]); dispatchkit::Param_List_Builder plb; @@ -167,7 +166,6 @@ namespace chaiscript } } break; - */ case (Token_Type::Inline_Array) : { try { retval = dispatch(ss.get_function("Vector"), dispatchkit::Param_List_Builder()); diff --git a/chaiscript/chaiscript_parser.hpp b/chaiscript/chaiscript_parser.hpp index d575a5f..ec09c8e 100644 --- a/chaiscript/chaiscript_parser.hpp +++ b/chaiscript/chaiscript_parser.hpp @@ -542,10 +542,12 @@ namespace chaiscript line = prev_line; return false; } - std::string match(start, input_pos); - TokenPtr t(new Token(match, Token_Type::Str, filename, prev_line, prev_col, line, col)); - match_stack.push_back(t); - return true; + else { + std::string match(start, input_pos); + TokenPtr t(new Token(match, Token_Type::Str, filename, prev_line, prev_col, line, col)); + match_stack.push_back(t); + return true; + } } else { return false; @@ -905,7 +907,7 @@ namespace chaiscript } bool Value() { - if (Var_Decl() || Lambda() || Id_Fun_Array() || Num(true) || Negate() || Not() || Quoted_String(true) || Single_Quoted_String(true) || + if (Var_Decl() || Lambda() || Id_Fun_Array() || Num(true) || Prefix() || Quoted_String(true) || Single_Quoted_String(true) || Paren_Expression() || Inline_Container() || Id_Literal()) { return true; } @@ -914,7 +916,7 @@ namespace chaiscript } } - bool Negate() { + bool Prefix() { bool retval = false; int prev_stack_top = match_stack.size(); @@ -928,17 +930,7 @@ namespace chaiscript build_match(Token_Type::Negate, prev_stack_top); } - - return retval; - - } - - bool Not() { - bool retval = false; - - int prev_stack_top = match_stack.size(); - - if (Symbol("!")) { + else if (Symbol("!")) { retval = true; if (!Expression()) { @@ -947,6 +939,24 @@ namespace chaiscript build_match(Token_Type::Not, prev_stack_top); } + if (Symbol("++", true)) { + retval = true; + + if (!Expression()) { + throw Parse_Error("Incomplete '++' expression", File_Position(line, col), filename); + } + + build_match(Token_Type::Prefix, prev_stack_top); + } + else if (Symbol("--", true)) { + retval = true; + + if (!Expression()) { + throw Parse_Error("Incomplete '--' expression", File_Position(line, col), filename); + } + + build_match(Token_Type::Prefix, prev_stack_top); + } return retval;