aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-dataloader/v2script/SimpleGrammar.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-dataloader/v2script/SimpleGrammar.hpp')
-rw-r--r--src/openvic-dataloader/v2script/SimpleGrammar.hpp56
1 files changed, 38 insertions, 18 deletions
diff --git a/src/openvic-dataloader/v2script/SimpleGrammar.hpp b/src/openvic-dataloader/v2script/SimpleGrammar.hpp
index c91935e..3e9a96e 100644
--- a/src/openvic-dataloader/v2script/SimpleGrammar.hpp
+++ b/src/openvic-dataloader/v2script/SimpleGrammar.hpp
@@ -32,7 +32,11 @@ namespace ovdl::v2script::grammar {
struct Identifier {
static constexpr auto rule = lexy::dsl::identifier(data_char_class);
- static constexpr auto value = lexy::as_string<std::string> | lexy::new_<ast::IdentifierNode, ast::NodePtr>;
+ static constexpr auto value = lexy::callback<ast::NodePtr>(
+ [](auto lexeme) {
+ std::string str(lexeme.data(), lexeme.size());
+ return ast::make_node_ptr<ast::IdentifierNode>(ast::NodeLocation { lexeme.begin(), lexeme.end() }, LEXY_MOV(str));
+ });
};
struct StringExpression {
@@ -55,57 +59,73 @@ namespace ovdl::v2script::grammar {
// or a Unicode code point of the form uXXXX.
auto escape = lexy::dsl::backslash_escape //
.symbol<escaped_symbols>();
- return lexy::dsl::quoted(c, escape);
+ return lexy::dsl::delimited(lexy::dsl::position(lexy::dsl::lit_b<'"'>))(c, escape);
}();
- static constexpr auto value = lexy::as_string<std::string> >> lexy::new_<ast::StringNode, ast::NodePtr>;
+ static constexpr auto value =
+ lexy::as_string<std::string> >>
+ lexy::callback<ast::NodePtr>(
+ [](const char* begin, auto&& str, const char* end) {
+ return ast::make_node_ptr<ast::StringNode>(ast::NodeLocation::make_from(begin, end), LEXY_MOV(str));
+ });
};
struct SimpleAssignmentStatement {
static constexpr auto rule =
- lexy::dsl::p<Identifier> >>
+ lexy::dsl::position(lexy::dsl::p<Identifier>) >>
lexy::dsl::equal_sign +
(lexy::dsl::p<Identifier> | lexy::dsl::p<StringExpression> | lexy::dsl::recurse_branch<StatementListBlock>);
static constexpr auto value = lexy::callback<ast::NodePtr>(
- [](auto name, auto&& initalizer) {
- return make_node_ptr<ast::AssignNode>(LEXY_MOV(name), LEXY_MOV(initalizer));
+ [](const char* pos, auto name, auto&& initalizer) {
+ return ast::make_node_ptr<ast::AssignNode>(pos, LEXY_MOV(name), LEXY_MOV(initalizer));
});
};
struct AssignmentStatement {
static constexpr auto rule =
- lexy::dsl::p<Identifier> >>
+ lexy::dsl::position(lexy::dsl::p<Identifier>) >>
(lexy::dsl::equal_sign >>
(lexy::dsl::p<Identifier> | lexy::dsl::p<StringExpression> | lexy::dsl::recurse_branch<StatementListBlock>) |
lexy::dsl::else_ >> lexy::dsl::return_) |
lexy::dsl::p<StringExpression>;
static constexpr auto value = lexy::callback<ast::NodePtr>(
+ [](const char* pos, auto name, lexy::nullopt = {}) {
+ return LEXY_MOV(name);
+ },
[](auto name, lexy::nullopt = {}) {
return LEXY_MOV(name);
},
- [](auto name, auto&& initalizer) {
- return make_node_ptr<ast::AssignNode>(LEXY_MOV(name), LEXY_MOV(initalizer));
+ [](const char* pos, auto name, auto&& initalizer) {
+ return ast::make_node_ptr<ast::AssignNode>(pos, LEXY_MOV(name), LEXY_MOV(initalizer));
});
};
struct StatementListBlock {
static constexpr auto rule =
- lexy::dsl::curly_bracketed(
- lexy::dsl::opt(lexy::dsl::list(lexy::dsl::p<AssignmentStatement>)) + lexy::dsl::opt(lexy::dsl::semicolon));
+ lexy::dsl::position(lexy::dsl::curly_bracketed.open()) >>
+ lexy::dsl::opt(lexy::dsl::list(lexy::dsl::p<AssignmentStatement>)) +
+ lexy::dsl::opt(lexy::dsl::semicolon) >>
+ lexy::dsl::position(lexy::dsl::curly_bracketed.close());
static constexpr auto value =
lexy::as_list<std::vector<ast::NodePtr>> >>
lexy::callback<ast::NodePtr>(
- [](lexy::nullopt = {}, lexy::nullopt = {}) {
- return ast::make_node_ptr<ast::ListNode>();
+ [](const char* begin, lexy::nullopt, const char* end) {
+ return ast::make_node_ptr<ast::ListNode>(ast::NodeLocation::make_from(begin, end));
+ },
+ [](const char* begin, auto&& list, const char* end) {
+ return ast::make_node_ptr<ast::ListNode>(ast::NodeLocation::make_from(begin, end), LEXY_MOV(list));
+ },
+ [](const char* begin, lexy::nullopt, lexy::nullopt, const char* end) {
+ return ast::make_node_ptr<ast::ListNode>(ast::NodeLocation::make_from(begin, end));
},
- [](auto&& list, lexy::nullopt = {}) {
- return make_node_ptr<ast::ListNode>(LEXY_MOV(list));
+ [](const char* begin, auto&& list, lexy::nullopt, const char* end) {
+ return ast::make_node_ptr<ast::ListNode>(ast::NodeLocation::make_from(begin, end), LEXY_MOV(list));
},
- [](auto& list) {
- return make_node_ptr<ast::ListNode>(list);
+ [](const char* begin, auto& list, const char* end) {
+ return ast::make_node_ptr<ast::ListNode>(ast::NodeLocation::make_from(begin, end), list);
});
};
@@ -113,7 +133,7 @@ namespace ovdl::v2script::grammar {
// Allow arbitrary spaces between individual tokens.
static constexpr auto whitespace = whitespace_specifier | comment_specifier;
- static constexpr auto rule = lexy::dsl::terminator(lexy::dsl::eof).list(lexy::dsl::p<AssignmentStatement>);
+ static constexpr auto rule = lexy::dsl::position + lexy::dsl::terminator(lexy::dsl::eof).list(lexy::dsl::p<AssignmentStatement>);
static constexpr auto value = lexy::as_list<std::vector<ast::NodePtr>> >> lexy::new_<ast::FileNode, ast::NodePtr>;
};