diff --git a/chaiscript/chaiscript.hpp b/chaiscript/chaiscript.hpp index 87a1942..afcb32b 100644 --- a/chaiscript/chaiscript.hpp +++ b/chaiscript/chaiscript.hpp @@ -40,13 +40,13 @@ 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, Prefix, Break, Map_Pair, Value_Range, - Inline_Range }; }; + Inline_Range, Annotation }; }; 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", "Prefix", "Break", "Map_Pair", "Value_Range", - "Inline_Range" }; + "Inline_Range", "Annotation"}; return token_types[tokentype]; } @@ -71,6 +71,7 @@ namespace chaiscript File_Position start, end; std::vector children; + TokenPtr annotation; Token(const std::string &token_text, int id, const char *fname) : text(token_text), identifier(id), filename(fname) { } diff --git a/chaiscript/chaiscript_parser.hpp b/chaiscript/chaiscript_parser.hpp index 7b56276..85aff5e 100644 --- a/chaiscript/chaiscript_parser.hpp +++ b/chaiscript/chaiscript_parser.hpp @@ -217,6 +217,33 @@ namespace chaiscript } } + bool Annotation() { + std::string::iterator start = input_pos; + int prev_col = col; + int prev_line = line; + if (Symbol_("#")) { + do { + while (input_pos != input_end) { + if (Eol_()) { + break; + } + else { + ++col; + ++input_pos; + } + } + } while (Symbol_("#")); + + std::string match(start, input_pos); + TokenPtr t(new Token(match, Token_Type::Annotation, filename, prev_line, prev_col, line, col)); + match_stack.push_back(t); + return true; + } + else { + return false; + } + } + bool Quoted_String_() { bool retval = false; char prev_char = 0; @@ -667,6 +694,16 @@ namespace chaiscript bool Def() { bool retval = false; + bool is_annotated = false; + + TokenPtr annotation; + + if (Annotation()) { + while (Eol_()); + annotation = match_stack.back(); + match_stack.pop_back(); + is_annotated = true; + } int prev_stack_top = match_stack.size(); @@ -698,6 +735,10 @@ namespace chaiscript } build_match(Token_Type::Def, prev_stack_top); + + if (is_annotated) { + match_stack.back()->annotation = annotation; + } } return retval; @@ -913,18 +954,6 @@ namespace chaiscript return retval; } - /* - * TODO: Look into if we need an explicit LHS for equations - bool LHS() { - if (Var_Decl() || Id()) { - return true; - } - else { - return false; - } - } - */ - bool Var_Decl() { bool retval = false;