jison(http://zaa.ch/jison/docs/)という単純なパーサを説明文に記載して書こうとしました。文法の競合:複数のアクションが可能
%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
;
この文章は警告付きでコンパイルされています。
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
しかし、テキストを解析しようとするとうまくいきます。これはコードのフルバージョンではなく、テキスト付きのバージョンです。私はnode
にノードを追加したいです。
xml要素内にテキストを記述するにはどうすればよいですか? 'テキストテキストテキスト xsl:template>'です。私はそのようなものを持っています: 'node:open_tag | close_tag |テキスト。 –
まあ、私はこれを得ると思います。私は短い要素のようにそれを解決しました。後にそれらに参加するつもりです。 –