Newer
Older
#include "RegExpFromStringLexer.h"
namespace regexp {
RegExpFromStringLexer::RegExpFromStringLexer(const std::string& in) : m_In(in) {
this->next();
}
RegExpFromStringLexer& RegExpFromStringLexer::next() {
char character;
L0:
character = m_In.get();
if(m_In.eof()) {
m_Current.type = TEOF;
return *this;
} else if(character == ' ' || character == '\n' || character == '\t') {
goto L0;
} else if(character == '"') {
goto L3;
} else if((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z') || (character >= '0' && character <= '9')) {
m_Current.type = SYMBOL;
m_Current.value += character;
goto L2;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
} else if(character == '(') {
m_Current.type = LPAR;
return *this;
} else if(character == ')') {
m_Current.type = RPAR;
return *this;
} else if(character == '+') {
m_Current.type = PLUS;
return *this;
} else if(character == '*') {
m_Current.type = STAR;
return *this;
} else if(character == '\\') {
goto L1;
} else {
m_In.unget();
m_Current.type = ERROR;
return *this;
}
L1:
character = m_In.get();
if(m_In.eof()) {
m_Current.type = ERROR;
return *this;
} else if(character == 'e') {
m_Current.type = EPS;
return *this;
} else if(character == '0') {
m_Current.type = EMPTY;
return *this;
} else {
m_In.unget();
m_Current.type = ERROR;
return *this;
}
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
L2:
character = m_In.get();
if(m_In.eof()) {
return *this;
} else if((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z') || (character >= '0' && character <= '9')) {
m_Current.value += character;
goto L2;
} else {
m_In.unget();
return *this;
}
L3:
character = m_In.get();
if(m_In.eof()) {
m_Current.type = ERROR;
return *this;
} else if(character == '"') {
m_Current.type = EPS;
return *this;
} else if(character == '\\') {
m_Current.type = SYMBOL;
goto L5;
} else {
m_Current.type = SYMBOL;
m_Current.value += character;
goto L4;
}
L4:
character = m_In.get();
if(m_In.eof()) {
m_Current.type = ERROR;
return *this;
} else if(character == '"') {
return *this;
} else if(character == '\\') {
goto L5;
} else {
m_Current.value += character;
goto L4;
}
L5:
character = m_In.get();
if(m_In.eof()) {
m_Current.type = ERROR;
return *this;
} else if(character == '"' || character == '\\') {
m_Current.value += character;
goto L4;
} else {
m_Current.type = ERROR;
return *this;
}
}
RegExpFromStringLexer::Token RegExpFromStringLexer::token() {