Ember
Loading...
Searching...
No Matches
ParserConfig.h
Go to the documentation of this file.
1#pragma once
2
3#include "Types/Types.h"
4#include <map>
5#include <nlohmann/json.hpp>
6#include <set>
7#include <vector>
8
9namespace EmberCore {
10
18 public:
23 BY_ELEMENT_NAME, // Node type determined by element name (e.g., <Control>, <Action>)
24 BY_ATTRIBUTE, // Node type determined by attribute value
25 HYBRID // Combination of both strategies
26 };
27
32 ERROR, // Throw error and fail parsing
33 WARNING, // Log warning and continue
34 GENERIC_NODE // Create generic node with inferred type
35 };
36
40 enum class WhitespaceHandling {
41 PRESERVE, // Keep all whitespace as-is
42 TRIM, // Trim leading/trailing whitespace
43 NORMALIZE // Normalize multiple spaces to single space
44 };
45
49 enum class NamingConvention {
50 STRICT, // Strict naming validation
51 BALANCED, // Balanced naming rules
52 LOOSE // Loose/permissive naming
53 };
54
58 enum class SubTreeExpansion {
59 IMMEDIATE, // Expand all SubTrees immediately after parsing
60 LAZY, // Expand SubTrees on first access
61 MANUAL // User must manually trigger expansion
62 };
63
64 // Document Structure Configuration
73
74 // Tree Element Configuration
84
85 // Node Element Configuration
97
98 // Node Type Classification Configuration
101 std::vector<String> control_types = {"Sequence", "Selector", "Parallel",
102 "ReactiveSequence", "IfThenElse", "RepeatAtOnce"};
103 std::vector<String> decorator_types = {"ForceSuccess", "ForceFailure", "Inverter",
104 "Delay", "RepeatUntilSuccess", "Repeat"};
105 std::vector<String> action_types; // Known action types (can be empty for generic)
106 std::vector<String> condition_types; // Known condition types (can be empty for generic)
108 String type_attribute_name = "type"; // Used for BY_ATTRIBUTE strategy
109 };
110
111 // Blackboard Configuration
120 std::map<String, String> type_mappings; // XML type -> Internal type
122 };
123
124 // Advanced Options
136
137 public:
138 ParserConfig();
139 ~ParserConfig() = default;
140
141 // Configuration accessors
144
146 const TreeConfig &GetTreeConfig() const { return tree_config_; }
147
149 const NodeConfig &GetNodeConfig() const { return node_config_; }
150
153
156
159
160 // JSON serialization/deserialization
161 nlohmann::json ToJson() const;
162 void FromJson(const nlohmann::json &json);
163
164 // Validation
165 bool Validate(std::vector<String> &errors) const;
166
167 // Helper methods
168 bool IsControlType(const String &type) const;
169 bool IsDecoratorType(const String &type) const;
170 bool IsActionType(const String &type) const;
171 bool IsConditionType(const String &type) const;
172
173 // Create default configurations
176
177 private:
184
185 // Helper methods for JSON conversion
186 static nlohmann::json ClassificationStrategyToJson(ClassificationStrategy strategy);
187 static ClassificationStrategy ClassificationStrategyFromJson(const nlohmann::json &json);
188 static nlohmann::json UnknownTypeBehaviorToJson(UnknownTypeBehavior behavior);
189 static UnknownTypeBehavior UnknownTypeBehaviorFromJson(const nlohmann::json &json);
190 static nlohmann::json WhitespaceHandlingToJson(WhitespaceHandling handling);
191 static WhitespaceHandling WhitespaceHandlingFromJson(const nlohmann::json &json);
192 static nlohmann::json SubTreeExpansionToJson(SubTreeExpansion expansion);
193 static SubTreeExpansion SubTreeExpansionFromJson(const nlohmann::json &json);
194 static nlohmann::json NamingConventionToJson(NamingConvention convention);
195 static NamingConvention NamingConventionFromJson(const nlohmann::json &json);
196};
197
198} // namespace EmberCore
Configuration for XML parser behavior and element/attribute mappings.
const ClassificationConfig & GetClassificationConfig() const
BlackboardConfig blackboard_config_
bool Validate(std::vector< String > &errors) const
SubTreeExpansion
SubTree expansion strategy.
static nlohmann::json SubTreeExpansionToJson(SubTreeExpansion expansion)
AdvancedConfig advanced_config_
static WhitespaceHandling WhitespaceHandlingFromJson(const nlohmann::json &json)
const DocumentConfig & GetDocumentConfig() const
NamingConvention
Naming convention strictness.
DocumentConfig & GetDocumentConfig()
ClassificationStrategy
Strategy for classifying node types.
ClassificationConfig & GetClassificationConfig()
static ParserConfig CreateDefault()
static nlohmann::json UnknownTypeBehaviorToJson(UnknownTypeBehavior behavior)
AdvancedConfig & GetAdvancedConfig()
bool IsConditionType(const String &type) const
static NamingConvention NamingConventionFromJson(const nlohmann::json &json)
UnknownTypeBehavior
How to handle unknown/unmapped types.
static nlohmann::json NamingConventionToJson(NamingConvention convention)
void FromJson(const nlohmann::json &json)
static ParserConfig CreateGeneric()
bool IsDecoratorType(const String &type) const
WhitespaceHandling
Whitespace handling strategy.
static SubTreeExpansion SubTreeExpansionFromJson(const nlohmann::json &json)
TreeConfig & GetTreeConfig()
static nlohmann::json ClassificationStrategyToJson(ClassificationStrategy strategy)
BlackboardConfig & GetBlackboardConfig()
const BlackboardConfig & GetBlackboardConfig() const
bool IsActionType(const String &type) const
nlohmann::json ToJson() const
static ClassificationStrategy ClassificationStrategyFromJson(const nlohmann::json &json)
DocumentConfig document_config_
const AdvancedConfig & GetAdvancedConfig() const
const TreeConfig & GetTreeConfig() const
bool IsControlType(const String &type) const
static nlohmann::json WhitespaceHandlingToJson(WhitespaceHandling handling)
ClassificationConfig classification_config_
NodeConfig & GetNodeConfig()
const NodeConfig & GetNodeConfig() const
static UnknownTypeBehavior UnknownTypeBehaviorFromJson(const nlohmann::json &json)
Main types header for EmberCore.
std::string String
Framework-agnostic string type.
Definition String.h:14
std::map< String, String > type_mappings