From 757114a3c5b748567b42f273c7b78ca039ae983c Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Tue, 28 Nov 2023 05:09:26 -0500 Subject: Add `deps/dryad` -> https://github.com/Spartan322/dryad Add `deps/fmt` -> https://github.com/fmtlib/fmt Add `deps/range-v3` -> https://github.com/ericniebler/range-v3 Improve parser error and warning support Update .clang-format Update `deps/SCsub` --- .../v2script/LuaDefinesGrammar.hpp | 82 +++++++++++----------- 1 file changed, 40 insertions(+), 42 deletions(-) (limited to 'src/openvic-dataloader/v2script/LuaDefinesGrammar.hpp') diff --git a/src/openvic-dataloader/v2script/LuaDefinesGrammar.hpp b/src/openvic-dataloader/v2script/LuaDefinesGrammar.hpp index b64d0f9..4d27d3e 100644 --- a/src/openvic-dataloader/v2script/LuaDefinesGrammar.hpp +++ b/src/openvic-dataloader/v2script/LuaDefinesGrammar.hpp @@ -1,11 +1,25 @@ #pragma once +#include #include +#include "openvic-dataloader/v2script/AbstractSyntaxTree.hpp" + #include "SimpleGrammar.hpp" -#include "detail/LexyLitRange.hpp" +#include "detail/dsl.hpp" namespace ovdl::v2script::lua::grammar { + template + constexpr auto callback(Callback... cb) { + return dsl::callback(cb...); + } + + template + constexpr auto construct = v2script::grammar::construct; + + template + constexpr auto construct_list = v2script::grammar::construct_list; + struct ParseOptions { }; @@ -17,20 +31,20 @@ namespace ovdl::v2script::lua::grammar { template struct Identifier { static constexpr auto rule = lexy::dsl::identifier(lexy::dsl::ascii::alpha_underscore, lexy::dsl::ascii::alpha_digit_underscore); - static constexpr auto value = lexy::callback( - [](auto lexeme) { - std::string str(lexeme.data(), lexeme.size()); - return ast::make_node_ptr(ast::NodeLocation { lexeme.begin(), lexeme.end() }, LEXY_MOV(str)); + static constexpr auto value = callback( + [](ast::ParseState& state, auto lexeme) { + auto value = state.ast().intern(lexeme.data(), lexeme.size()); + return state.ast().create(lexeme.begin(), lexeme.end(), value); }); }; template struct Value { static constexpr auto rule = lexy::dsl::identifier(lexy::dsl::ascii::digit / lexy::dsl::lit_c<'.'> / lexy::dsl::lit_c<'-'>); - static constexpr auto value = lexy::callback( - [](auto lexeme) { - std::string str(lexeme.data(), lexeme.size()); - return ast::make_node_ptr(ast::NodeLocation { lexeme.begin(), lexeme.end() }, LEXY_MOV(str)); + static constexpr auto value = callback( + [](ast::ParseState& state, auto lexeme) { + auto value = state.ast().intern(lexeme.data(), lexeme.size()); + return state.ast().create(lexeme.begin(), lexeme.end(), value); }); }; @@ -38,66 +52,50 @@ namespace ovdl::v2script::lua::grammar { struct String { static constexpr auto rule = [] { // Arbitrary code points that aren't control characters. - auto c = ovdl::detail::lexydsl::make_range<0x20, 0xFF>() - lexy::dsl::ascii::control; + auto c = dsl::make_range<0x20, 0xFF>() - lexy::dsl::ascii::control; return lexy::dsl::delimited(lexy::dsl::position(lexy::dsl::lit_b<'"'>))(c) | lexy::dsl::delimited(lexy::dsl::position(lexy::dsl::lit_b<'\''>))(c); }(); static constexpr auto value = lexy::as_string >> - lexy::callback( - [](const char* begin, auto&& str, const char* end) { - return ast::make_node_ptr(ast::NodeLocation::make_from(begin, end), LEXY_MOV(str)); + callback( + [](ast::ParseState& state, const char* begin, const std::string& str, const char* end) { + auto value = state.ast().intern(str.data(), str.length()); + return state.ast().create(begin, end, value); }); }; template struct Expression { static constexpr auto rule = lexy::dsl::p> | lexy::dsl::p>; - static constexpr auto value = lexy::forward; + static constexpr auto value = lexy::forward; }; template struct AssignmentStatement { static constexpr auto rule = - lexy::dsl::position(lexy::dsl::p>) >> + dsl::p> >> lexy::dsl::equal_sign >> (lexy::dsl::p> | lexy::dsl::recurse_branch>); - static constexpr auto value = lexy::callback( - [](const char* pos, auto name, lexy::nullopt = {}) { - return LEXY_MOV(name); - }, - [](auto name, lexy::nullopt = {}) { - return LEXY_MOV(name); - }, - [](const char* pos, auto name, auto&& initalizer) { - return ast::make_node_ptr(pos, LEXY_MOV(name), LEXY_MOV(initalizer)); + static constexpr auto value = callback( + [](ast::ParseState& state, const char* pos, ast::IdentifierValue* name, ast::Value* initializer) { + return state.ast().create(pos, name, initializer); }); }; template struct StatementListBlock { static constexpr auto rule = - lexy::dsl::position(lexy::dsl::curly_bracketed.open()) >> - lexy::dsl::opt( - lexy::dsl::list( - lexy::dsl::recurse_branch>, - lexy::dsl::trailing_sep(lexy::dsl::lit_c<','>))) >> - lexy::dsl::position(lexy::dsl::curly_bracketed.close()); + dsl::curly_bracketed( + lexy::dsl::opt( + lexy::dsl::list( + lexy::dsl::recurse_branch>, + lexy::dsl::trailing_sep(lexy::dsl::lit_c<','>)))); static constexpr auto value = - lexy::as_list> >> - lexy::callback( - [](const char* begin, lexy::nullopt, const char* end) { - return ast::make_node_ptr(ast::NodeLocation::make_from(begin, end)); - }, - [](const char* begin, auto&& list, const char* end) { - return ast::make_node_ptr(ast::NodeLocation::make_from(begin, end), LEXY_MOV(list)); - }, - [](const char* begin, auto& list, const char* end) { - return ast::make_node_ptr(ast::NodeLocation::make_from(begin, end), list); - }); + lexy::as_list >> construct_list; }; template @@ -107,6 +105,6 @@ namespace ovdl::v2script::lua::grammar { static constexpr auto rule = lexy::dsl::position + lexy::dsl::terminator(lexy::dsl::eof).opt_list(lexy::dsl::p>); - static constexpr auto value = lexy::as_list> >> lexy::new_; + static constexpr auto value = lexy::as_list >> construct; }; } \ No newline at end of file -- cgit v1.2.3-56-ga3b1