Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple alternatives with the same label, only the last gets anything assigned to it
    primarykey
    data
    text
    <p>I have some non-reserved keywords I'm matching with rules like:</p> <pre><code>kFOO = {self.input.LT(1).text.lower() == 'foo'}? ID; </code></pre> <p>Where the <code>ID</code> token is a standard alpha-numeric string. These kinds of rules work great, except when I try to do something like this:</p> <pre><code>some_rule @after { do_something_with($t.text) } : t=kWORD1 | t=kWORD2 | t=kWORD3 ; </code></pre> <p>In the generated parser, the <code>kWORD1</code> and <code>kWORD2</code> rule functions don't return anything, but the <code>kWORD3</code> function does. As well, in the <code>some_rule</code> function, only the block trying to match <code>kWORD3</code> assign the return value to <code>t</code>. The other two invocations don't reference <code>t</code> in any way.</p> <p>(Also, I expected the following to work, but it did not, I suspect for the same underlying reason.</p> <pre><code>some_rule @after { do_something_with($t.text) } : t=( kWORD1 | kWORD2 | kWORD3) ; </code></pre> <p>Nothing gets assigned to <code>t</code> under any conditions.)</p> <p>However, the following DOES work as expected:</p> <pre><code>some_rule @after { do_something_with($t1.text or $t2.text or $t3.text) } : t1=kWORD1 | t2=kWORD2 | t3=kWORD3 ; </code></pre> <p>Each of the matching functions is generated to return a value, and each of the blocks matching the keyword rules in <code>some_rule</code> assigns the return value to their label. The problem with this solution is it gets a little excessive when there are several more alternatives.</p> <p>Half of me cries "BUG!" but this is the first antlr project I've done, so more likely there's something I don't understand.</p> <p>What's the best way to do what it is I'm trying to do here?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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