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
|
/* description: Parses words out of html, ignoring html in the parse, but returning it in the end */
/* lexical grammar */
%lex
%%
"<"(.|\n)*?">" return 'TAG'
[a-zA-Z0-9]+ return 'WORD'
(.|\n) return 'CHAR'
<<EOF>> return 'EOF'
/lex
%start html
%% /* language grammar */
html
: contents EOF
{return $1;}
;
contents
: content
{$$ = $1;}
| contents content
{$$ = $1 + $2;}
;
content
: TAG
{
if (!yy.lexer.tagHandler) yy.lexer.tagHandler = function(tag) {return tag;};
$$ = yy.lexer.tagHandler(yytext);
}
| WORD
{
if (!yy.lexer.wordHandler) yy.lexer.wordHandler = function(word) {return word;};
$$ = yy.lexer.wordHandler(yytext);
}
| CHAR
{
if (!yy.lexer.charHandler) yy.lexer.charHandler = function(char) {return char;};
$$ = yy.lexer.charHandler(yytext);
}
;
|