-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rename files * add extension * add extension test * refactor peg grammar program * update parser extension test * update deps * update travis * update Glue * v1.5
- Loading branch information
1 parent
3e90a90
commit 6589ec5
Showing
22 changed files
with
286 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
@PACKAGE_INIT@ | ||
|
||
include(CMakeFindDependencyMacro) | ||
|
||
find_dependency(LHC) | ||
|
||
if(@BUILD_LARS_PARSER_GLUE_EXTENSION@) | ||
find_dependency(Glue) | ||
endif() | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/LarsParserTargets.cmake") | ||
check_required_components("@PROJECT_NAME@") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <lars/glue.h> | ||
|
||
namespace lars{ | ||
namespace extensions{ | ||
std::shared_ptr<Extension> parser(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <lars/parser/extension.h> | ||
#include <lars/parser/generator.h> | ||
#include <stdexcept> | ||
#include <lars/log.h> | ||
|
||
std::shared_ptr<lars::Extension> lars::extensions::parser(){ | ||
using namespace lars; | ||
|
||
using ParserGenerator = lars::ParserGenerator<Any,Any&>; | ||
using Expression = ParserGenerator::Expression; | ||
|
||
auto expressionExtension = std::make_shared<Extension>(); | ||
expressionExtension->set_class<ParserGenerator::Expression>(); | ||
|
||
expressionExtension->add_function("evaluate", [](Expression &e,Any &d){ | ||
return e.evaluate(d); | ||
}); | ||
|
||
expressionExtension->add_function("size", [](Expression &e)->unsigned{ | ||
return e.size(); | ||
}); | ||
|
||
expressionExtension->add_function("get", [](Expression &e, unsigned i){ | ||
if (i < e.size()) { | ||
return e[i]; | ||
} else { | ||
throw std::runtime_error("invalid expression index"); | ||
} | ||
}); | ||
|
||
expressionExtension->add_function("string", [](Expression &e){ | ||
return e.string(); | ||
}); | ||
|
||
expressionExtension->add_function("position", [](Expression &e){ | ||
return e.position(); | ||
}); | ||
|
||
expressionExtension->add_function("length", [](Expression &e){ | ||
return e.length(); | ||
}); | ||
|
||
auto parserGeneratorExtension = std::make_shared<Extension>(); | ||
parserGeneratorExtension->set_class<ParserGenerator>(); | ||
parserGeneratorExtension->add_function("create", [](){ return ParserGenerator(); }); | ||
|
||
parserGeneratorExtension->add_function("run", [](ParserGenerator &g, const std::string &str, Any& arg){ | ||
return g.run(str, arg); | ||
}); | ||
|
||
parserGeneratorExtension->add_function("setRule",[](ParserGenerator &g, const std::string &name, const std::string &grammar){ | ||
return g.setRule(name, grammar); | ||
}); | ||
|
||
parserGeneratorExtension->add_function("setRuleWithCallback",[](ParserGenerator &g, const std::string &name, const std::string &grammar, AnyFunction callback){ | ||
return g.setRule(name, grammar, [callback](auto e, Any v){ | ||
return callback(e, v); | ||
}); | ||
}); | ||
|
||
parserGeneratorExtension->add_function("setStartRule", [](ParserGenerator &g, const std::string &name){ | ||
g.setStart(g.getRule(name)); | ||
}); | ||
|
||
parserGeneratorExtension->add_function("setSeparatorRule", [](ParserGenerator &g, const std::string &name){ | ||
g.setSeparator(g.getRule(name)); | ||
}); | ||
|
||
auto extension = std::make_shared<Extension>(); | ||
extension->add_extension("Program", parserGeneratorExtension); | ||
extension->add_extension("Expression", expressionExtension); | ||
|
||
return extension; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.