diff --git a/README.md b/README.md index d62b836..243a9ce 100644 --- a/README.md +++ b/README.md @@ -597,6 +597,7 @@ usage: grammar_file_path [source_file_path] options: --source: source text + --packrat: enable packrat memoise --ast: show AST tree --opt, --opt-all: optimaze all AST nodes except nodes selected with `no_ast_opt` instruction --opt-only: optimaze only AST nodes selected with `no_ast_opt` instruction diff --git a/lint/README.md b/lint/README.md index d6da622..1d88b10 100644 --- a/lint/README.md +++ b/lint/README.md @@ -8,6 +8,7 @@ usage: grammar_file_path [source_file_path] options: --ast: show AST tree + --packrat: enable packrat memoise --opt, --opt-all: optimaze all AST nodes except nodes selected with `no_ast_opt` instruction --opt-only: optimaze only AST nodes selected with `no_ast_opt` instruction --source: source text diff --git a/lint/peglint.cc b/lint/peglint.cc index 1131207..72e2888 100644 --- a/lint/peglint.cc +++ b/lint/peglint.cc @@ -33,6 +33,7 @@ inline vector split(const string &s, char delim) { } int main(int argc, const char **argv) { + auto opt_packrat = false; auto opt_ast = false; auto opt_optimize = false; auto opt_mode = true; @@ -47,6 +48,8 @@ int main(int argc, const char **argv) { auto arg = argv[argi++]; if (string("--help") == arg) { opt_help = true; + } else if (string("--packrat") == arg) { + opt_packrat = true; } else if (string("--ast") == arg) { opt_ast = true; } else if (string("--opt") == arg || string("--opt-all") == arg) { @@ -73,6 +76,7 @@ int main(int argc, const char **argv) { options: --source: source text + --packrat: enable packrat memoise --ast: show AST tree --opt, --opt-all: optimaze all AST nodes except nodes selected with `no_ast_opt` instruction --opt-only: optimaze only AST nodes selected with `no_ast_opt` instruction @@ -115,6 +119,10 @@ int main(int argc, const char **argv) { cerr << source_path << ":" << ln << ":" << col << ": " << msg << endl; }; + if (opt_packrat) { + parser.enable_packrat_parsing(); + } + if (opt_trace) { size_t prev_pos = 0; parser.enable_trace(