Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RegExpToXmlComposer.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/deque>
11#include <sax/Token.h>
12
13#include <core/xmlApi.hpp>
14
15namespace regexp {
16
21public:
22 template < class SymbolType >
24
25 class Unbounded {
26 public:
27 template < class SymbolType >
28 static void visit( const UnboundedRegExpAlternation < SymbolType > & alternation, ext::deque < sax::Token > & output);
29 template < class SymbolType >
30 static void visit( const UnboundedRegExpConcatenation < SymbolType > & concatenation, ext::deque < sax::Token > & output);
31 template < class SymbolType >
32 static void visit( const UnboundedRegExpIteration < SymbolType > & iteration, ext::deque < sax::Token > & output);
33 template < class SymbolType >
34 static void visit( const UnboundedRegExpSymbol < SymbolType > & symbol, ext::deque < sax::Token > & output);
35 template < class SymbolType >
36 static void visit( const UnboundedRegExpEpsilon < SymbolType > & epsilon, ext::deque < sax::Token > & output);
37 template < class SymbolType >
38 static void visit( const UnboundedRegExpEmpty < SymbolType > & empty, ext::deque < sax::Token > & output);
39 };
40
41 class Formal {
42 public:
43 template < class SymbolType >
44 static void visit( const FormalRegExpAlternation < SymbolType > & alternation, ext::deque < sax::Token > & output);
45 template < class SymbolType >
46 static void visit( const FormalRegExpConcatenation < SymbolType > & concatenation, ext::deque < sax::Token > & output);
47 template < class SymbolType >
48 static void visit( const FormalRegExpIteration < SymbolType > & iteration, ext::deque < sax::Token > & output);
49 template < class SymbolType >
50 static void visit( const FormalRegExpSymbol < SymbolType > & symbol, ext::deque < sax::Token > & output);
51 template < class SymbolType >
52 static void visit( const FormalRegExpEpsilon < SymbolType > & epsilon, ext::deque < sax::Token > & output);
53 template < class SymbolType >
54 static void visit( const FormalRegExpEmpty < SymbolType > & empty, ext::deque < sax::Token > & output);
55 };
56};
57
58template < class SymbolType >
60 output.emplace_back("alternation", sax::Token::TokenType::START_ELEMENT);
61 for (const UnboundedRegExpElement < SymbolType > & element : alternation.getElements()) {
62 element.template accept < void, RegExpToXmlComposer::Unbounded > ( output );
63 }
64 output.emplace_back("alternation", sax::Token::TokenType::END_ELEMENT);
65}
66
67template < class SymbolType >
69 output.emplace_back("concatenation", sax::Token::TokenType::START_ELEMENT);
70 for (const UnboundedRegExpElement < SymbolType > & element : concatenation.getElements()) {
71 element.template accept < void, RegExpToXmlComposer::Unbounded > ( output );
72 }
73 output.emplace_back("concatenation", sax::Token::TokenType::END_ELEMENT);
74}
75
76template < class SymbolType >
78 output.emplace_back("iteration", sax::Token::TokenType::START_ELEMENT);
79 iteration.getElement().template accept < void, RegExpToXmlComposer::Unbounded > ( output );
80 output.emplace_back("iteration", sax::Token::TokenType::END_ELEMENT);
81}
82
83template < class SymbolType >
86}
87
88template < class SymbolType >
90 output.emplace_back("epsilon", sax::Token::TokenType::START_ELEMENT);
91 output.emplace_back("epsilon", sax::Token::TokenType::END_ELEMENT);
92}
93
94template < class SymbolType >
96 output.emplace_back("empty", sax::Token::TokenType::START_ELEMENT);
97 output.emplace_back("empty", sax::Token::TokenType::END_ELEMENT);
98}
99
100template < class SymbolType >
102 output.emplace_back("alternation", sax::Token::TokenType::START_ELEMENT);
103 alternation.getLeftElement().template accept < void, RegExpToXmlComposer::Formal > ( output );
104 alternation.getRightElement().template accept < void, RegExpToXmlComposer::Formal > ( output );
105 output.emplace_back("alternation", sax::Token::TokenType::END_ELEMENT);
106}
107
108template < class SymbolType >
110 output.emplace_back("concatenation", sax::Token::TokenType::START_ELEMENT);
111 concatenation.getLeftElement().template accept < void, RegExpToXmlComposer::Formal > ( output );
112 concatenation.getRightElement().template accept < void, RegExpToXmlComposer::Formal > ( output );
113 output.emplace_back("concatenation", sax::Token::TokenType::END_ELEMENT);
114}
115
116template < class SymbolType >
118 output.emplace_back("iteration", sax::Token::TokenType::START_ELEMENT);
119 iteration.getElement().template accept < void, RegExpToXmlComposer::Formal > ( output );
120 output.emplace_back("iteration", sax::Token::TokenType::END_ELEMENT);
121}
122
123template < class SymbolType >
126}
127
128template < class SymbolType >
130 output.emplace_back("epsilon", sax::Token::TokenType::START_ELEMENT);
131 output.emplace_back("epsilon", sax::Token::TokenType::END_ELEMENT);
132}
133
134template < class SymbolType >
136 output.emplace_back("empty", sax::Token::TokenType::START_ELEMENT);
137 output.emplace_back("empty", sax::Token::TokenType::END_ELEMENT);
138}
139
140template < class SymbolType >
142 output.emplace_back("alphabet", sax::Token::TokenType::START_ELEMENT);
143 for (const SymbolType & symbol : alphabet) {
144 core::xmlApi<SymbolType>::compose(output, symbol);
145 }
146 output.emplace_back("alphabet", sax::Token::TokenType::END_ELEMENT);
147}
148
149} /* namespace regexp */
150
Definition: set.hpp:44
Represents the alternation operator in the regular expression. The node must have exactly two childre...
Definition: FormalRegExpAlternation.h:44
const FormalRegExpElement< SymbolType > & getLeftElement() const
Definition: FormalRegExpAlternation.h:219
const FormalRegExpElement< SymbolType > & getRightElement() const
Definition: FormalRegExpAlternation.h:224
Represents the concatenation operator in the regular expression. The node must have exactly two child...
Definition: FormalRegExpConcatenation.h:44
const FormalRegExpElement< SymbolType > & getRightElement() const
Definition: FormalRegExpConcatenation.h:224
const FormalRegExpElement< SymbolType > & getLeftElement() const
Definition: FormalRegExpConcatenation.h:219
Represents the empty expression in the regular expression. The node can't have any children.
Definition: FormalRegExpEmpty.h:41
Represents the epsilon expression in the regular expression. The node can't have any children.
Definition: FormalRegExpEpsilon.h:41
Represents the iteration operator in the regular expression. The node has exactly one child.
Definition: FormalRegExpIteration.h:44
const FormalRegExpElement< SymbolType > & getElement() const
Definition: FormalRegExpIteration.h:190
Represents the symbol in the regular expression. The can't have any children.
Definition: FormalRegExpSymbol.h:42
const SymbolType & getSymbol() const &
Definition: FormalRegExpSymbol.h:212
Definition: RegExpToXmlComposer.h:41
static void visit(const FormalRegExpAlternation< SymbolType > &alternation, ext::deque< sax::Token > &output)
Definition: RegExpToXmlComposer.h:101
Definition: RegExpToXmlComposer.h:25
static void visit(const UnboundedRegExpAlternation< SymbolType > &alternation, ext::deque< sax::Token > &output)
Definition: RegExpToXmlComposer.h:59
Definition: RegExpToXmlComposer.h:20
static void composeAlphabet(ext::deque< sax::Token > &output, const ext::set< SymbolType > &alphabet)
Definition: RegExpToXmlComposer.h:141
Represents the alternation operator in the regular expression. The node can have 0 to n children in l...
Definition: UnboundedRegExpAlternation.h:44
const ext::ptr_vector< UnboundedRegExpElement< SymbolType > > & getElements() const
Definition: UnboundedRegExpAlternation.h:185
Represents the concatenation operator in the regular expression. The node can have 0 to n children in...
Definition: UnboundedRegExpConcatenation.h:44
const ext::ptr_vector< UnboundedRegExpElement< SymbolType > > & getElements() const
Definition: UnboundedRegExpConcatenation.h:185
Definition: UnboundedRegExpElement.h:62
Represents the empty expression in the regular expression. The node can't have any children.
Definition: UnboundedRegExpEmpty.h:41
Represents the epsilon expression in the regular expression. The node can't have any children.
Definition: UnboundedRegExpEpsilon.h:41
Represents the iteration operator in the regular expression. The node has exactly one child.
Definition: UnboundedRegExpIteration.h:43
const UnboundedRegExpElement< SymbolType > & getElement() const
Definition: UnboundedRegExpIteration.h:196
Represents the symbol in the regular expression. The can't have any children.
Definition: UnboundedRegExpSymbol.h:42
const SymbolType & getSymbol() const &
Definition: UnboundedRegExpSymbol.h:220
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: ToAutomaton.h:15
Definition: xmlApi.hpp:27