From ab3d8b0d0e8b850171ff2215b03503f6f4f0556a Mon Sep 17 00:00:00 2001 From: yhirose Date: Thu, 4 Jun 2015 19:06:37 -0400 Subject: [PATCH] Code cleanup and fixed build error. --- language/parser.cc | 40 ++++++++++++++++++++-------------------- language/parser.hpp | 2 +- peglib.h | 12 ++++++------ test/test.cc | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/language/parser.cc b/language/parser.cc index a1428a8..5ebf5e4 100644 --- a/language/parser.cc +++ b/language/parser.cc @@ -77,26 +77,26 @@ peg& get_parser() /* Definition, Tag Optimize ---------------------- ------------------ ---------- */ - { "STATEMENTS", Statements }, - { "WHILE", While }, - { "ASSIGNMENT", Assignment }, - { "IF", If }, - { "FUNCTION", Function }, - { "PARAMETERS", Default }, - { "FUNCTION_CALL", FunctionCall }, - { "ARGUMENTS", Default }, - { "PRIMARY", LogicalOr, true }, - { "LOGICAL_OR", LogicalAnd, true }, - { "LOGICAL_AND", Condition, true }, - { "CONDITION", BinExpresion, true }, - { "TERM", UnaryPlus, true }, - { "UNARY_PLUS", UnaryMinus, true }, - { "UNARY_MINUS", UnaryNot, true }, - { "UNARY_NOT", BinExpresion, true }, - { "NUMBER", Number }, - { "BOOLEAN", Boolean }, - { "IDENTIFIER", Identifier }, - { "INTERPOLATED_STRING", InterpolatedString }, + { "STATEMENTS", Statements, false }, + { "WHILE", While, false }, + { "ASSIGNMENT", Assignment, false }, + { "IF", If, false }, + { "FUNCTION", Function, false }, + { "PARAMETERS", Default, false }, + { "FUNCTION_CALL", FunctionCall, false }, + { "ARGUMENTS", Default, false }, + { "PRIMARY", LogicalOr, true }, + { "LOGICAL_OR", LogicalAnd, true }, + { "LOGICAL_AND", Condition, true }, + { "CONDITION", BinExpresion, true }, + { "TERM", UnaryPlus, true }, + { "UNARY_PLUS", UnaryMinus, true }, + { "UNARY_MINUS", UnaryNot, true }, + { "UNARY_NOT", BinExpresion, true }, + { "NUMBER", Number, false }, + { "BOOLEAN", Boolean, false }, + { "IDENTIFIER", Identifier, false }, + { "INTERPOLATED_STRING", InterpolatedString, false }, }); } diff --git a/language/parser.hpp b/language/parser.hpp index 88389e0..884fad9 100644 --- a/language/parser.hpp +++ b/language/parser.hpp @@ -2,7 +2,7 @@ enum AstTag { - Default = peglib::Ast::DefaultTag, + Default = peglib::AstDefaultTag, Statements, While, If, FunctionCall, Assignment, LogicalOr, LogicalAnd, Condition, UnaryPlus, UnaryMinus, UnaryNot, BinExpresion, Identifier, InterpolatedString, diff --git a/peglib.h b/peglib.h index 245d8b6..e088647 100644 --- a/peglib.h +++ b/peglib.h @@ -1832,10 +1832,10 @@ private: * AST *---------------------------------------------------------------------------*/ +const int AstDefaultTag = -1; + struct Ast { - static const int DefaultTag = -1; - Ast(const char* _name, int _tag, const std::vector>& _nodes) : name(_name), tag(_tag), is_token(false), nodes(_nodes) {} @@ -2020,7 +2020,7 @@ public: return (*grammar_)[s]; } - void packrat_parsing(bool sw) { + void enable_packrat_parsing(bool sw) { if (grammar_ != nullptr) { auto& rule = (*grammar_)[start_]; rule.enablePackratParsing = sw; @@ -2029,7 +2029,7 @@ public: struct AstNodeInfo { const char* name; - int tag; + int tag; // TODO: It should be calculated at compile-time from 'name' with constexpr hash function. bool optimize; }; @@ -2083,13 +2083,13 @@ private: if (!action) { action = [name](const SemanticValues& sv) { if (sv.is_token()) { - return std::make_shared(name.c_str(), Ast::DefaultTag, std::string(sv.s, sv.n)); + return std::make_shared(name.c_str(), AstDefaultTag, std::string(sv.s, sv.n)); } if (sv.size() == 1) { std::shared_ptr ast = sv[0].get>(); return ast; } - return std::make_shared(name.c_str(), Ast::DefaultTag, sv.map>()); + return std::make_shared(name.c_str(), AstDefaultTag, sv.map>()); }; } } diff --git a/test/test.cc b/test/test.cc index f698b6e..dcd2cd4 100644 --- a/test/test.cc +++ b/test/test.cc @@ -225,7 +225,7 @@ TEST_CASE("Backtracking test", "[general]") count++; }; - parser.packrat_parsing(true); + parser.enable_packrat_parsing(true); bool ret = parser.parse("Hello Two"); REQUIRE(ret == true);