mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-23 04:15:31 +00:00
Code cleanup and fixed build error.
This commit is contained in:
parent
b91efa1489
commit
ab3d8b0d0e
@ -77,26 +77,26 @@ peg& get_parser()
|
|||||||
/*
|
/*
|
||||||
Definition, Tag Optimize
|
Definition, Tag Optimize
|
||||||
---------------------- ------------------ ---------- */
|
---------------------- ------------------ ---------- */
|
||||||
{ "STATEMENTS", Statements },
|
{ "STATEMENTS", Statements, false },
|
||||||
{ "WHILE", While },
|
{ "WHILE", While, false },
|
||||||
{ "ASSIGNMENT", Assignment },
|
{ "ASSIGNMENT", Assignment, false },
|
||||||
{ "IF", If },
|
{ "IF", If, false },
|
||||||
{ "FUNCTION", Function },
|
{ "FUNCTION", Function, false },
|
||||||
{ "PARAMETERS", Default },
|
{ "PARAMETERS", Default, false },
|
||||||
{ "FUNCTION_CALL", FunctionCall },
|
{ "FUNCTION_CALL", FunctionCall, false },
|
||||||
{ "ARGUMENTS", Default },
|
{ "ARGUMENTS", Default, false },
|
||||||
{ "PRIMARY", LogicalOr, true },
|
{ "PRIMARY", LogicalOr, true },
|
||||||
{ "LOGICAL_OR", LogicalAnd, true },
|
{ "LOGICAL_OR", LogicalAnd, true },
|
||||||
{ "LOGICAL_AND", Condition, true },
|
{ "LOGICAL_AND", Condition, true },
|
||||||
{ "CONDITION", BinExpresion, true },
|
{ "CONDITION", BinExpresion, true },
|
||||||
{ "TERM", UnaryPlus, true },
|
{ "TERM", UnaryPlus, true },
|
||||||
{ "UNARY_PLUS", UnaryMinus, true },
|
{ "UNARY_PLUS", UnaryMinus, true },
|
||||||
{ "UNARY_MINUS", UnaryNot, true },
|
{ "UNARY_MINUS", UnaryNot, true },
|
||||||
{ "UNARY_NOT", BinExpresion, true },
|
{ "UNARY_NOT", BinExpresion, true },
|
||||||
{ "NUMBER", Number },
|
{ "NUMBER", Number, false },
|
||||||
{ "BOOLEAN", Boolean },
|
{ "BOOLEAN", Boolean, false },
|
||||||
{ "IDENTIFIER", Identifier },
|
{ "IDENTIFIER", Identifier, false },
|
||||||
{ "INTERPOLATED_STRING", InterpolatedString },
|
{ "INTERPOLATED_STRING", InterpolatedString, false },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
enum AstTag
|
enum AstTag
|
||||||
{
|
{
|
||||||
Default = peglib::Ast::DefaultTag,
|
Default = peglib::AstDefaultTag,
|
||||||
Statements, While, If, FunctionCall, Assignment,
|
Statements, While, If, FunctionCall, Assignment,
|
||||||
LogicalOr, LogicalAnd, Condition, UnaryPlus, UnaryMinus, UnaryNot, BinExpresion,
|
LogicalOr, LogicalAnd, Condition, UnaryPlus, UnaryMinus, UnaryNot, BinExpresion,
|
||||||
Identifier, InterpolatedString,
|
Identifier, InterpolatedString,
|
||||||
|
12
peglib.h
12
peglib.h
@ -1832,10 +1832,10 @@ private:
|
|||||||
* AST
|
* AST
|
||||||
*---------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
const int AstDefaultTag = -1;
|
||||||
|
|
||||||
struct Ast
|
struct Ast
|
||||||
{
|
{
|
||||||
static const int DefaultTag = -1;
|
|
||||||
|
|
||||||
Ast(const char* _name, int _tag, const std::vector<std::shared_ptr<Ast>>& _nodes)
|
Ast(const char* _name, int _tag, const std::vector<std::shared_ptr<Ast>>& _nodes)
|
||||||
: name(_name), tag(_tag), is_token(false), nodes(_nodes) {}
|
: name(_name), tag(_tag), is_token(false), nodes(_nodes) {}
|
||||||
|
|
||||||
@ -2020,7 +2020,7 @@ public:
|
|||||||
return (*grammar_)[s];
|
return (*grammar_)[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
void packrat_parsing(bool sw) {
|
void enable_packrat_parsing(bool sw) {
|
||||||
if (grammar_ != nullptr) {
|
if (grammar_ != nullptr) {
|
||||||
auto& rule = (*grammar_)[start_];
|
auto& rule = (*grammar_)[start_];
|
||||||
rule.enablePackratParsing = sw;
|
rule.enablePackratParsing = sw;
|
||||||
@ -2029,7 +2029,7 @@ public:
|
|||||||
|
|
||||||
struct AstNodeInfo {
|
struct AstNodeInfo {
|
||||||
const char* name;
|
const char* name;
|
||||||
int tag;
|
int tag; // TODO: It should be calculated at compile-time from 'name' with constexpr hash function.
|
||||||
bool optimize;
|
bool optimize;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2083,13 +2083,13 @@ private:
|
|||||||
if (!action) {
|
if (!action) {
|
||||||
action = [name](const SemanticValues& sv) {
|
action = [name](const SemanticValues& sv) {
|
||||||
if (sv.is_token()) {
|
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) {
|
if (sv.size() == 1) {
|
||||||
std::shared_ptr<Ast> ast = sv[0].get<std::shared_ptr<Ast>>();
|
std::shared_ptr<Ast> ast = sv[0].get<std::shared_ptr<Ast>>();
|
||||||
return 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++;
|
count++;
|
||||||
};
|
};
|
||||||
|
|
||||||
parser.packrat_parsing(true);
|
parser.enable_packrat_parsing(true);
|
||||||
|
|
||||||
bool ret = parser.parse("Hello Two");
|
bool ret = parser.parse("Hello Two");
|
||||||
REQUIRE(ret == true);
|
REQUIRE(ret == true);
|
||||||
|
Loading…
Reference in New Issue
Block a user