mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Code cleanup and fixed build error.
This commit is contained in:
parent
b91efa1489
commit
ab3d8b0d0e
@ -77,14 +77,14 @@ peg& get_parser()
|
||||
/*
|
||||
Definition, Tag Optimize
|
||||
---------------------- ------------------ ---------- */
|
||||
{ "STATEMENTS", Statements },
|
||||
{ "WHILE", While },
|
||||
{ "ASSIGNMENT", Assignment },
|
||||
{ "IF", If },
|
||||
{ "FUNCTION", Function },
|
||||
{ "PARAMETERS", Default },
|
||||
{ "FUNCTION_CALL", FunctionCall },
|
||||
{ "ARGUMENTS", Default },
|
||||
{ "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 },
|
||||
@ -93,10 +93,10 @@ peg& get_parser()
|
||||
{ "UNARY_PLUS", UnaryMinus, true },
|
||||
{ "UNARY_MINUS", UnaryNot, true },
|
||||
{ "UNARY_NOT", BinExpresion, true },
|
||||
{ "NUMBER", Number },
|
||||
{ "BOOLEAN", Boolean },
|
||||
{ "IDENTIFIER", Identifier },
|
||||
{ "INTERPOLATED_STRING", InterpolatedString },
|
||||
{ "NUMBER", Number, false },
|
||||
{ "BOOLEAN", Boolean, false },
|
||||
{ "IDENTIFIER", Identifier, false },
|
||||
{ "INTERPOLATED_STRING", InterpolatedString, false },
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
12
peglib.h
12
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<std::shared_ptr<Ast>>& _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<Ast>(name.c_str(), Ast::DefaultTag, std::string(sv.s, sv.n));
|
||||
return std::make_shared<Ast>(name.c_str(), AstDefaultTag, std::string(sv.s, sv.n));
|
||||
}
|
||||
if (sv.size() == 1) {
|
||||
std::shared_ptr<Ast> ast = sv[0].get<std::shared_ptr<Ast>>();
|
||||
return ast;
|
||||
}
|
||||
return std::make_shared<Ast>(name.c_str(), Ast::DefaultTag, sv.map<std::shared_ptr<Ast>>());
|
||||
return std::make_shared<Ast>(name.c_str(), AstDefaultTag, sv.map<std::shared_ptr<Ast>>());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user