Fixed build errors.

This commit is contained in:
yhirose 2015-07-31 19:07:20 -04:00
parent 65d1d99b2b
commit 02957c3668
2 changed files with 7 additions and 5 deletions

View File

@ -89,13 +89,14 @@ int main(int argc, const char** argv)
}; };
if (opt_ast) { if (opt_ast) {
peg.enable_ast(opt_optimize_ast_nodes); peg.enable_ast();
std::shared_ptr<peglib::Ast> ast; std::shared_ptr<peglib::Ast> ast;
if (!peg.parse_n(source.data(), source.size(), ast)) { if (!peg.parse_n(source.data(), source.size(), ast)) {
return -1; return -1;
} }
ast = peglib::AstOptimizer(opt_optimize_ast_nodes).optimize(ast);
peglib::AstPrint().print(*ast); peglib::AstPrint().print(*ast);
} else { } else {
if (!peg.parse_n(source.data(), source.size())) { if (!peg.parse_n(source.data(), source.size())) {

View File

@ -453,7 +453,7 @@ TEST_CASE("Calculator test with AST", "[general]")
" ~_ <- [ \t\r\n]* " " ~_ <- [ \t\r\n]* "
); );
parser.enable_ast(true); parser.enable_ast();
function<long (const Ast&)> eval = [&](const Ast& ast) { function<long (const Ast&)> eval = [&](const Ast& ast) {
if (ast.name == "NUMBER") { if (ast.name == "NUMBER") {
@ -477,6 +477,7 @@ TEST_CASE("Calculator test with AST", "[general]")
shared_ptr<Ast> ast; shared_ptr<Ast> ast;
auto ret = parser.parse("1+2*3*(4-5+6)/7-8", ast); auto ret = parser.parse("1+2*3*(4-5+6)/7-8", ast);
ast = peglib::AstOptimizer(true).optimize(ast);
auto val = eval(*ast); auto val = eval(*ast);
REQUIRE(ret == true); REQUIRE(ret == true);
@ -492,7 +493,7 @@ TEST_CASE("Ignore semantic value test", "[general]")
" _ <- [ \t\r\n]* " " _ <- [ \t\r\n]* "
); );
parser.enable_ast(false); parser.enable_ast();
shared_ptr<Ast> ast; shared_ptr<Ast> ast;
auto ret = parser.parse("Hello World", ast); auto ret = parser.parse("Hello World", ast);
@ -512,7 +513,7 @@ TEST_CASE("Ignore semantic value of 'or' predicate test", "[general]")
" ~_ <- [ \t\r\n]* " " ~_ <- [ \t\r\n]* "
); );
parser.enable_ast(false); parser.enable_ast();
shared_ptr<Ast> ast; shared_ptr<Ast> ast;
auto ret = parser.parse("Hello World.", ast); auto ret = parser.parse("Hello World.", ast);
@ -531,7 +532,7 @@ TEST_CASE("Ignore semantic value of 'and' predicate test", "[general]")
" ~_ <- [ \t\r\n]* " " ~_ <- [ \t\r\n]* "
); );
parser.enable_ast(false); parser.enable_ast();
shared_ptr<Ast> ast; shared_ptr<Ast> ast;
auto ret = parser.parse("Hello World.", ast); auto ret = parser.parse("Hello World.", ast);