1
2
3
4
5
6 #include <sngcpp/symbols/GrammarSymbol.hpp>
7
8 namespace sngcpp { namespace symbols {
9
10 GrammarSymbol::GrammarSymbol(const Span& span_, const std::u32string& name_) : ContainerSymbol(span_, name_)
11 {
12 SetAccess(Specifier::public_);
13 }
14
15 std::u32string GrammarSymbol::KindStr()
16 {
17 return U"grammar";
18 }
19
20 void GrammarSymbol::AddMember(std::std::unique_ptr<Symbol>&&member)
21 {
22 Symbol* m = member.get();
23 ContainerSymbol::AddMember(std::move(member));
24 if (m->IsRuleSymbol())
25 {
26 rules.push_back(static_cast<RuleSymbol*>(m));
27 }
28 }
29
30 std::std::unique_ptr<sngxml::dom::Element>GrammarSymbol::CreateElement()
31 {
32 std::unique_ptr<sngxml::dom::Element> grammarElement(new sngxml::dom::Element(U"grammar"));
33 if (!rules.empty())
34 {
35 std::unique_ptr<sngxml::dom::Element> rulesElement(new sngxml::dom::Element(U"rules"));
36 for (RuleSymbol* ruleSymbol : rules)
37 {
38 std::unique_ptr<sngxml::dom::Element> ruleElement(ruleSymbol->ToDomElement());
39 rulesElement->AppendChild(std::unique_ptr<sngxml::dom::Node>(ruleElement.release()));
40 }
41 grammarElement->AppendChild(std::unique_ptr<sngxml::dom::Node>(rulesElement.release()));
42 }
43 return grammarElement;
44 }
45
46 } }