Question

trying out upgrading antlr4, I have 2 lines in the grammar that produce the error message:

label tok assigned to a block which is not a set

Specifically for a grammar line that looks like this:

contextRadius: tok=('radius' 'change-authorize-nas-ip') (IP4_ADDRESS|IP6_ADDRESS) 'encrypted' 'key' ID 'port' INT_TOK 'event-timestamp-window' INT_TOK 'no-reverse-path-forward-check'
    ;

What does this imply, exactly - to be a "block which is not set" and is there a general solution?

Was it helpful?

Solution

The improper label is the following:

tok=('radius' 'change-authorize-nas-ip')

In this case, ANTLR doesn't know whether to assign the token 'radius' or the token 'change-authorize-nas-ip' to the label tok. Starting with ANTLR 4, rather than generate code with unclear semantics an error is produced. You'll want to either remove the label tok or move it to the intended item. In other words, use one of the following three forms.

('radius' 'change-authorize-nas-ip')
(tok='radius' 'change-authorize-nas-ip')
('radius' tok='change-authorize-nas-ip')

The reason labels are allowed on blocks in grammars is to support items like the following. This block is a set, meaning the contents can be collapsed to matching exactly one token from a fixed set of allowed tokens. The particular item matched by the set is then assigned to x.

x=('a' | 'b')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top