antlr4 + gradle

175 views
Skip to first unread message

Tim Spriggs

unread,
Jul 26, 2018, 7:09:44 PM7/26/18
to antlr-discussion
Hello!

  I'm attempting to create a somewhat complex grammar which uses lexical modes. I'm having a heck of a time getting gradle+antlr4 to build the following structure:

Foo.g4 (parser grammar)
FooLexer.g4 (lexer grammar with modes)
FooTokens.g4 (support grammar which is imported by FooLexer)

I've looked over many bug reports and possible work-arounds but haven't found anything that ultimately fixes my issue, thus I created a minimal repository [1] and created a corresponding issue [2]. It was suggested that I post here for support help so, here I am :)

  If anyone has any suggestions, I would appreciate them!

Thanks,
-Tim

Gerald Rosenberg

unread,
Jul 26, 2018, 9:48:29 PM7/26/18
to antlr-di...@googlegroups.com
Likely the errors -- or some of the errors -- stem from the Antlr tool treating (as it should) `Foo.g4` as a composite grammar.

To instead have it treated as a split grammar, need to rename `Foo.g4` to `FooParser.g4` and change the first line of the grammar to `parser grammar Foo ;`

Tim Spriggs

unread,
Aug 6, 2018, 5:02:50 PM8/6/18
to antlr-di...@googlegroups.com
Hi Gerald,

I tried that but the difference between the parser name and the filename seems to be problematic:

  error(8): FooParser.g4:1:15: grammar name Foo and file name FooParser.g4 differ

However, using "parser grammar FooParser;" brings me back to the same set of issues and may obfuscate the results (eg: FooParserParser).

It seems the problem is understood in the bug report I filed but will not be accepted as a bug to the antlr tool so I'm going to just live with an obtuse work-around locally.

Thanks for the help!
-Tim
Reply all
Reply to author
Forward
0 new messages