0
votes

I am using Antlrworks2. There is lexer grammar which has 'lexical modes' defined in it. I have combined grammar which imports lexer grammar. After generating the code from combined grammar it will generate two .java file. Eg: If my Combined grammar file name is 'xyz.g4' the java file names are 'xyzLexer.java', 'xyzParser.java'. But when i click 'run in TestRig' in Antlrworks2 it will through below error in console.

Compiling grammar files...
warning: Supported source version 'RELEASE_6' from annotation processor 'org.netbeans.modules.openide.modules.PatchedPublicProcessor' less than -source '1.7'
warning: Supported source version 'RELEASE_6' from annotation processor 'org.netbeans.modules.openide.util.ServiceProviderProcessor' less than -source '1.7'
warning: Supported source version 'RELEASE_6' from annotation processor 'org.netbeans.modules.openide.util.NamedServiceProcessor' less than -source '1.7'
warning: Supported source version 'RELEASE_6' from annotation processor 'org.netbeans.modules.openide.util.NbBundleProcessor' less than -source '1.7'
C:\Users\cc91kor\AppData\Local\Temp\TestRigTask-1361256016169\CDFCombinedGrammarLexer.java:144: error: cannot find symbol
        case 1: _mode = INSIDE_BRACKETS;  break;
                        ^
  symbol:   variable INSIDE_BRACKETS
  location: class CDFCombinedGrammarLexer
C:\Users\cc91kor\AppData\Local\Temp\TestRigTask-1361256016169\CDFCombinedGrammarLexer.java:149: error: cannot find symbol
        case 0: _mode = INSIDE_BRACKETS;  break;
                        ^
  symbol:   variable INSIDE_BRACKETS
  location: class CDFCombinedGrammarLexer
2 errors
4 warnings
Arguments: [CDFCombinedGrammar, vt, -tokens, -tree, -gui, C:\Users\cc91kor\Desktop\vt.txt]
Can't load CDFCombinedGrammar as lexer or parser

As i observed in CDFCombinedGrammarLexer.java(In above example xyzLexer.java), the code for 'lexical mode' is not present. I could find the code for mode in the java file which has been generated from actual lexer file.

Below is the code i could see in actual lexer generated java file.

public static final int INSIDE_BRACKETS = 1;
    public static String[] modeNames = {
        "DEFAULT_MODE", "INSIDE_BRACKETS"
    };

Any help on this??? I am awaiting!!!

Thanks in advance!

1

1 Answers

0
votes

Importing multi-mode lexer grammars is not yet supported in ANTLR 4. The following issue will track the progress of this feature:

Support importing multi-mode lexer grammars