aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-10-04 01:23:49 +0200
committer George L. Albany <Megacake1234@gmail.com>2023-10-05 01:35:42 +0200
commit7b1e33c26b4d36be2e3d1292dc539ff17e358589 (patch)
tree4456832acce290261f5839a083018afbd154ba16 /src
parent02c30fdda7b775782af1163b2321e7d6fcf01fcc (diff)
Make File contents optional
Add lexy::nullopt support to String and List nodes
Diffstat (limited to 'src')
-rw-r--r--src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp9
-rw-r--r--src/openvic-dataloader/v2script/SimpleGrammar.hpp2
2 files changed, 10 insertions, 1 deletions
diff --git a/src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp b/src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp
index 8dc1800..c7a325b 100644
--- a/src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp
+++ b/src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp
@@ -9,6 +9,7 @@
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
+#include <lexy/dsl/option.hpp>
#include <lexy/input_location.hpp>
using namespace ovdl::v2script::ast;
@@ -21,8 +22,10 @@ void ovdl::v2script::ast::copy_into_node_ptr_vector(const std::vector<NodePtr>&
}
}
+AbstractStringNode::AbstractStringNode() : Node({}) {}
AbstractStringNode::AbstractStringNode(NodeLocation location, std::string&& name) : Node(location),
_name(std::move(name)) {}
+AbstractStringNode::AbstractStringNode(NodeLocation location) : Node(location) {}
AbstractStringNode::AbstractStringNode(std::string&& name) : AbstractStringNode({}, std::move(name)) {}
std::ostream& AbstractStringNode::print(std::ostream& stream, size_t indent) const {
@@ -30,8 +33,12 @@ std::ostream& AbstractStringNode::print(std::ostream& stream, size_t indent) con
}
#define OVDL_AST_STRING_NODE_DEF(NAME, ...) \
+ NAME::NAME() : AbstractStringNode() {} \
NAME::NAME(std::string&& name) : AbstractStringNode(std::move(name)) {} \
+ NAME::NAME(lexy::nullopt) : AbstractStringNode() {} \
+ NAME::NAME(NodeLocation location) : AbstractStringNode(location) {} \
NAME::NAME(NodeLocation location, std::string&& name) : AbstractStringNode(location, std::move(name)) {} \
+ NAME::NAME(NodeLocation location, lexy::nullopt) : AbstractStringNode(location, {}) {} \
std::ostream& NAME::print(std::ostream& stream, size_t indent) const __VA_ARGS__
OVDL_AST_STRING_NODE_DEF(IdentifierNode, {
@@ -124,7 +131,9 @@ std::ostream& AbstractListNode::print(std::ostream& stream, size_t indent) const
#define OVDL_AST_LIST_NODE_DEF(NAME, ...) \
NAME::NAME(const std::vector<NodePtr>& statements) : AbstractListNode(statements) {} \
+ NAME::NAME(lexy::nullopt) : AbstractListNode() {} \
NAME::NAME(NodeLocation location, const std::vector<NodePtr>& statements) : AbstractListNode(location, statements) {} \
+ NAME::NAME(NodeLocation location, lexy::nullopt) : AbstractListNode(location, {}) {} \
std::ostream& NAME::print(std::ostream& stream, size_t indent) const __VA_ARGS__
OVDL_AST_LIST_NODE_DEF(FileNode, {
diff --git a/src/openvic-dataloader/v2script/SimpleGrammar.hpp b/src/openvic-dataloader/v2script/SimpleGrammar.hpp
index a065c7f..9bddabd 100644
--- a/src/openvic-dataloader/v2script/SimpleGrammar.hpp
+++ b/src/openvic-dataloader/v2script/SimpleGrammar.hpp
@@ -183,7 +183,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::position + lexy::dsl::terminator(lexy::dsl::eof).list(lexy::dsl::p<AssignmentStatement<Options>>);
+ static constexpr auto rule = lexy::dsl::position + lexy::dsl::terminator(lexy::dsl::eof).opt_list(lexy::dsl::p<AssignmentStatement<Options>>);
static constexpr auto value = lexy::as_list<std::vector<ast::NodePtr>> >> lexy::new_<ast::FileNode, ast::NodePtr>;
};