Open Chris2011 opened 7 years ago
Be careful! The text, you cite, deals with grammar importations, that is done with the help of import statements.
In your example, you load / import a .tokens file. Its right place is different. A .tokens file may be:
Ok, thx I understand. I only used this file, it is not created by me. The problem is, the tokens file will be generated, why should I import it into the Parser.g4 file? Do I have to created it again?
Effectively, most of the time, .a tokens file is simply generated from a lexer grammar. But it is possible to add tokens file created by a programmer.
If I understood your situation, you are in the first case.
The ANTLR plugin parses required sources (here ANTLR grammar files), in alphabetic order. So it will begin by your lexer grammar. If it is the first time or if you have cleaned the destination directory, It will see that no generated file is present so it will launch a generation process. Then it will do the same for your parser grammar. At this step, the plugin will find your generated .tokens file in destination directory.
If the alphabetic order places your parser grammar before your lexer grammar then ANTLR plugin will not find your .tokens file but that's not a problem if it exist a lexer grammar with the same name. He will force the code generation for that grammar and restart to generate code associated with your parser grammar.
Ok great, I understand it. Yes I only have the Parser and Lexer file. Nevertheless it is a bit of confusing, for someone who started to find the solution for an "error", Visual Studio Code and IntelliJ doesn't show such error. I didn't know how to handled it.
But I understand, when the build goes through it, it will use the Lexer and created a token file, after this, the error should gone away in the parser file, because it is already there and your plugin build goes through the parser file, right?
In fact, this way to work is imposed by ANTLR. There is an ANTLR plugin for IntelliJ but I don(t know how it works but except if they have added restrictions, you should have the same way to work.
Yeah I thought that. I only opened the file in IntelliJ, not the project. Thx for the explanation.
Release 1.2.1 is published on
So dowload the new release an check if your problems are solved or not.
Ok thx. :)
I can't install it:
Some plugins require plugin Maven Projects to be installed.
The plugin Maven Projects is requested in implementation version 201510222201. The following plugin is affected: ANTLR 4 Plugin for NetBeans 8.1
I'm using NetBeans 8.2 and there is no releases at the github repo. Only to let you know.
First point: It seems that you have uninstalled standard Maven plugin. It is a plugin that comes with NetBeans so download it and install it even if you don't use it.
Second point: you recover the plugin v1.2.1 for Netbeans 8.2 in nbm/1.2.1/nb8.2 directory in Github repository.
Ahh ok yo you didn't create real releases/tags in git. Ok.
I will have a look into the missing maven plugin.
My IDE wanted to install the ANTLR update for NB 8.1, I downloaded the package manually, now it is working. Strange that NB wants to install the 8.1 update.
After hit run, I have the created CSharpLexer.tokens file will not created inside the imports folder, so the problem with the missing import in the parser file, still exists.
And the structure looks like this, which is wrong for me
As you can see, both have the same name, which is wrong, because the first is source and the second is the built folder.
As you wrote it here:
Both files CSharpParser.g4 and CSharpLexer.g4 are in the same directory. And this is the line in my CSharpParser.g4 file:
options { tokenVocab=CSharpLexer; }
But I get this error:
Unable to find imported token file CSharpLexer in the same directory as current grammar or in import directory or in destinationdirectory (in same relative subdir as current grammar)
and I can't navigate to the Lexer file.
Regards
Chris