%option batch %option c++ %option noyywrap %option 8bit %option stack %option yylineno %option yyclass="json::jsonParser" %option prefix="jsonBase" %{ #include #include class jsonBaseFlexLexer; #include "jsonParse.h" %} beginobj "{" endobj "}" beginarray "[" endarray "]" beginstr "\"" endstr "\"" true "true" false "false" null "null" number [-+]?[0-9]+(\.[0-9]+)? colon ":" separator "," escape "\\" text [^\\\"]* %x OBJECT_ITEM %x OBJECT_ITEM_OR_END %x OBJECT_NEXT %x ARRAY_ITEM %x ARRAY_NEXT %x COLON %x TEXT %x STRING %x ESCAPE %% {true} { pushBoolean(true); yy_pop_state(); } {false} { pushBoolean(false); yy_pop_state(); } {number} { pushNumber(YYText()); yy_pop_state(); } {null} { pushNull(); yy_pop_state(); } {beginstr} { yy_push_state(STRING); } {beginobj} { beginObject(); BEGIN(OBJECT_ITEM_OR_END); } {beginarray} { beginArray(); BEGIN(ARRAY_NEXT); yy_push_state(ARRAY_ITEM); } {endstr} { yy_pop_state(); switch (YY_START) { case ARRAY_ITEM: case INITIAL: pushText(std::move(buf)); yy_pop_state(); break; case OBJECT_ITEM: case OBJECT_ITEM_OR_END: pushKey(std::move(buf)); BEGIN(COLON); break; } buf.clear(); } {endobj} { endObject(); yy_pop_state(); } {endarray} { endArray(); yy_pop_state(); yy_pop_state(); } {endarray} { endArray(); yy_pop_state(); } {colon} { BEGIN(OBJECT_NEXT); yy_push_state(INITIAL); } {separator} { BEGIN(OBJECT_ITEM); } {separator} { yy_push_state(INITIAL); } {escape} { yy_push_state(ESCAPE); } "\"" { buf += "\""; yy_pop_state(); } "\\" { buf += "\\"; yy_pop_state(); } "/" { buf += "/"; yy_pop_state(); } "b" { buf += "\b"; yy_pop_state(); } "f" { buf += "\f"; yy_pop_state(); } "n" { buf += "\n"; yy_pop_state(); } "r" { buf += "\r"; yy_pop_state(); } "t" { buf += "\t"; yy_pop_state(); } "u"[0-9a-fA-Z]{4} { appendEscape(YYText(), buf); yy_pop_state(); } {text} { buf += YYText(); } <*>[ \t\r\n\f] { } <*>. { LexerError("Unexpected input"); // Make iwyu think unistd.h is required [[maybe_unused]]static constexpr auto x=getpid; [[maybe_unused]]static constexpr auto y=printf; }