%option noinput nounput noyywrap noreject 8bit %option reentrant bison-bridge bison-locations %option prefix="kalmia" %start STRING TAG_START TAG %{ #include #define YYLTYPE KALMIALTYPE #define YYSTYPE KALMIASTYPE #include "kalmia.tab.h" #define YY_USER_ACTION \ yylloc->first_line = yylloc->last_line; \ yylloc->first_column = yylloc->last_column; \ if (*yytext == '\n') { \ yylloc->last_line += 1; \ yylloc->last_column = 0; \ } \ else { \ yylloc->last_column += yyleng; \ } %} S \x20\x0a\x0d\x09 ATTR ([\x20\x0a\x0d\x09]*)?"=" %% "" { /* xml prologue */ return PROLOG; } [\x20\x0a\x0d\x09] | [\x20\x0a\x0d\x09] { /* ignore whitespace */ } "<" { BEGIN(TAG_START); return S_TAG_OPEN; } "">" { BEGIN(INITIAL); return TAG_CLOSE; } "/>" { BEGIN(INITIAL); return EMPTY_TAG_CLOSE; } [a-zA-Z_:][a-zA-Z0-9\.\-_:]* { /* generic tag name */ BEGIN(TAG); yylval->string = strdup(yytext); return NAME; } [a-zA-Z_:][a-zA-Z0-9\.\-_:]* { /* generic attribute key */ yylval->string = strdup(yytext); return ATTR; } "=" { /* attribute "=" */ return *yytext; } "\"" { /* begin a string */ BEGIN(STRING); return *yytext; } "\"" { /* end a string */ BEGIN(TAG); return *yytext; } [^"]+ { /* within a string */ yylval->string = strdup(yytext); return TEXT; } [^\x20\x0a\x0d\x09<][^<]*[^\x20\x0a\x0d\x09<] { yylval->string = strdup(yytext); return CONTENT; }