Note that there are some explanatory texts on larger screens.

plurals
  1. POTree Rewrite - whole subtree not just the top node should become root
    primarykey
    data
    text
    <p>I want that the tree rewrite of *addition_operator* contains the whole subtree not only the top node, so that *hint_keywords* are still in the tree.</p> <p><em>addition</em> is so complex because I want to add the T_LEFT and T_RIGHT in the tree.</p> <p>antlr 3.3</p> <p>grammar:</p> <pre><code>grammar Test; options { output = AST; } tokens { T_LEFT; T_RIGHT; T_MARKER; } @lexer::header { package com.spielwiese; } @header { package com.spielwiese; } NUM : '0' .. '9' ( '0' .. '9' )*; ASTERISK : '*'; PLUS : '+'; MINUS : '-'; WS : (' '|'\r'|'\t'|'\n') {skip();}; addition : (a=atom -&gt; $a) ( addition_operator b=atom -&gt; ^(addition_operator ^(T_LEFT $addition) ^(T_RIGHT $b) ) )+ ; atom : NUM | '(' addition ')' -&gt; addition ; addition_operator : PLUS hints? -&gt; ^(PLUS hints?) | MINUS hints? -&gt; ^(MINUS hints?) ; hints : '[' hint_keywords += hint_keyword (',' hint_keywords += hint_keyword)* ']' -&gt; $hint_keywords ; hint_keyword : 'FAST' | 'SLOW' | 'BIG' | 'THIN' ; </code></pre> <p>As far as I can see the reason is the implementation of RewriteRuleSubtreeStream#nextNode() which uses adaptor.dupNode(tree) and I want a adaptor.dupTree(tree). </p> <p>given input</p> <p>2 + [BIG] 3 - [FAST, THIN] 4</p> <p>is:</p> <pre><code> +---------+ | - | +---------+ | \ | \ T_LEFT T_RIGHT | | +---------+ | + | 4 +---------+ | \ T_LEFT T_RIGHT | | 2 3 </code></pre> <p>and should be</p> <pre><code> +---------+ | - | +---------+ / / | \ / / | \ FAST THIN T_LEFT T_RIGHT | | +---------+ | + | 4 +---------+ / | \ / T_LEFT T_RIGHT BIG | | 2 3 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload