aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp16
-rw-r--r--src/openvic-dataloader/v2script/AiBehaviorGrammar.hpp2
-rw-r--r--src/openvic-dataloader/v2script/DecisionGrammar.hpp2
-rw-r--r--src/openvic-dataloader/v2script/EffectGrammar.hpp2
-rw-r--r--src/openvic-dataloader/v2script/EventGrammar.hpp31
-rw-r--r--src/openvic-dataloader/v2script/ModifierGrammar.hpp5
-rw-r--r--src/openvic-dataloader/v2script/TriggerGrammar.hpp2
7 files changed, 41 insertions, 19 deletions
diff --git a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp
index 0d0b019..1dcd7c7 100644
--- a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp
+++ b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <memory>
+#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
@@ -50,6 +51,12 @@ namespace ovdl::v2script::ast {
constexpr bool is_type() const {
return get_type().compare(detail::type_name<T>()) == 0;
}
+
+ template<typename T>
+ constexpr std::optional<T&> cast_to() {
+ if (is_type<T>()) return static_cast<T>(*this);
+ return std::nullopt;
+ }
};
using NodePtr = Node*;
@@ -77,7 +84,7 @@ namespace ovdl::v2script::ast {
std::vector<NodeUPtr> result;
result.reserve(ptrs.size());
for (auto&& p : ptrs) {
- if (p == nullptr) continue;
+ if (!p || p == nullptr) continue;
result.push_back(NodeUPtr(p));
}
return result;
@@ -103,13 +110,15 @@ namespace ovdl::v2script::ast {
}) \
}
+ // Value Expression Nodes
OVDL_AST_STRING_NODE(IdentifierNode);
+ OVDL_AST_STRING_NODE(StringNode);
+
+ // Assignment Nodes
OVDL_AST_STRING_NODE(FactorNode);
OVDL_AST_STRING_NODE(MonthNode);
OVDL_AST_STRING_NODE(NameNode);
- OVDL_AST_STRING_NODE(StringNode);
OVDL_AST_STRING_NODE(FireOnlyNode);
-
OVDL_AST_STRING_NODE(IdNode);
OVDL_AST_STRING_NODE(TitleNode);
OVDL_AST_STRING_NODE(DescNode);
@@ -172,6 +181,7 @@ namespace ovdl::v2script::ast {
}
OVDL_AST_LIST_NODE(ListNode);
+
OVDL_AST_LIST_NODE(ModifierNode);
OVDL_AST_LIST_NODE(MtthNode);
OVDL_AST_LIST_NODE(EventOptionNode);
diff --git a/src/openvic-dataloader/v2script/AiBehaviorGrammar.hpp b/src/openvic-dataloader/v2script/AiBehaviorGrammar.hpp
index a772a7c..bbdc67d 100644
--- a/src/openvic-dataloader/v2script/AiBehaviorGrammar.hpp
+++ b/src/openvic-dataloader/v2script/AiBehaviorGrammar.hpp
@@ -26,7 +26,7 @@ namespace ovdl::v2script::grammar {
return LEXY_MOV(list);
},
[](lexy::nullopt = {}) {
- return nullptr;
+ return lexy::nullopt {};
});
};
} \ No newline at end of file
diff --git a/src/openvic-dataloader/v2script/DecisionGrammar.hpp b/src/openvic-dataloader/v2script/DecisionGrammar.hpp
index 3e77616..e6e3b57 100644
--- a/src/openvic-dataloader/v2script/DecisionGrammar.hpp
+++ b/src/openvic-dataloader/v2script/DecisionGrammar.hpp
@@ -103,7 +103,7 @@ namespace ovdl::v2script::grammar {
return ast::make_node_ptr<ast::DecisionListNode>(LEXY_MOV(list));
},
[](lexy::nullopt = {}) {
- return nullptr;
+ return lexy::nullopt {};
});
};
diff --git a/src/openvic-dataloader/v2script/EffectGrammar.hpp b/src/openvic-dataloader/v2script/EffectGrammar.hpp
index 71697c4..db35f02 100644
--- a/src/openvic-dataloader/v2script/EffectGrammar.hpp
+++ b/src/openvic-dataloader/v2script/EffectGrammar.hpp
@@ -34,7 +34,7 @@ namespace ovdl::v2script::grammar {
return LEXY_MOV(list);
},
[](lexy::nullopt = {}) {
- return nullptr;
+ return lexy::nullopt {};
});
};
} \ No newline at end of file
diff --git a/src/openvic-dataloader/v2script/EventGrammar.hpp b/src/openvic-dataloader/v2script/EventGrammar.hpp
index 216d645..4a64ce4 100644
--- a/src/openvic-dataloader/v2script/EventGrammar.hpp
+++ b/src/openvic-dataloader/v2script/EventGrammar.hpp
@@ -49,8 +49,13 @@ namespace ovdl::v2script::grammar {
struct EventMtthStatement {
OVDL_GRAMMAR_KEYWORD_DEFINE(months);
+ struct MonthValue {
+ static constexpr auto rule = lexy::dsl::inline_<Identifier>;
+ static constexpr auto value = lexy::as_string<std::string> | lexy::new_<ast::MonthNode, ast::NodePtr>;
+ };
+
static constexpr auto rule = lexy::dsl::list(
- (months_p >> lexy::dsl::p<Identifier>) |
+ (months_p >> lexy::dsl::p<MonthValue>) |
lexy::dsl::p<ModifierStatement>);
static constexpr auto value =
@@ -61,6 +66,20 @@ namespace ovdl::v2script::grammar {
});
};
+ template<auto Production, typename AstNode>
+ struct _StringStatement {
+ static constexpr auto rule = Production >> (lexy::dsl::p<StringExpression> | lexy::dsl::p<Identifier>);
+ static constexpr auto value =
+ lexy::callback<ast::NodePtr>(
+ [](auto&& value) {
+ auto result = ast::make_node_ptr<AstNode>(std::move(static_cast<ast::AbstractStringNode*>(value)->_name));
+ delete value;
+ return result;
+ });
+ };
+ template<auto Production, typename AstNode>
+ static constexpr auto StringStatement = lexy::dsl::p<_StringStatement<Production, AstNode>>;
+
struct EventOptionList {
OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(name);
OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(ai_chance);
@@ -68,7 +87,7 @@ namespace ovdl::v2script::grammar {
static constexpr auto rule = [] {
constexpr auto create_flags = name_rule::flag.create() + ai_chance_rule::flag.create();
- constexpr auto name_statement = name_p >> (lexy::dsl::p<StringExpression> | lexy::dsl::p<Identifier>);
+ constexpr auto name_statement = StringStatement<name_p, ast::NameNode>;
constexpr auto ai_chance_statement = ai_chance_p >> lexy::dsl::curly_bracketed(lexy::dsl::p<AiBehaviorList>);
return create_flags + lexy::dsl::list(name_statement | ai_chance_statement | lexy::dsl::p<EffectList>);
@@ -83,14 +102,6 @@ namespace ovdl::v2script::grammar {
};
struct EventStatement {
- template<auto Production, typename AstNode>
- struct _StringStatement {
- static constexpr auto rule = Production >> (lexy::dsl::p<StringExpression> | lexy::dsl::p<Identifier>);
- static constexpr auto value = lexy::forward<ast::NodePtr>;
- };
- template<auto Production, typename AstNode>
- static constexpr auto StringStatement = lexy::dsl::p<_StringStatement<Production, AstNode>>;
-
OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(id);
OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(title);
OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(desc);
diff --git a/src/openvic-dataloader/v2script/ModifierGrammar.hpp b/src/openvic-dataloader/v2script/ModifierGrammar.hpp
index 2b28712..74deef7 100644
--- a/src/openvic-dataloader/v2script/ModifierGrammar.hpp
+++ b/src/openvic-dataloader/v2script/ModifierGrammar.hpp
@@ -3,14 +3,15 @@
#include "SimpleGrammar.hpp"
#include "TriggerGrammar.hpp"
#include <lexy/dsl.hpp>
+#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
namespace ovdl::v2script::grammar {
constexpr auto modifier_keyword = LEXY_KEYWORD("modifier", lexy::dsl::inline_<Identifier>);
constexpr auto factor_keyword = LEXY_KEYWORD("factor", lexy::dsl::inline_<Identifier>);
struct FactorStatement {
- static constexpr auto rule = factor_keyword >> lexy::dsl::equal_sign + lexy::dsl::p<Identifier>;
- static constexpr auto value = lexy::forward<ast::NodePtr>;
+ static constexpr auto rule = factor_keyword >> lexy::dsl::equal_sign + lexy::dsl::inline_<Identifier>;
+ static constexpr auto value = lexy::as_string<std::string> | lexy::new_<ast::FactorNode, ast::NodePtr>;
};
struct ModifierStatement {
diff --git a/src/openvic-dataloader/v2script/TriggerGrammar.hpp b/src/openvic-dataloader/v2script/TriggerGrammar.hpp
index 514da49..ffed1d3 100644
--- a/src/openvic-dataloader/v2script/TriggerGrammar.hpp
+++ b/src/openvic-dataloader/v2script/TriggerGrammar.hpp
@@ -34,7 +34,7 @@ namespace ovdl::v2script::grammar {
return LEXY_MOV(list);
},
[](lexy::nullopt = {}) {
- return nullptr;
+ return lexy::nullopt {};
});
};
} \ No newline at end of file