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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
|
%filenames scanner
%class-name = "Scanner"
%token-path = "../tokens/tokens.h"
%debug
// %print-tokens
%x xstring pstring pxstring string rawstring comment quote block typespec
%x typecomment
OCTAL [0-7]
OCT3 {OCTAL}{3}
HEX [[:xdigit:]]
HEX2 {HEX}{2}
ID1 [[:alpha:]_]
ID2 [[:alnum:]_]
IDENT {ID1}{ID2}*
NR [[:digit:]]+
%%
<INITIAL,block>{
"{" {
// open or count a nested a block
d_block.open(lineNr(), filename());
begin(StartCondition_::block);
}
// The whitespace-eating RegExes (REs) will normally simply consume the
// WS. However, if d_retWS is unequal 0 then WS is returned. This is
// sometimes needed (e.g., inside code blocks to be able to return the ws
// as part of the code-block). Comment is part of the WS returning REs
[ \t]+ {
if (d_block)
d_block += " ";
}
[\n]+ {
setLineNrs();
if (d_block)
d_block += "\n";
}
"//".* // ignore eoln comment in source blocks
// If comment is entered from `block' either a blank or a newline will be
// added to the block as soon as the matching end-comment is seen, and
// the scanner will return to its block-miniscanner state
"/*" {
d_commentChar[0] = ' ';
begin(StartCondition_::comment);
}
}
// Blocks start at { and end at their matching } char. They may contain
// comment and whitespace, but whitespace is reduced to single blanks or
// newlines. All STRING and QUOTE constants are kept as-is, and are
// registered as skip-ranges for $-checks
<block>{
R\"{IDENT}?\( rawString();
"}" {
if (d_block.close()) // close a block
{
begin(StartCondition_::INITIAL);
return Tokens::BLOCK;
}
}
"\"" {
begin(StartCondition_::string);
more();
}
"'" {
begin(StartCondition_::quote);
more();
}
// negative dollar indices with tag indicate a .get request.
// there is no reference option:
// "_$<"{IDENT}">"-{NR} | // refDid_n
// see: parser/substituteblock.cc
// AtDollar Pattern:
"$$"[ \t\n]*= | // assignments are refDD or refD_
"$"-?{NR}[ \t\n]*= assignment();
"$$(" |
@@ |
@{NR} |
"_$$" |
"$$"\.? |
"$$->" |
"_$"-?{NR} |
\$-?{NR} |
\$-?{NR}\. |
\$-?{NR}"->" |
"$<"{IDENT}">"-{NR}\.? |
"$<"{IDENT}">"-{NR}"->" d_block.atDollar(lineNr(), d_matched, false);
. d_block(d_matched);
}
%baseclass-header[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::BASECLASS_HEADER;
}
%baseclass-preinclude[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::BASECLASS_PREINCLUDE;
}
%class-header[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::CLASS_HEADER;
}
%class-name return Tokens::CLASS_NAME;
%constructor-checks return Tokens::CONSTRUCTOR_CHECKS;
%default-actions return Tokens::DEFAULT_ACTIONS;
%debug return Tokens::DEBUGFLAG;
%error-verbose return Tokens::ERROR_VERBOSE;
%expect return Tokens::EXPECT;
%filenames[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::FILENAMES;
}
"%flex" return Tokens::FLEX;
%implementation-header[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::IMPLEMENTATION_HEADER;
}
%include[ \t]+ {
begin(StartCondition_::pxstring);
d_include = true;
}
%left return Tokens::LEFT;
%locationstruct return Tokens::LOCATIONSTRUCT;
%lsp-needed return Tokens::LSP_NEEDED;
%ltype[ \t]+ {
begin(StartCondition_::xstring);
return Tokens::LTYPE;
}
%namespace return Tokens::NAMESPACE;
%negative-dollar-indices return Tokens::NEG_DOLLAR;
%no-lines return Tokens::NOLINES;
%nonassoc return Tokens::NONASSOC;
%parsefun-source[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::PARSEFUN_SOURCE;
}
%polymorphic return Tokens::POLYMORPHIC;
%prec return Tokens::PREC;
%print-tokens return Tokens::PRINT_TOKENS;
%prompt return Tokens::PROMPT;
%required-tokens return Tokens::REQUIRED;
%right return Tokens::RIGHT;
%scanner[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::SCANNER;
}
%scanner-class-name[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::SCANNER_CLASS_NAME;
}
%scanner-token-function[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::SCANNER_TOKEN_FUNCTION;
}
%scanner-matched-text-function[ \t]+ {
begin(StartCondition_::pxstring);
return
Tokens::SCANNER_MATCHED_TEXT_FUNCTION;
}
%stack-expansion[ \t]+ return Tokens::STACK_EXPANSION;
%start return Tokens::START;
%stype[ \t]+ {
begin(StartCondition_::xstring);
return Tokens::STYPE;
}
%tag-mismatches return Tokens::WARN_TAGS;
%target-directory[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::TARGET_DIRECTORY;
}
%thread-safe return Tokens::THREAD_SAFE;
%token return Tokens::TOKEN;
%token-class return Tokens::TOKEN_CLASS;
%token-namespace return Tokens::TOKEN_NAMESPACE;
%token-path[ \t]+ {
begin(StartCondition_::pxstring);
return Tokens::TOKEN_PATH;
}
%type return Tokens::TYPE;
%union return Tokens::UNION;
%weak-tags return Tokens::WEAK_TAGS;
"%%" return Tokens::TWO_PERCENTS;
"'" {
begin(StartCondition_::quote);
more();
}
"\"" {
begin(StartCondition_::string);
more();
}
{IDENT} return Tokens::IDENTIFIER;
[[:digit:]]+ {
d_number = stoul(d_matched);
return Tokens::NUMBER;
}
. return d_matched[0];
// pxstring is activated after a directive has been sensed.
// it extracts a string, pstring or any sequence of non-blank characters,
<pxstring>{
"\"" {
more();
begin(StartCondition_::string);
}
"<" {
more();
begin(StartCondition_::pstring);
}
. {
accept(0);
begin(StartCondition_::xstring);
}
\n return eoln();
}
// string may be entered from block and pxstring
// strings are all series (including escaped chars, like \") surrounded by
// double quotes:
<string>{
"\"" {
if (handleXstring(0))
return Tokens::STRING;
}
"\\". |
. more();
\n return eoln();
}
// a pstring is a string surrounded by < and >
<pstring>{
">" {
if (handleXstring(0))
return Tokens::STRING;
}
"\\". |
. more();
\n return eoln();
}
// xstring returns the next string delimited by either blanks, tabs,
// newlines or C/C++ comment.
<xstring>{
[[:space:]] {
if (handleXstring(1))
return Tokens::STRING;
}
"//" |
"/*" {
if (handleXstring(2))
return Tokens::STRING;
}
. more();
}
<rawstring>{
\){IDENT}?\" checkEndOfRawString();
.|\n more();
}
<comment>{
.
\n {
setLineNrs();
d_commentChar[0] = '\n';
}
"*/" {
if (!d_block)
begin(StartCondition_::INITIAL);
else
{
d_block += d_commentChar;
begin(StartCondition_::block);
}
}
}
// quote may be entered from INITIAL and block.
// quoted constants start with a quote. They may be octal or hex numbers,
// escaped chars, or quoted constants
<quote>{
"\\"{OCT3}"'" returnQuoted(&Scanner::octal);
"\\x"{HEX2}"'" returnQuoted(&Scanner::hexadecimal);
"\\"[abfnrtv]"'" {
if (d_block(d_matched))
begin(StartCondition_::block);
else
{
begin(StartCondition_::INITIAL);
escape(); // quoted escape char
return Tokens::QUOTE;
}
}
"\\"."'" returnQuoted(&Scanner::matched2);
."'" returnQuoted(&Scanner::matched1);
[^']+"'" returnQuoted(&Scanner::multiCharQuote);
}
// a typespec holds all chars after a ':' until a ';' or '%' (which are
// pushed back). It is used as a type specification in
// parser/inc/directives. Escape characters are interpreted
<typespec>{
\n d_typeName += ' '; // convert newlines to spaces
\\. | // add escaped chars as-is
[^;%] d_typeName += matched(); // accept all until ; or %
"//".* // ignore EOLN comment
// ignore std C comment
"/*" begin(StartCondition_::typecomment);
[;%] returnTypeSpec(); // back to INITIAL, returns IDENTIFIER
}
<typecomment>{
.|\n // ignored
"*/" {
d_typeName += ' ';
begin(StartCondition_::typespec);
}
}
|