Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRegExp.h
Go to the documentation of this file.
1
6#pragma once
7
11#include <core/stringApi.hpp>
12
13#include "UnboundedRegExp.h"
14
15namespace core {
16
17template<class SymbolType >
18struct stringApi < regexp::FormalRegExpStructure < SymbolType > > {
20 static bool first ( ext::istream & input );
21 static void compose ( ext::ostream & output, const regexp::FormalRegExpStructure < SymbolType > & regexp );
22private:
23 enum class Priority {
24 ALTERNATION,
25 CONCATENATION,
26 FACTOR
27 };
28
29 class Formal {
30 public:
37 };
38};
39
40template<class SymbolType >
43}
44
45template<class SymbolType >
47 return false; // FIXME temporarily dissable the formal regexp parser so that it does not take precedence over unbounded regexp parser see issue #205
49}
50
51template<class SymbolType >
53 Priority tmp = Priority::ALTERNATION;
55 regexp.getStructure ( ).template accept < void, stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal > ( out );
56}
57
58template < class SymbolType >
60 Priority outerPriorityMinimum = std::get < 0 > ( output );
61 if ( outerPriorityMinimum == ext::any_of ( Priority::CONCATENATION, Priority::FACTOR ) ) std::get < 1 > ( output ) << '(';
62
63 std::get < 0 > ( output ) = Priority::ALTERNATION;
64 alternation.getLeftElement ( ).template accept < void, stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal > ( output );
65 std::get < 1 > ( output ) << '+';
66 alternation.getRightElement ( ).template accept < void, stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal > ( output );
67
68 if ( outerPriorityMinimum == ext::any_of ( Priority::CONCATENATION, Priority::FACTOR ) ) std::get < 1 > ( output ) << ')';
69}
70
71template < class SymbolType >
72void stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal::visit( const regexp::FormalRegExpConcatenation < SymbolType > & concatenation, ext::tuple < Priority &, ext::ostream & > & output ) {
73 Priority outerPriorityMinimum = std::get < 0 > ( output );
74 if ( outerPriorityMinimum == Priority::FACTOR ) std::get < 1 > ( output ) << '(';
75
76 std::get < 0 > ( output ) = Priority::CONCATENATION;
77 concatenation.getLeftElement ( ).template accept < void, stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal > ( output );
78 std::get < 1 > ( output ) << ' ';
79 std::get < 0 > ( output ) = Priority::CONCATENATION;
80 concatenation.getRightElement ( ).template accept < void, stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal > ( output );
81
82 if ( outerPriorityMinimum == Priority::FACTOR ) std::get < 1 > ( output ) << ')';
83}
84
85template < class SymbolType >
86void stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal::visit( const regexp::FormalRegExpIteration < SymbolType > & iteration, ext::tuple < Priority &, ext::ostream & > & output ) {
87 std::get < 0 > ( output ) = Priority::FACTOR;
88 iteration.getElement ( ).template accept < void, stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal > ( output );
89 std::get < 1 > ( output ) << "*";
90}
91
92template < class SymbolType >
93void stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal::visit( const regexp::FormalRegExpSymbol < SymbolType > & symbol, ext::tuple < Priority &, ext::ostream & > & output ) {
94 core::stringApi < SymbolType >::compose ( std::get < 1 > ( output ), symbol.getSymbol ( ) );
95}
96
97template < class SymbolType >
98void stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal::visit( const regexp::FormalRegExpEpsilon < SymbolType > &, ext::tuple < Priority &, ext::ostream & > & output ) {
99 std::get < 1 > ( output ) << "#E";
100}
101
102template < class SymbolType >
103void stringApi < regexp::FormalRegExpStructure < SymbolType > >::Formal::visit( const regexp::FormalRegExpEmpty < SymbolType > &, ext::tuple < Priority &, ext::ostream & > & output ) {
104 std::get < 1 > ( output ) << "#0";
105}
106
107template<class SymbolType >
108struct stringApi < regexp::FormalRegExp < SymbolType > > {
109 static regexp::FormalRegExp < SymbolType > parse ( ext::istream & input );
110 static bool first ( ext::istream & input );
111 static void compose ( ext::ostream & output, const regexp::FormalRegExp < SymbolType > & regexp );
112};
113
114template<class SymbolType >
117}
118
119template<class SymbolType >
122}
123
124template<class SymbolType >
127}
128
129} /* namespace core */
130
Definition: dry-comparisons.hpp:131
Definition: istream.h:32
Definition: ostream.h:14
Class extending the tuple class from the standard library. Original reason is to allow printing of th...
Definition: tuple.hpp:42
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 formal regular expression structure. Regular expression is stored as a tree of FormalRegEx...
Definition: FormalRegExpStructure.h:45
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
Formal regular expression represents regular expression. It describes regular languages....
Definition: FormalRegExp.h:78
Represents unbounded regular expression structure. Regular expression is stored as a tree of Unbounde...
Definition: UnboundedRegExpStructure.h:47
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
constexpr auto visit(Visitor &&vis, Variants &&... vars)
Definition: variant.hpp:42
Definition: ToAutomaton.h:15
Definition: stringApi.hpp:26