I've tried to write simple parser with jison (http://zaa.ch/jison/docs/) at stuck in describing text.
%lex
%%
[\s\n\t]+ return 'TK_SPACE';
[0-9]+("."[0-9]+)?\b return 'TK_NUMBER';
[a-zA-Z]+([a-zA-Z0-9]+)?\b return 'TK_WORD';
<<EOF>> return 'EOF';
/lex
%start document
%%
document
: nodes EOF
{ console.log($1); }
| EOF
;
nodes
: nodes node
{ $1.push($2); $$ = $1; }
| node
{ $$ = [$1]; }
;
node
: text
;
text
: text text_element
{ $$ = $1 + $2; }
| text_element
;
text_element
: TK_NUMBER
| TK_WORD
| TK_SPACE
;
This grammar compiled with warnings.
Conflict in grammar: multiple actions possible when lookahead token is TK_SPACE in state 5
- reduce by rule: node -> text
- shift token (then go to state 9)
Conflict in grammar: multiple actions possible when lookahead token is TK_WORD in state 5
- reduce by rule: node -> text
- shift token (then go to state 8)
Conflict in grammar: multiple actions possible when lookahead token is TK_NUMBER in state 5
- reduce by rule: node -> text
- shift token (then go to state 7)
States with conflicts:
State 5
node -> text . #lookaheads= TK_SPACE TK_WORD TK_NUMBER EOF
text -> text .text_element #lookaheads= EOF TK_NUMBER TK_WORD TK_SPACE
text_element -> .TK_NUMBER
text_element -> .TK_WORD
text_element -> .TK_SPACE
But if i try to parse text it works fine. This is not a full version of code, just version with text. I want to append nodes at node
in feature.