diff options
author | Spartan322 <Megacake1234@gmail.com> | 2023-07-25 02:24:01 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2023-07-26 23:54:58 +0200 |
commit | be1d0545c2f7a85a63d05b4bdc1020ee284e72cb (patch) | |
tree | 09cb0fa0a1dbe83d4833bcd62dc8832161e4329b /src/openvic-dataloader/v2script | |
parent | 65443efcc2f4c7d687b2bd9c631f6bb426688bbf (diff) |
Initial structural commit
Diffstat (limited to 'src/openvic-dataloader/v2script')
-rw-r--r-- | src/openvic-dataloader/v2script/Grammar.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/openvic-dataloader/v2script/Grammar.cpp b/src/openvic-dataloader/v2script/Grammar.cpp new file mode 100644 index 0000000..ec9fac2 --- /dev/null +++ b/src/openvic-dataloader/v2script/Grammar.cpp @@ -0,0 +1,74 @@ +#include <lexy/dsl.hpp> +#include <openvic-dataloader/v2script/Parser.hpp> + +using namespace ovdl::v2script; + +// Node Definitions // +namespace dsl = lexy::dsl; + +namespace ovdl::v2script::nodes { + struct StatementListBlock; + + static constexpr auto whitespace_specifier = dsl::code_point.range<0x09, 0x0A>() / dsl::lit_cp<0x0D> / dsl::lit_cp<0x20>; + static constexpr auto comment_specifier = LEXY_LIT("#") >> dsl::until(dsl::newline).or_eof(); + + static constexpr auto data_specifier = + dsl::ascii::alpha_digit_underscore / + dsl::code_point.range<0x25, 0x27>() / dsl::lit_cp<0x2B> / dsl::code_point.range<0x2D, 0x2E>() / + dsl::lit_cp<0x3A> / + dsl::lit_cp<0x8A> / dsl::lit_cp<0x8C> / dsl::lit_cp<0x8E> / + dsl::lit_cp<0x92> / dsl::lit_cp<0x9A> / dsl::lit_cp<0x9C> / dsl::code_point.range<0x9E, 0x9F>() / + dsl::code_point.range<0xC0, 0xD6>() / dsl::code_point.range<0xD8, 0xF6>() / dsl::code_point.range<0xF8, 0xFF>(); + + static constexpr auto data_char_class = LEXY_CHAR_CLASS("DataSpecifier", data_specifier); + + struct Identifier { + static constexpr auto rule = dsl::identifier(data_char_class); + }; + + struct StringExpression { + static constexpr auto escaped_symbols = lexy::symbol_table<char> // + .map<'"'>('"') + .map<'\''>('\'') + .map<'\\'>('\\') + .map<'/'>('/') + .map<'b'>('\b') + .map<'f'>('\f') + .map<'n'>('\n') + .map<'r'>('\r') + .map<'t'>('\t'); + static constexpr auto rule = [] { + // Arbitrary code points that aren't control characters. + auto c = -dsl::unicode::control; + + // Escape sequences start with a backlash. + // They either map one of the symbols, + // or a Unicode code point of the form uXXXX. + auto escape = dsl::backslash_escape // + .symbol<escaped_symbols>() + .rule(dsl::lit_c<'u'> >> dsl::code_point_id<4>); + return dsl::quoted(c, escape); + }(); + }; + + struct AssignmentStatement { + static constexpr auto rule = dsl::p<Identifier> >> + (dsl::equal_sign >> + (dsl::p<Identifier> | dsl::p<StringExpression> | dsl::recurse_branch<StatementListBlock>) | + dsl::else_ >> dsl::return_); + }; + + struct StatementListBlock { + static constexpr auto rule = + dsl::curly_bracketed.open() >> + dsl::opt(dsl::list(dsl::p<AssignmentStatement>)) + dsl::opt(dsl::semicolon) + + dsl::curly_bracketed.close(); + }; + + struct File { + // Allow arbitrary spaces between individual tokens. + static constexpr auto whitespace = whitespace_specifier | comment_specifier; + + static constexpr auto rule = dsl::terminator(dsl::eof).list(dsl::p<AssignmentStatement>); + }; +} |