ANTLR 4 $channel = HIDDEN and options

The v4 equivalent would look like: COMMENT : ( ‘//’ ~[\r\n]* ‘\r’? ‘\n’ | ‘/*’ .*? ‘*/’ ) -> channel(HIDDEN) ; which will put all single- and multi line comment on the HIDDEN channel. However, if you’re not doing anything with these HIDDEN-tokens, you could also skip these tokens, which would look like this: COMMENT … Read more

Is “Implicit token definition in parser rule” something to worry about?

I highly recommend correcting all instances of this warning in code of any importance. This warning was created (by me actually) to alert you to situations like the following: shiftExpr : ID ((‘<<‘ | ‘>>’) ID)?; Since ANTLR 4 encourages action code be written in separate files in the target language instead of embedding them … Read more

Once grammar is complete, what’s the best way to walk an ANTLR v4 tree?

I wouldn’t walk this manually if I were you. After generating a lexer and parser, ANTLR would also have generated a file called CfscriptBaseListener that has empty methods for all of your parser rules. You can let ANTLR walk your tree and attach a custom tree-listener in which you override only those methods/rules you’re interested … Read more

Webpack Error – configuration.node has an unknown property ‘fs’

I managed to get this to work with some help from the Webpack team. Using the following webpack configuration as recommended by the antlr4 documentation is no longer supported. Does not work { node: { fs: ’empty’, module: ’empty’, net: ’empty’ } } Working configuration { resolve: { fallback: { fs: false } } } … Read more

Antlr4 Listeners and Visitors – which to implement?

Here is quote from the book that I think is relevant: The biggest difference between the listener and visitor mechanisms is that listener methods are called by the ANTLR-provided walker object, whereas visitor methods must walk their children with explicit visit calls. Forgetting to invoke visit() on a node’s children means those subtrees don’t get … Read more

If/else statements in ANTLR using listeners

By default, ANTLR 4 generates listeners. But if you give org.antlr.v4.Tool the command line parameter -visitor, ANTLR generates visitor classes for you. These work much like listeners, but give you more control over which (sub) trees are walked/visited. This is particularly useful if you want to exclude certain (sub) trees (like else/if blocks, as in … Read more