aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author George L. Albany <Megacake1234@gmail.com>2023-10-05 01:38:17 +0200
committer GitHub <noreply@github.com>2023-10-05 01:38:17 +0200
commit4009e1d576ad177aff59c8fce0339963303fc6e5 (patch)
tree4456832acce290261f5839a083018afbd154ba16
parent02c30fdda7b775782af1163b2321e7d6fcf01fcc (diff)
parent7b1e33c26b4d36be2e3d1292dc539ff17e358589 (diff)
Merge pull request #22 from OpenVicProject/add/v2script-optional-content
-rw-r--r--include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp12
-rw-r--r--src/openvic-dataloader/v2script/AbstractSyntaxTree.cpp9
-rw-r--r--src/openvic-dataloader/v2script/SimpleGrammar.hpp2
3 files changed, 22 insertions, 1 deletions
diff --git a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp
index 8e39bd9..8ff910f 100644
--- a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp
+++ b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp
@@ -14,6 +14,10 @@
#include <openvic-dataloader/detail/SelfType.hpp>
#include <openvic-dataloader/detail/TypeName.hpp>
+namespace lexy {
+ struct nullopt;
+}
+
namespace ovdl::v2script {
class Parser;
}
@@ -161,7 +165,9 @@ namespace ovdl::v2script::ast {
struct AbstractStringNode : public Node {
std::string _name;
+ AbstractStringNode();
AbstractStringNode(std::string&& name);
+ AbstractStringNode(NodeLocation location);
AbstractStringNode(NodeLocation location, std::string&& name);
OVDL_TYPE_DEFINE_SELF;
OVDL_RT_TYPE_DEF;
@@ -172,8 +178,12 @@ namespace ovdl::v2script::ast {
#define OVDL_AST_STRING_NODE(NAME) \
struct NAME final : public AbstractStringNode { \
+ NAME(); \
NAME(std::string&& name); \
+ NAME(lexy::nullopt); \
+ NAME(NodeLocation location); \
NAME(NodeLocation location, std::string&& name); \
+ NAME(NodeLocation location, lexy::nullopt); \
OVDL_TYPE_DEFINE_SELF; \
OVDL_RT_TYPE_DEF; \
OVDL_PRINT_FUNC_DEF; \
@@ -219,7 +229,9 @@ namespace ovdl::v2script::ast {
#define OVDL_AST_LIST_NODE(NAME) \
struct NAME final : public AbstractListNode { \
NAME(const std::vector<NodePtr>& statements = std::vector<NodePtr> {}); \
+ NAME(lexy::nullopt); \
NAME(NodeLocation location, const std::vector<NodePtr>& statements = std::vector<NodePtr> {}); \
+ NAME(NodeLocation location, lexy::nullopt); \
OVDL_TYPE_DEFINE_SELF; \
OVDL_RT_TYPE_DEF; \
OVDL_PRINT_FUNC_DEF; \
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>;
};