-
Notifications
You must be signed in to change notification settings - Fork 27
/
checktestdata.l
161 lines (133 loc) · 3.61 KB
/
checktestdata.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
%filenames scanner
// Define an exclusive sub-scanner:
%x string
%%
ISEOF { return Parser::TEST_EOF; }
MATCH { return Parser::TEST_MATCH; }
UNIQUE { return Parser::TEST_UNIQUE; }
INARRAY { return Parser::TEST_INARRAY; }
&& { return Parser::LOGIC_AND; }
\|\| { return Parser::LOGIC_OR; }
\< { return Parser::CMP_LT; }
\> { return Parser::CMP_GT; }
\<= { return Parser::CMP_LE; }
\>= { return Parser::CMP_GE; }
== { return Parser::CMP_EQ; }
!= { return Parser::CMP_NE; }
STRLEN { return Parser::FUN_STRLEN; }
SPACE { return Parser::CMD_SPACE; }
NEWLINE { return Parser::CMD_NEWLINE; }
EOF { return Parser::CMD_EOF; }
INT { return Parser::CMD_INT; }
FLOAT { return Parser::CMD_FLOAT; }
FLOATP { return Parser::CMD_FLOATP; }
STRING { return Parser::CMD_STRING; }
REGEX { return Parser::CMD_REGEX; }
ASSERT { return Parser::CMD_ASSERT; }
SET { return Parser::CMD_SET; }
UNSET { return Parser::CMD_UNSET; }
REP { return Parser::CMD_REP; }
WHILE { return Parser::CMD_WHILE; }
REPI { return Parser::CMD_REPI; }
WHILEI { return Parser::CMD_WHILEI; }
IF { return Parser::CMD_IF; }
ELSE { return Parser::CMD_ELSE; }
END { return Parser::CMD_END; }
FIXED { return Parser::OPT_FIXED; }
SCIENTIFIC { return Parser::OPT_SCIENTIFIC; }
[a-z][a-z0-9]* {
return Parser::VARNAME;
}
/* A floating point number must have a decimal point or exponent: */
[0-9]+\.[0-9]*([eE][+-]?[0-9]+)? {
return Parser::FLOAT;
}
[0-9]+[eE][+-]?[0-9]+ {
return Parser::FLOAT;
}
[0-9]+ {
return Parser::INTEGER;
}
/* String parsing -- adapted from the flex and flexc++ manuals */
\" {
/* begin of string */
#if ( FLEXCPP_VERSION >= 20700LL )
begin(StartCondition_::string);
#else
begin(StartCondition__::string);
#endif
}
<string>{
\" {
/* end of string */
setMatched(matched().substr(0,matched().length()-1));
#if ( FLEXCPP_VERSION >= 20700LL )
begin(StartCondition_::INITIAL);
#else
begin(StartCondition__::INITIAL);
#endif
return Parser::STRING;
}
\n {
/* Allow string constants to span multiple lines. */
more();
}
\\[0-7]{1,3} {
/* octal escape sequence */
size_t esc_pos = matched().rfind('\\');
std::string oct_str = matched().substr(esc_pos+1);
int res;
size_t pos = 0;
try {
res = std::stoi(oct_str,&pos,8);
} catch ( ... ) {
res = -1;
}
if ( pos!=oct_str.length() || res<0 || res>=256 ) {
throw(ScannerException("bad escape sequence '\\"+oct_str+
"' on line "+std::to_string(lineNr())));
}
setMatched(matched().substr(0,esc_pos)+(char)res);
more();
}
\\[ntrbf\"\\] {
/* Escape sequences for some special characters. */
char c = matched().back(), res;
switch ( c ) {
case 'n': res = '\n'; break;
case 't': res = '\t'; break;
case 'r': res = '\r'; break;
case 'b': res = '\b'; break;
case 'f': res = '\f'; break;
case '\"': res = '\"'; break;
case '\\': res = '\\'; break;
default:
throw(ScannerException("unknown escape character '\\"+std::string(1,c)+
"' on line "+std::to_string(lineNr())));
}
setMatched(matched().substr(0,matched().length()-2)+res);
more();
}
\\\n {
/* Ignore escaped newlines (line continuation). */
setMatched(matched().substr(0,matched().length()-2));
more();
}
/* Treat all other backslashes normally. */
\\. more();
[^\\\n\"]+ {
/* Fast match any text not containing special characters. */
more();
}
} /* end of string parsing */
[ \t\r\n]+ {
/* Ignore whitespace and newlines. */
}
#.* {
/* Ignore comments, starting with '#' until end of line (or file). */
}
. {
/* Return all others characters as-is. */
return matched()[0];
}
%%