fredyvonvinet / ANTLR4-Plugins-for-NetBeans

NetBeans plugins for ANTLR 4 enabling to integrate ANTLR grammar files in standard NetBeans projects (ant-based or Maven-based).
9 stars 11 forks source link

Navigate to imported Lexer file is not working #41

Open Chris2011 opened 7 years ago

Chris2011 commented 7 years ago

As you wrote it here:

An imported grammar file must be located in the same directory as the grammar importing it or in ANTLR imports directory.

If the imported grammar cannot be found, an error badge is raised. Otherwise, you should be able to navigate from your grammar to the imported grammar by pressing Ctrl and clicking on the imported grammar name. In the same way, you can navigate from a token reference, fragment reference or a parser rule reference to its definition even if this one is located in another file.

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

fredyvonvinet commented 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:

Chris2011 commented 7 years ago

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?

fredyvonvinet commented 7 years ago

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.

Chris2011 commented 7 years ago

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?

fredyvonvinet commented 7 years ago

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.

Chris2011 commented 7 years ago

Yeah I thought that. I only opened the file in IntelliJ, not the project. Thx for the explanation.

fredyvonvinet commented 7 years ago

Release 1.2.1 is published on

So dowload the new release an check if your problems are solved or not.

Chris2011 commented 7 years ago

Ok thx. :)

Chris2011 commented 7 years ago

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
Chris2011 commented 7 years ago

I'm using NetBeans 8.2 and there is no releases at the github repo. Only to let you know.

fredyvonvinet commented 7 years ago

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.

Chris2011 commented 7 years ago

Ahh ok yo you didn't create real releases/tags in git. Ok.

I will have a look into the missing maven plugin.

Chris2011 commented 7 years ago

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.

Chris2011 commented 7 years ago

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.

Chris2011 commented 7 years ago

And the structure looks like this, which is wrong for me

antlr-same-name

As you can see, both have the same name, which is wrong, because the first is source and the second is the built folder.