split AST for combined grammar into two, copying to lexer grammar.

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6669]
This commit is contained in:
parrt 2010-02-06 14:58:26 -08:00
parent 6d4a521ec0
commit 09eb3b5753
16 changed files with 1429 additions and 1255 deletions

View File

@ -27,8 +27,8 @@
*/
package org.antlr.v4.runtime.tree;
import org.antlr.runtime.RecognizerSharedState;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.RecognizerSharedState;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.*;
@ -89,7 +89,7 @@ public class TreeFilter extends TreeParser {
}
public TreeFilter(TreeNodeStream input, RecognizerSharedState state) {
super(input, state);
originalAdaptor = input.getTreeAdaptor();
originalAdaptor = (TreeAdaptor) input.getTreeAdaptor();
originalTokenStream = input.getTokenStream();
}

View File

@ -5,10 +5,7 @@ import org.antlr.v4.parse.ANTLRLexer;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.parse.GrammarASTAdaptor;
import org.antlr.v4.semantics.SemanticsPipeline;
import org.antlr.v4.tool.ErrorManager;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.GrammarRootAST;
import org.antlr.v4.tool.*;
import java.io.File;
import java.io.IOException;
@ -294,7 +291,7 @@ public class Tool {
}
}
public Grammar load(String fileName) {
public GrammarRootAST load(String fileName) {
ANTLRFileStream in = null;
try {
in = new ANTLRFileStream(fileName);
@ -302,38 +299,48 @@ public class Tool {
catch (IOException ioe) {
ErrorManager.toolError(ErrorType.CANNOT_OPEN_FILE, fileName, ioe);
}
Grammar g = load(in);
g.fileName = fileName;
return g;
return load(in);
}
public Grammar loadFromString(String grammar) {
Grammar g = load(new ANTLRStringStream(grammar));
g.fileName = "<string>";
return g;
public GrammarRootAST loadFromString(String grammar) {
return load(new ANTLRStringStream(grammar));
}
public Grammar load(CharStream in) {
Grammar g = null;
public GrammarRootAST load(CharStream in) {
try {
ANTLRLexer lexer = new ANTLRLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ANTLRParser p = new ANTLRParser(tokens);
p.setTreeAdaptor(new GrammarASTAdaptor(in));
ParserRuleReturnScope r = p.grammarSpec();
g = new Grammar(this, (GrammarRootAST)r.getTree());
return (GrammarRootAST)r.getTree();
}
catch (RecognitionException re) {
// TODO: do we gen errors now?
ErrorManager.internalError("can't generate this message at moment; antlr recovers");
}
return g;
return null;
}
public void process() {
// testing parser
Grammar g = load(grammarFileNames.get(0));
grammars.put(g.name, g);
GrammarRootAST ast = load(grammarFileNames.get(0));
GrammarRootAST lexerAST = null;
if ( ast.grammarType==ANTLRParser.COMBINED ) {
lexerAST = extractImplicitLexer(ast); // alters ast
}
Grammar g = new Grammar(this, ast);
process(g);
if ( lexerAST!=null ) {
// todo: don't process if errors in parser
Grammar g2 = new Grammar(this, lexerAST);
g2.implicitLexer = true;
process(g2);
}
}
protected void process(Grammar g) {
grammars.put(g.name, g);
g.loadImportedGrammars();
if ( g.ast!=null && internalOption_PrintGrammarTree ) System.out.println(g.ast.toStringTree());
//g.ast.inspect();
@ -341,6 +348,86 @@ public class Tool {
sem.process(g);
}
// TODO: Move to ast manipulation class?
/** Build lexer grammar from combined grammar that looks like:
*
* (COMBINED_GRAMMAR A
* (tokens { X (= Y 'y'))
* (OPTIONS (= x 'y'))
* (scope Blort { int x; })
* (@ members {foo})
* (@ lexer header {package jj;})
* (RULES (RULE .+)))
*
* Move rules and actions to new tree, don't dup. Split AST apart.
* We'll have this Grammar share token symbols later; don't generate
* tokenVocab or tokens{} section.
*
* Side-effects: it removes children from GRAMMAR & RULES nodes
* in combined AST. Careful: nodes are shared between
* trees after this call.
*/
public GrammarRootAST extractImplicitLexer(GrammarRootAST combinedAST) {
//System.out.println("before="+combinedAST.toStringTree());
GrammarASTAdaptor adaptor = new GrammarASTAdaptor(combinedAST.token.getInputStream());
// MAKE A GRAMMAR ROOT and ID
String lexerName = combinedAST.getChild(0).getText()+"Lexer";
GrammarRootAST lexerAST =
new GrammarRootAST(new CommonToken(ANTLRParser.GRAMMAR,"LEXER_GRAMMAR"));
lexerAST.token.setInputStream(combinedAST.token.getInputStream());
lexerAST.addChild((GrammarAST)adaptor.create(ANTLRParser.ID, lexerName));
// MOVE OPTIONS
GrammarAST optionsRoot =
(GrammarAST)combinedAST.getFirstChildWithType(ANTLRParser.OPTIONS);
if ( optionsRoot!=null ) {
GrammarAST lexerOptionsRoot = (GrammarAST)adaptor.dupNode(optionsRoot);
lexerAST.addChild(lexerOptionsRoot);
List<GrammarAST> options = optionsRoot.getChildren();
for (GrammarAST o : options) {
String optionName = o.getChild(0).getText();
if ( !Grammar.doNotCopyOptionsToLexer.contains(optionName) ) {
lexerOptionsRoot.addChild(o);
}
}
}
// MOVE lexer:: actions
List<GrammarAST> elements = combinedAST.getChildren();
for (GrammarAST e : elements) {
if ( e.getType()==ANTLRParser.AT ) {
if ( e.getChild(0).getText().equals("lexer") ) {
lexerAST.addChild(e);
elements.remove(e);
}
}
}
GrammarAST combinedRulesRoot =
(GrammarAST)combinedAST.getFirstChildWithType(ANTLRParser.RULES);
if ( combinedRulesRoot==null ) return lexerAST;
// MOVE lexer rules
GrammarAST lexerRulesRoot =
(GrammarAST)adaptor.create(ANTLRParser.RULES, "RULES");
lexerAST.addChild(lexerRulesRoot);
List<GrammarAST> rulesWeMoved = new ArrayList<GrammarAST>();
List<GrammarASTWithOptions> rules = combinedRulesRoot.getChildren();
for (GrammarASTWithOptions r : rules) {
String ruleName = r.getChild(0).getText();
if ( Character.isUpperCase(ruleName.charAt(0)) ) {
lexerRulesRoot.addChild(r);
rulesWeMoved.add(r);
}
}
rules.removeAll(rulesWeMoved);
//System.out.println("after ="+combinedAST.toStringTree());
//System.out.println("lexer ="+lexerAST.toStringTree());
return lexerAST;
}
private static void version() {
ErrorManager.info("ANTLR Parser Generator Version " + new Tool().VERSION);
}

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRLexer.g 2010-02-04 17:29:59
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRLexer.g 2010-02-06 14:39:32
/*
[The "BSD licence"]
@ -263,7 +263,7 @@ public class ANTLRLexer extends Lexer {
if ( (( input.LA(2) != '/')) ) {
alt3=1;
}
else if ( ((( true )||(( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') )))) ) {
else if ( (((( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') ))||( true ))) ) {
alt3=2;
}
else {

View File

@ -78,10 +78,7 @@ tokens {
ARG;
ARGLIST;
RET;
//LEXER_GRAMMAR;
// PARSER_GRAMMAR;
// TREE_GRAMMAR;
// COMBINED_GRAMMAR;
COMBINED;
INITACTION;
LABEL; // $x used in rewrite rules
TEMPLATE;
@ -219,7 +216,7 @@ grammarType
grammarType
@after {
if ( $t!=null ) ((GrammarRootAST)$tree).grammarType = $t.type;
else ((GrammarRootAST)$tree).grammarType=GRAMMAR;
else ((GrammarRootAST)$tree).grammarType=COMBINED;
}
: ( t=LEXER g=GRAMMAR -> GRAMMAR<GrammarRootAST>[$g, "LEXER_GRAMMAR"]
| // A standalone parser specification

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
LT=43
COMBINED=91
STAR=48
BACKTRACK_SEMPRED=95
BACKTRACK_SEMPRED=96
DOUBLE_ANGLE_STRING_LITERAL=11
FORCED_ACTION=5
ARGLIST=89
@ -10,7 +11,7 @@ SEMPRED=4
ACTION=16
TOKEN_REF=62
RULEMODIFIERS=74
ST_RESULT=99
ST_RESULT=100
RPAREN=41
RET=90
IMPORT=22
@ -23,8 +24,8 @@ GRAMMAR=27
ACTION_CHAR_LITERAL=13
WSCHARS=65
RULEACTIONS=75
INITACTION=91
ALT_REWRITE=100
INITACTION=92
ALT_REWRITE=101
IMPLIES=42
RBRACE=61
RULE=72
@ -35,7 +36,7 @@ THROWS=32
INT=64
CHAR_RANGE=82
EPSILON=83
LIST=97
LIST=98
COLONCOLON=37
WSNLCHARS=18
WS=70
@ -47,7 +48,7 @@ CLOSURE=79
PARSER=25
DOLLAR=53
PROTECTED=28
ELEMENT_OPTIONS=98
ELEMENT_OPTIONS=99
NESTED_ACTION=15
FRAGMENT=23
ID=87
@ -60,7 +61,7 @@ TREE=26
SCOPE=21
ETC=56
COMMA=38
WILDCARD=96
WILDCARD=97
DOC_COMMENT=6
PLUS=49
REWRITE_BLOCK=77
@ -72,7 +73,7 @@ UNICODE_ESC=69
HEX_DIGIT=68
RANGE=55
TOKENS=20
GATED_SEMPRED=93
GATED_SEMPRED=94
RESULT=86
BANG=47
ACTION_STRING_LITERAL=12
@ -85,9 +86,9 @@ SYNPRED=81
COLON=36
QUESTION=46
FINALLY=34
LABEL=92
LABEL=93
TEMPLATE=35
SYN_SEMPRED=94
SYN_SEMPRED=95
ERRCHAR=71
BLOCK=76
PLUS_ASSIGN=50

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ASTVerifier.g 2010-02-04 17:30:02
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ASTVerifier.g 2010-02-06 14:39:35
/*
[The "BSD license"]
@ -41,11 +41,12 @@ import java.util.List;
*/
public class ASTVerifier extends TreeParser {
public static final String[] tokenNames = new String[] {
"<invalid>", "<EOR>", "<DOWN>", "<UP>", "SEMPRED", "FORCED_ACTION", "DOC_COMMENT", "SRC", "NLCHARS", "COMMENT", "DOUBLE_QUOTE_STRING_LITERAL", "DOUBLE_ANGLE_STRING_LITERAL", "ACTION_STRING_LITERAL", "ACTION_CHAR_LITERAL", "ARG_ACTION", "NESTED_ACTION", "ACTION", "ACTION_ESC", "WSNLCHARS", "OPTIONS", "TOKENS", "SCOPE", "IMPORT", "FRAGMENT", "LEXER", "PARSER", "TREE", "GRAMMAR", "PROTECTED", "PUBLIC", "PRIVATE", "RETURNS", "THROWS", "CATCH", "FINALLY", "TEMPLATE", "COLON", "COLONCOLON", "COMMA", "SEMI", "LPAREN", "RPAREN", "IMPLIES", "LT", "GT", "ASSIGN", "QUESTION", "BANG", "STAR", "PLUS", "PLUS_ASSIGN", "OR", "ROOT", "DOLLAR", "DOT", "RANGE", "ETC", "RARROW", "TREE_BEGIN", "AT", "NOT", "RBRACE", "TOKEN_REF", "RULE_REF", "INT", "WSCHARS", "ESC_SEQ", "STRING_LITERAL", "HEX_DIGIT", "UNICODE_ESC", "WS", "ERRCHAR", "RULE", "RULES", "RULEMODIFIERS", "RULEACTIONS", "BLOCK", "REWRITE_BLOCK", "OPTIONAL", "CLOSURE", "POSITIVE_CLOSURE", "SYNPRED", "CHAR_RANGE", "EPSILON", "ALT", "ALTLIST", "RESULT", "ID", "ARG", "ARGLIST", "RET", "INITACTION", "LABEL", "GATED_SEMPRED", "SYN_SEMPRED", "BACKTRACK_SEMPRED", "WILDCARD", "LIST", "ELEMENT_OPTIONS", "ST_RESULT", "ALT_REWRITE"
"<invalid>", "<EOR>", "<DOWN>", "<UP>", "SEMPRED", "FORCED_ACTION", "DOC_COMMENT", "SRC", "NLCHARS", "COMMENT", "DOUBLE_QUOTE_STRING_LITERAL", "DOUBLE_ANGLE_STRING_LITERAL", "ACTION_STRING_LITERAL", "ACTION_CHAR_LITERAL", "ARG_ACTION", "NESTED_ACTION", "ACTION", "ACTION_ESC", "WSNLCHARS", "OPTIONS", "TOKENS", "SCOPE", "IMPORT", "FRAGMENT", "LEXER", "PARSER", "TREE", "GRAMMAR", "PROTECTED", "PUBLIC", "PRIVATE", "RETURNS", "THROWS", "CATCH", "FINALLY", "TEMPLATE", "COLON", "COLONCOLON", "COMMA", "SEMI", "LPAREN", "RPAREN", "IMPLIES", "LT", "GT", "ASSIGN", "QUESTION", "BANG", "STAR", "PLUS", "PLUS_ASSIGN", "OR", "ROOT", "DOLLAR", "DOT", "RANGE", "ETC", "RARROW", "TREE_BEGIN", "AT", "NOT", "RBRACE", "TOKEN_REF", "RULE_REF", "INT", "WSCHARS", "ESC_SEQ", "STRING_LITERAL", "HEX_DIGIT", "UNICODE_ESC", "WS", "ERRCHAR", "RULE", "RULES", "RULEMODIFIERS", "RULEACTIONS", "BLOCK", "REWRITE_BLOCK", "OPTIONAL", "CLOSURE", "POSITIVE_CLOSURE", "SYNPRED", "CHAR_RANGE", "EPSILON", "ALT", "ALTLIST", "RESULT", "ID", "ARG", "ARGLIST", "RET", "COMBINED", "INITACTION", "LABEL", "GATED_SEMPRED", "SYN_SEMPRED", "BACKTRACK_SEMPRED", "WILDCARD", "LIST", "ELEMENT_OPTIONS", "ST_RESULT", "ALT_REWRITE"
};
public static final int COMBINED=91;
public static final int LT=43;
public static final int STAR=48;
public static final int BACKTRACK_SEMPRED=95;
public static final int BACKTRACK_SEMPRED=96;
public static final int DOUBLE_ANGLE_STRING_LITERAL=11;
public static final int FORCED_ACTION=5;
public static final int ARGLIST=89;
@ -56,7 +57,7 @@ public class ASTVerifier extends TreeParser {
public static final int ACTION=16;
public static final int TOKEN_REF=62;
public static final int RULEMODIFIERS=74;
public static final int ST_RESULT=99;
public static final int ST_RESULT=100;
public static final int RPAREN=41;
public static final int RET=90;
public static final int IMPORT=22;
@ -69,8 +70,8 @@ public class ASTVerifier extends TreeParser {
public static final int GRAMMAR=27;
public static final int RULEACTIONS=75;
public static final int WSCHARS=65;
public static final int INITACTION=91;
public static final int ALT_REWRITE=100;
public static final int INITACTION=92;
public static final int ALT_REWRITE=101;
public static final int IMPLIES=42;
public static final int RULE=72;
public static final int RBRACE=61;
@ -81,7 +82,7 @@ public class ASTVerifier extends TreeParser {
public static final int CHAR_RANGE=82;
public static final int INT=64;
public static final int EPSILON=83;
public static final int LIST=97;
public static final int LIST=98;
public static final int COLONCOLON=37;
public static final int WSNLCHARS=18;
public static final int WS=70;
@ -93,7 +94,7 @@ public class ASTVerifier extends TreeParser {
public static final int PARSER=25;
public static final int DOLLAR=53;
public static final int PROTECTED=28;
public static final int ELEMENT_OPTIONS=98;
public static final int ELEMENT_OPTIONS=99;
public static final int NESTED_ACTION=15;
public static final int FRAGMENT=23;
public static final int ID=87;
@ -106,7 +107,7 @@ public class ASTVerifier extends TreeParser {
public static final int SCOPE=21;
public static final int ETC=56;
public static final int COMMA=38;
public static final int WILDCARD=96;
public static final int WILDCARD=97;
public static final int DOC_COMMENT=6;
public static final int PLUS=49;
public static final int REWRITE_BLOCK=77;
@ -118,7 +119,7 @@ public class ASTVerifier extends TreeParser {
public static final int HEX_DIGIT=68;
public static final int RANGE=55;
public static final int TOKENS=20;
public static final int GATED_SEMPRED=93;
public static final int GATED_SEMPRED=94;
public static final int RESULT=86;
public static final int BANG=47;
public static final int ACTION_STRING_LITERAL=12;
@ -132,8 +133,8 @@ public class ASTVerifier extends TreeParser {
public static final int QUESTION=46;
public static final int FINALLY=34;
public static final int TEMPLATE=35;
public static final int LABEL=92;
public static final int SYN_SEMPRED=94;
public static final int LABEL=93;
public static final int SYN_SEMPRED=95;
public static final int ERRCHAR=71;
public static final int BLOCK=76;
public static final int ASSIGN=45;
@ -4178,7 +4179,7 @@ public class ASTVerifier extends TreeParser {
static final String DFA26_minS =
"\1\4\1\uffff\2\2\6\uffff\2\57";
static final String DFA26_maxS =
"\1\140\1\uffff\2\2\6\uffff\2\140";
"\1\141\1\uffff\2\2\6\uffff\2\141";
static final String DFA26_acceptS =
"\1\uffff\1\1\2\uffff\1\2\1\3\1\4\1\5\1\6\1\7\2\uffff";
static final String DFA26_specialS =
@ -4186,7 +4187,7 @@ public class ASTVerifier extends TreeParser {
static final String[] DFA26_transitionS = {
"\1\7\13\uffff\1\6\31\uffff\1\5\2\uffff\1\1\1\uffff\1\3\2\uffff"+
"\1\1\1\uffff\1\2\1\uffff\2\4\2\uffff\1\11\3\uffff\2\4\3\uffff"+
"\1\4\10\uffff\1\5\1\uffff\3\5\14\uffff\1\10\2\uffff\1\4",
"\1\4\10\uffff\1\5\1\uffff\3\5\15\uffff\1\10\2\uffff\1\4",
"",
"\1\12",
"\1\13",
@ -4197,9 +4198,9 @@ public class ASTVerifier extends TreeParser {
"",
"",
"\1\4\4\uffff\1\4\2\uffff\1\4\4\uffff\1\4\1\uffff\2\4\3\uffff"+
"\1\4\10\uffff\1\5\23\uffff\1\4",
"\1\4\10\uffff\1\5\24\uffff\1\4",
"\1\4\4\uffff\1\4\2\uffff\1\4\4\uffff\1\4\1\uffff\2\4\3\uffff"+
"\1\4\10\uffff\1\5\23\uffff\1\4"
"\1\4\10\uffff\1\5\24\uffff\1\4"
};
static final short[] DFA26_eot = DFA.unpackEncodedString(DFA26_eotS);
@ -4243,8 +4244,8 @@ public class ASTVerifier extends TreeParser {
"\1\57\2\2\1\uffff\1\2\2\uffff\2\57\1\127\4\uffff\1\57\1\uffff\2"+
"\2\1\uffff\2\57";
static final String DFA33_maxS =
"\1\140\2\2\1\uffff\1\2\2\uffff\2\140\1\127\4\uffff\1\140\1\uffff"+
"\2\2\1\uffff\2\140";
"\1\141\2\2\1\uffff\1\2\2\uffff\2\141\1\127\4\uffff\1\141\1\uffff"+
"\2\2\1\uffff\2\141";
static final String DFA33_acceptS =
"\3\uffff\1\5\1\uffff\1\10\1\11\3\uffff\1\1\1\3\1\2\1\4\1\uffff\1"+
"\6\2\uffff\1\7\2\uffff";
@ -4252,7 +4253,7 @@ public class ASTVerifier extends TreeParser {
"\25\uffff}>";
static final String[] DFA33_transitionS = {
"\1\2\4\uffff\1\1\1\uffff\1\4\1\3\6\uffff\1\5\1\6\3\uffff\1\5"+
"\34\uffff\1\5",
"\35\uffff\1\5",
"\1\7",
"\1\10",
"",
@ -4260,23 +4261,23 @@ public class ASTVerifier extends TreeParser {
"",
"",
"\1\5\4\uffff\1\5\2\uffff\1\12\4\uffff\1\13\1\uffff\1\5\1\6"+
"\3\uffff\1\5\34\uffff\1\5",
"\3\uffff\1\5\35\uffff\1\5",
"\1\5\4\uffff\1\5\2\uffff\1\14\4\uffff\1\15\1\uffff\1\5\1\6"+
"\3\uffff\1\5\34\uffff\1\5",
"\3\uffff\1\5\35\uffff\1\5",
"\1\16",
"",
"",
"",
"",
"\1\21\4\uffff\1\20\11\uffff\1\17\1\22\3\uffff\1\17\34\uffff"+
"\1\21\4\uffff\1\20\11\uffff\1\17\1\22\3\uffff\1\17\35\uffff"+
"\1\17",
"",
"\1\23",
"\1\24",
"",
"\1\17\4\uffff\1\17\11\uffff\1\17\1\22\3\uffff\1\17\34\uffff"+
"\1\17\4\uffff\1\17\11\uffff\1\17\1\22\3\uffff\1\17\35\uffff"+
"\1\17",
"\1\17\4\uffff\1\17\11\uffff\1\17\1\22\3\uffff\1\17\34\uffff"+
"\1\17\4\uffff\1\17\11\uffff\1\17\1\22\3\uffff\1\17\35\uffff"+
"\1\17"
};
@ -4320,35 +4321,35 @@ public class ASTVerifier extends TreeParser {
static final String DFA42_minS =
"\1\57\3\2\4\uffff\1\16\3\uffff\1\3\3\uffff";
static final String DFA42_maxS =
"\4\140\4\uffff\1\142\3\uffff\1\142\3\uffff";
"\4\141\4\uffff\1\143\3\uffff\1\143\3\uffff";
static final String DFA42_acceptS =
"\4\uffff\1\11\1\12\1\1\1\2\1\uffff\1\6\1\7\1\10\1\uffff\1\5\1\4"+
"\1\3";
static final String DFA42_specialS =
"\20\uffff}>";
static final String[] DFA42_transitionS = {
"\1\5\4\uffff\1\4\11\uffff\1\2\4\uffff\1\1\34\uffff\1\3",
"\1\5\4\uffff\1\4\11\uffff\1\2\4\uffff\1\1\35\uffff\1\3",
"\1\6\2\7\13\uffff\1\7\31\uffff\1\7\2\uffff\1\7\1\uffff\1\7"+
"\2\uffff\1\7\1\uffff\1\7\1\uffff\2\7\2\uffff\1\7\3\uffff\2\7"+
"\3\uffff\1\7\10\uffff\1\7\1\uffff\3\7\14\uffff\1\7\2\uffff\1"+
"\3\uffff\1\7\10\uffff\1\7\1\uffff\3\7\15\uffff\1\7\2\uffff\1"+
"\7",
"\1\10\2\11\13\uffff\1\11\31\uffff\1\11\2\uffff\1\11\1\uffff"+
"\1\11\2\uffff\1\11\1\uffff\1\11\1\uffff\2\11\2\uffff\1\11\3"+
"\uffff\2\11\3\uffff\1\11\10\uffff\1\11\1\uffff\3\11\14\uffff"+
"\uffff\2\11\3\uffff\1\11\10\uffff\1\11\1\uffff\3\11\15\uffff"+
"\1\11\2\uffff\1\11",
"\1\12\2\13\13\uffff\1\13\31\uffff\1\13\2\uffff\1\13\1\uffff"+
"\1\13\2\uffff\1\13\1\uffff\1\13\1\uffff\2\13\2\uffff\1\13\3"+
"\uffff\2\13\3\uffff\1\13\10\uffff\1\13\1\uffff\3\13\14\uffff"+
"\uffff\2\13\3\uffff\1\13\10\uffff\1\13\1\uffff\3\13\15\uffff"+
"\1\13\2\uffff\1\13",
"",
"",
"",
"",
"\1\14\123\uffff\1\15",
"\1\14\124\uffff\1\15",
"",
"",
"",
"\1\16\136\uffff\1\17",
"\1\16\137\uffff\1\17",
"",
"",
""
@ -4395,7 +4396,7 @@ public class ASTVerifier extends TreeParser {
"\1\20\1\2\1\uffff\1\2\2\uffff\1\16\4\uffff\1\2\1\55\1\3\1\2\1\3"+
"\1\127\2\uffff\1\103\4\3";
static final String DFA51_maxS =
"\2\134\1\uffff\1\134\2\uffff\1\142\4\uffff\1\2\2\127\1\2\1\16\1"+
"\2\135\1\uffff\1\135\2\uffff\1\143\4\uffff\1\2\2\127\1\2\1\16\1"+
"\127\2\uffff\1\127\2\3\2\127";
static final String DFA51_acceptS =
"\2\uffff\1\5\1\uffff\1\10\1\11\1\uffff\1\4\1\6\1\7\1\3\6\uffff\1"+
@ -4403,15 +4404,15 @@ public class ASTVerifier extends TreeParser {
static final String DFA51_specialS =
"\30\uffff}>";
static final String[] DFA51_transitionS = {
"\1\5\55\uffff\1\1\1\2\3\uffff\1\3\30\uffff\1\4",
"\1\5\55\uffff\1\1\1\2\3\uffff\1\3\31\uffff\1\4",
"\1\6\1\7\14\uffff\1\7\51\uffff\1\7\3\uffff\2\7\3\uffff\1\7"+
"\12\uffff\3\7\13\uffff\1\7",
"\12\uffff\3\7\14\uffff\1\7",
"",
"\1\10\1\11\14\uffff\1\11\51\uffff\1\11\3\uffff\2\11\3\uffff"+
"\1\11\12\uffff\3\11\13\uffff\1\11",
"\1\11\12\uffff\3\11\14\uffff\1\11",
"",
"",
"\1\12\123\uffff\1\13",
"\1\12\124\uffff\1\13",
"",
"",
"",
@ -4603,17 +4604,17 @@ public class ASTVerifier extends TreeParser {
public static final BitSet FOLLOW_RULEMODIFIERS_in_ruleModifiers660 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ruleModifier_in_ruleModifiers662 = new BitSet(new long[]{0x0000000070800008L});
public static final BitSet FOLLOW_set_in_ruleModifier0 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_alternative_in_altList722 = new BitSet(new long[]{0x0000000000000002L,0x0000001000100000L});
public static final BitSet FOLLOW_alternative_in_altList722 = new BitSet(new long[]{0x0000000000000002L,0x0000002000100000L});
public static final BitSet FOLLOW_BLOCK_in_altListAsBlock741 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_altList_in_altListAsBlock743 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ALT_REWRITE_in_alternative762 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_alternative_in_alternative764 = new BitSet(new long[]{0x0000000000000000L,0x0000000800400000L});
public static final BitSet FOLLOW_alternative_in_alternative764 = new BitSet(new long[]{0x0000000000000000L,0x0000001000400000L});
public static final BitSet FOLLOW_rewrite_in_alternative766 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ALT_in_alternative776 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_EPSILON_in_alternative778 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_elements_in_alternative789 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ALT_in_elements807 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_element_in_elements809 = new BitSet(new long[]{0xC4D4A40000010018L,0x000000012001D008L});
public static final BitSet FOLLOW_element_in_elements809 = new BitSet(new long[]{0xC4D4A40000010018L,0x000000024001D008L});
public static final BitSet FOLLOW_labeledElement_in_element825 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_atom_in_element830 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ebnf_in_element835 = new BitSet(new long[]{0x0000000000000002L});
@ -4622,15 +4623,15 @@ public class ASTVerifier extends TreeParser {
public static final BitSet FOLLOW_GATED_SEMPRED_in_element854 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_treeSpec_in_element859 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ASSIGN_in_labeledElement872 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_labeledElement874 = new BitSet(new long[]{0xC0D0840000000000L,0x000000010001D008L});
public static final BitSet FOLLOW_ID_in_labeledElement874 = new BitSet(new long[]{0xC0D0840000000000L,0x000000020001D008L});
public static final BitSet FOLLOW_atom_in_labeledElement877 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_block_in_labeledElement879 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_PLUS_ASSIGN_in_labeledElement887 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_labeledElement889 = new BitSet(new long[]{0xC0D0840000000000L,0x000000010001D008L});
public static final BitSet FOLLOW_ID_in_labeledElement889 = new BitSet(new long[]{0xC0D0840000000000L,0x000000020001D008L});
public static final BitSet FOLLOW_atom_in_labeledElement892 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_block_in_labeledElement894 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_TREE_BEGIN_in_treeSpec911 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_element_in_treeSpec913 = new BitSet(new long[]{0xC4D4A40000010018L,0x000000012001D008L});
public static final BitSet FOLLOW_element_in_treeSpec913 = new BitSet(new long[]{0xC4D4A40000010018L,0x000000024001D008L});
public static final BitSet FOLLOW_blockSuffix_in_ebnf928 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_block_in_ebnf930 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_block_in_ebnf937 = new BitSet(new long[]{0x0000000000000002L});
@ -4649,10 +4650,10 @@ public class ASTVerifier extends TreeParser {
public static final BitSet FOLLOW_notSet_in_atom1047 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_range_in_atom1053 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_DOT_in_atom1059 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_atom1061 = new BitSet(new long[]{0x4010800000000000L,0x0000000100000008L});
public static final BitSet FOLLOW_ID_in_atom1061 = new BitSet(new long[]{0x4010800000000000L,0x0000000200000008L});
public static final BitSet FOLLOW_terminal_in_atom1063 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_DOT_in_atom1070 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_atom1072 = new BitSet(new long[]{0xC0D0800000000000L,0x0000000100000008L});
public static final BitSet FOLLOW_ID_in_atom1072 = new BitSet(new long[]{0xC0D0800000000000L,0x0000000200000008L});
public static final BitSet FOLLOW_ruleref_in_atom1074 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_terminal_in_atom1085 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ruleref_in_atom1095 = new BitSet(new long[]{0x0000000000000002L});
@ -4662,9 +4663,9 @@ public class ASTVerifier extends TreeParser {
public static final BitSet FOLLOW_block_in_notSet1127 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_set_in_notTerminal0 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_BLOCK_in_block1171 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_optionsSpec_in_block1173 = new BitSet(new long[]{0x0800000100290000L,0x0000001000100000L});
public static final BitSet FOLLOW_ruleAction_in_block1176 = new BitSet(new long[]{0x0800000100290000L,0x0000001000100000L});
public static final BitSet FOLLOW_ACTION_in_block1179 = new BitSet(new long[]{0x0800000100290000L,0x0000001000100000L});
public static final BitSet FOLLOW_optionsSpec_in_block1173 = new BitSet(new long[]{0x0800000100290000L,0x0000002000100000L});
public static final BitSet FOLLOW_ruleAction_in_block1176 = new BitSet(new long[]{0x0800000100290000L,0x0000002000100000L});
public static final BitSet FOLLOW_ACTION_in_block1179 = new BitSet(new long[]{0x0800000100290000L,0x0000002000100000L});
public static final BitSet FOLLOW_altList_in_block1182 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ROOT_in_ruleref1201 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref1203 = new BitSet(new long[]{0x0000000000004008L});
@ -4682,7 +4683,7 @@ public class ASTVerifier extends TreeParser {
public static final BitSet FOLLOW_elementOptions_in_terminal1312 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal1321 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal1330 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_terminal1332 = new BitSet(new long[]{0x0000000000000000L,0x0000000400000000L});
public static final BitSet FOLLOW_ARG_ACTION_in_terminal1332 = new BitSet(new long[]{0x0000000000000000L,0x0000000800000000L});
public static final BitSet FOLLOW_elementOptions_in_terminal1334 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal1344 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_terminal1346 = new BitSet(new long[]{0x0000000000000008L});
@ -4705,7 +4706,7 @@ public class ASTVerifier extends TreeParser {
public static final BitSet FOLLOW_ASSIGN_in_elementOption1477 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_elementOption1479 = new BitSet(new long[]{0x0000000000000000L,0x0000000000000008L});
public static final BitSet FOLLOW_STRING_LITERAL_in_elementOption1481 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_predicatedRewrite_in_rewrite1496 = new BitSet(new long[]{0x0000000000000000L,0x0000000800400000L});
public static final BitSet FOLLOW_predicatedRewrite_in_rewrite1496 = new BitSet(new long[]{0x0000000000000000L,0x0000001000400000L});
public static final BitSet FOLLOW_nakedRewrite_in_rewrite1499 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ST_RESULT_in_predicatedRewrite1511 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_SEMPRED_in_predicatedRewrite1513 = new BitSet(new long[]{0x0100000800010000L,0x0000000000180000L});
@ -4722,7 +4723,7 @@ public class ASTVerifier extends TreeParser {
public static final BitSet FOLLOW_ETC_in_rewriteAlt1583 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_EPSILON_in_rewriteAlt1591 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ALT_in_rewriteTreeAlt1610 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_rewriteTreeElement_in_rewriteTreeAlt1612 = new BitSet(new long[]{0xC400000000010008L,0x000000001001C008L});
public static final BitSet FOLLOW_rewriteTreeElement_in_rewriteTreeAlt1612 = new BitSet(new long[]{0xC400000000010008L,0x000000002001C008L});
public static final BitSet FOLLOW_rewriteTreeAtom_in_rewriteTreeElement1628 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_rewriteTree_in_rewriteTreeElement1633 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_rewriteTreeEbnf_in_rewriteTreeElement1640 = new BitSet(new long[]{0x0000000000000002L});
@ -4744,8 +4745,8 @@ public class ASTVerifier extends TreeParser {
public static final BitSet FOLLOW_REWRITE_BLOCK_in_rewriteTreeEbnf1753 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_rewriteTreeAlt_in_rewriteTreeEbnf1755 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_TREE_BEGIN_in_rewriteTree1768 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_rewriteTreeAtom_in_rewriteTree1770 = new BitSet(new long[]{0xC400000000010008L,0x000000001001C008L});
public static final BitSet FOLLOW_rewriteTreeElement_in_rewriteTree1772 = new BitSet(new long[]{0xC400000000010008L,0x000000001001C008L});
public static final BitSet FOLLOW_rewriteTreeAtom_in_rewriteTree1770 = new BitSet(new long[]{0xC400000000010008L,0x000000002001C008L});
public static final BitSet FOLLOW_rewriteTreeElement_in_rewriteTree1772 = new BitSet(new long[]{0xC400000000010008L,0x000000002001C008L});
public static final BitSet FOLLOW_TEMPLATE_in_rewriteTemplate1787 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_rewriteTemplateArgs_in_rewriteTemplate1789 = new BitSet(new long[]{0x0000000000000400L});
public static final BitSet FOLLOW_DOUBLE_QUOTE_STRING_LITERAL_in_rewriteTemplate1792 = new BitSet(new long[]{0x0000000000000008L});

View File

@ -1,6 +1,7 @@
COMBINED=91
LT=43
STAR=48
BACKTRACK_SEMPRED=95
BACKTRACK_SEMPRED=96
DOUBLE_ANGLE_STRING_LITERAL=11
FORCED_ACTION=5
ARGLIST=89
@ -10,7 +11,7 @@ SEMPRED=4
ACTION=16
TOKEN_REF=62
RULEMODIFIERS=74
ST_RESULT=99
ST_RESULT=100
RPAREN=41
RET=90
IMPORT=22
@ -23,8 +24,8 @@ ACTION_CHAR_LITERAL=13
GRAMMAR=27
RULEACTIONS=75
WSCHARS=65
INITACTION=91
ALT_REWRITE=100
INITACTION=92
ALT_REWRITE=101
IMPLIES=42
RULE=72
RBRACE=61
@ -35,7 +36,7 @@ THROWS=32
CHAR_RANGE=82
INT=64
EPSILON=83
LIST=97
LIST=98
COLONCOLON=37
WSNLCHARS=18
WS=70
@ -47,7 +48,7 @@ CLOSURE=79
PARSER=25
DOLLAR=53
PROTECTED=28
ELEMENT_OPTIONS=98
ELEMENT_OPTIONS=99
NESTED_ACTION=15
FRAGMENT=23
ID=87
@ -60,7 +61,7 @@ TREE=26
SCOPE=21
ETC=56
COMMA=38
WILDCARD=96
WILDCARD=97
DOC_COMMENT=6
PLUS=49
REWRITE_BLOCK=77
@ -72,7 +73,7 @@ UNICODE_ESC=69
HEX_DIGIT=68
RANGE=55
TOKENS=20
GATED_SEMPRED=93
GATED_SEMPRED=94
RESULT=86
BANG=47
ACTION_STRING_LITERAL=12
@ -86,8 +87,8 @@ COLON=36
QUESTION=46
FINALLY=34
TEMPLATE=35
LABEL=92
SYN_SEMPRED=94
LABEL=93
SYN_SEMPRED=95
ERRCHAR=71
BLOCK=76
ASSIGN=45

View File

@ -2,7 +2,8 @@ package org.antlr.v4.parse;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.CommonTreeAdaptor;
import org.antlr.v4.tool.*;
import org.antlr.v4.tool.GrammarAST;
import org.antlr.v4.tool.GrammarASTErrorNode;
public class GrammarASTAdaptor extends CommonTreeAdaptor {
CharStream input; // where we can find chars ref'd by tokens in tree
@ -43,4 +44,62 @@ public class GrammarASTAdaptor extends CommonTreeAdaptor {
{
return new GrammarASTErrorNode(input, start, stop, e);
}
/*
public Object nil() { return delegate. }
public boolean isNil(Object tree) {
return false;
}
public void addChild(Object t, Object child) {
}
public Object becomeRoot(Object newRoot, Object oldRoot) { return delegate. }
public Object rulePostProcessing(Object root) { return delegate. }
public int getUniqueID(Object node) { return delegate. }
public Object becomeRoot(Token newRoot, Object oldRoot) { return delegate. }
public Object create(int tokenType, Token fromToken) { return delegate. }
public Object create(int tokenType, Token fromToken, String text) { return delegate. }
public int getType(Object t) { return delegate. }
public void setType(Object t, int type) { return delegate. }
public String getText(Object t) { return delegate. }
public void setText(Object t, String text) { return delegate. }
public Token getToken(Object t) { return delegate. }
public void setTokenBoundaries(Object t, Token startToken, Token stopToken) { return delegate. }
public int getTokenStartIndex(Object t) { return delegate. }
public int getTokenStopIndex(Object t) { return delegate. }
public Object getChild(Object t, int i) { return delegate. }
public void setChild(Object t, int i, Object child) { return delegate. }
public Object deleteChild(Object t, int i) { return delegate. }
public int getChildCount(Object t) { return delegate. }
public Object getParent(Object t){ return delegate. }
public void setParent(Object t, Object parent){ return delegate. }
public int getChildIndex(Object t) { return delegate. }
public void setChildIndex(Object t, int index) { delegate.setChildIndex(t,index); }
public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t) {
delegate.replaceChildren(parent, startChildIndex, stopChildIndex, t);
}
*/
}

View File

@ -102,10 +102,10 @@ public class BasicSemanticChecks {
{
map(ANTLRParser.LEXER, ANTLRParser.LEXER);
map(ANTLRParser.LEXER, ANTLRParser.PARSER);
map(ANTLRParser.LEXER, ANTLRParser.GRAMMAR);
map(ANTLRParser.LEXER, ANTLRParser.COMBINED);
map(ANTLRParser.PARSER, ANTLRParser.PARSER);
map(ANTLRParser.PARSER, ANTLRParser.GRAMMAR);
map(ANTLRParser.PARSER, ANTLRParser.COMBINED);
map(ANTLRParser.TREE, ANTLRParser.TREE);
@ -116,7 +116,8 @@ public class BasicSemanticChecks {
// TODO: track errors?
protected static void checkGrammarName(Token nameToken) {
protected static void checkGrammarName(Grammar g, Token nameToken) {
if ( g.implicitLexer ) return;
String fullyQualifiedName = nameToken.getInputStream().getSourceName();
File f = new File(fullyQualifiedName);
String fileName = f.getName();
@ -241,7 +242,7 @@ public class BasicSemanticChecks {
ok = false;
}
}
else if ( parent.getType()==ANTLRParser.GRAMMAR &&
else if ( parent.getType()==ANTLRParser.COMBINED &&
!legalGrammarOption(g.getType(), optionID.getText()) ) { // grammar
ErrorManager.grammarError(ErrorType.ILLEGAL_OPTION,
g.fileName,
@ -394,7 +395,7 @@ public class BasicSemanticChecks {
importID,
g, delegate);
}
if ( g.getType()==ANTLRParser.GRAMMAR &&
if ( g.getType()==ANTLRParser.COMBINED &&
(delegate.name.equals(g.name+Grammar.getGrammarTypeToFileNameSuffix(ANTLRParser.LEXER))||
delegate.name.equals(g.name+Grammar.getGrammarTypeToFileNameSuffix(ANTLRParser.PARSER))) )
{

View File

@ -103,7 +103,7 @@ grammarSpec
: ^( GRAMMAR ID DOC_COMMENT?
{
name = $ID.text;
BasicSemanticChecks.checkGrammarName($ID.token);
BasicSemanticChecks.checkGrammarName(g,$ID.token);
root = (GrammarRootAST)$start;
}
prequelConstructs ^(RULES .*)

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 BasicSemanticTriggers.g 2010-02-05 14:20:12
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 BasicSemanticTriggers.g 2010-02-06 14:39:36
/*
[The "BSD license"]
@ -40,11 +40,12 @@ import java.util.List;
*/
public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter {
public static final String[] tokenNames = new String[] {
"<invalid>", "<EOR>", "<DOWN>", "<UP>", "SEMPRED", "FORCED_ACTION", "DOC_COMMENT", "SRC", "NLCHARS", "COMMENT", "DOUBLE_QUOTE_STRING_LITERAL", "DOUBLE_ANGLE_STRING_LITERAL", "ACTION_STRING_LITERAL", "ACTION_CHAR_LITERAL", "ARG_ACTION", "NESTED_ACTION", "ACTION", "ACTION_ESC", "WSNLCHARS", "OPTIONS", "TOKENS", "SCOPE", "IMPORT", "FRAGMENT", "LEXER", "PARSER", "TREE", "GRAMMAR", "PROTECTED", "PUBLIC", "PRIVATE", "RETURNS", "THROWS", "CATCH", "FINALLY", "TEMPLATE", "COLON", "COLONCOLON", "COMMA", "SEMI", "LPAREN", "RPAREN", "IMPLIES", "LT", "GT", "ASSIGN", "QUESTION", "BANG", "STAR", "PLUS", "PLUS_ASSIGN", "OR", "ROOT", "DOLLAR", "DOT", "RANGE", "ETC", "RARROW", "TREE_BEGIN", "AT", "NOT", "RBRACE", "TOKEN_REF", "RULE_REF", "INT", "WSCHARS", "ESC_SEQ", "STRING_LITERAL", "HEX_DIGIT", "UNICODE_ESC", "WS", "ERRCHAR", "RULE", "RULES", "RULEMODIFIERS", "RULEACTIONS", "BLOCK", "REWRITE_BLOCK", "OPTIONAL", "CLOSURE", "POSITIVE_CLOSURE", "SYNPRED", "CHAR_RANGE", "EPSILON", "ALT", "ALTLIST", "RESULT", "ID", "ARG", "ARGLIST", "RET", "INITACTION", "LABEL", "GATED_SEMPRED", "SYN_SEMPRED", "BACKTRACK_SEMPRED", "WILDCARD", "LIST", "ELEMENT_OPTIONS", "ST_RESULT", "ALT_REWRITE"
"<invalid>", "<EOR>", "<DOWN>", "<UP>", "SEMPRED", "FORCED_ACTION", "DOC_COMMENT", "SRC", "NLCHARS", "COMMENT", "DOUBLE_QUOTE_STRING_LITERAL", "DOUBLE_ANGLE_STRING_LITERAL", "ACTION_STRING_LITERAL", "ACTION_CHAR_LITERAL", "ARG_ACTION", "NESTED_ACTION", "ACTION", "ACTION_ESC", "WSNLCHARS", "OPTIONS", "TOKENS", "SCOPE", "IMPORT", "FRAGMENT", "LEXER", "PARSER", "TREE", "GRAMMAR", "PROTECTED", "PUBLIC", "PRIVATE", "RETURNS", "THROWS", "CATCH", "FINALLY", "TEMPLATE", "COLON", "COLONCOLON", "COMMA", "SEMI", "LPAREN", "RPAREN", "IMPLIES", "LT", "GT", "ASSIGN", "QUESTION", "BANG", "STAR", "PLUS", "PLUS_ASSIGN", "OR", "ROOT", "DOLLAR", "DOT", "RANGE", "ETC", "RARROW", "TREE_BEGIN", "AT", "NOT", "RBRACE", "TOKEN_REF", "RULE_REF", "INT", "WSCHARS", "ESC_SEQ", "STRING_LITERAL", "HEX_DIGIT", "UNICODE_ESC", "WS", "ERRCHAR", "RULE", "RULES", "RULEMODIFIERS", "RULEACTIONS", "BLOCK", "REWRITE_BLOCK", "OPTIONAL", "CLOSURE", "POSITIVE_CLOSURE", "SYNPRED", "CHAR_RANGE", "EPSILON", "ALT", "ALTLIST", "RESULT", "ID", "ARG", "ARGLIST", "RET", "COMBINED", "INITACTION", "LABEL", "GATED_SEMPRED", "SYN_SEMPRED", "BACKTRACK_SEMPRED", "WILDCARD", "LIST", "ELEMENT_OPTIONS", "ST_RESULT", "ALT_REWRITE"
};
public static final int COMBINED=91;
public static final int LT=43;
public static final int STAR=48;
public static final int BACKTRACK_SEMPRED=95;
public static final int BACKTRACK_SEMPRED=96;
public static final int DOUBLE_ANGLE_STRING_LITERAL=11;
public static final int FORCED_ACTION=5;
public static final int ARGLIST=89;
@ -55,7 +56,7 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
public static final int ACTION=16;
public static final int TOKEN_REF=62;
public static final int RULEMODIFIERS=74;
public static final int ST_RESULT=99;
public static final int ST_RESULT=100;
public static final int RPAREN=41;
public static final int RET=90;
public static final int IMPORT=22;
@ -68,8 +69,8 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
public static final int GRAMMAR=27;
public static final int RULEACTIONS=75;
public static final int WSCHARS=65;
public static final int INITACTION=91;
public static final int ALT_REWRITE=100;
public static final int INITACTION=92;
public static final int ALT_REWRITE=101;
public static final int IMPLIES=42;
public static final int RULE=72;
public static final int RBRACE=61;
@ -80,7 +81,7 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
public static final int CHAR_RANGE=82;
public static final int INT=64;
public static final int EPSILON=83;
public static final int LIST=97;
public static final int LIST=98;
public static final int COLONCOLON=37;
public static final int WSNLCHARS=18;
public static final int WS=70;
@ -92,7 +93,7 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
public static final int PARSER=25;
public static final int DOLLAR=53;
public static final int PROTECTED=28;
public static final int ELEMENT_OPTIONS=98;
public static final int ELEMENT_OPTIONS=99;
public static final int NESTED_ACTION=15;
public static final int FRAGMENT=23;
public static final int ID=87;
@ -105,7 +106,7 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
public static final int SCOPE=21;
public static final int ETC=56;
public static final int COMMA=38;
public static final int WILDCARD=96;
public static final int WILDCARD=97;
public static final int DOC_COMMENT=6;
public static final int PLUS=49;
public static final int REWRITE_BLOCK=77;
@ -117,7 +118,7 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
public static final int HEX_DIGIT=68;
public static final int RANGE=55;
public static final int TOKENS=20;
public static final int GATED_SEMPRED=93;
public static final int GATED_SEMPRED=94;
public static final int RESULT=86;
public static final int BANG=47;
public static final int ACTION_STRING_LITERAL=12;
@ -131,8 +132,8 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
public static final int QUESTION=46;
public static final int FINALLY=34;
public static final int TEMPLATE=35;
public static final int LABEL=92;
public static final int SYN_SEMPRED=94;
public static final int LABEL=93;
public static final int SYN_SEMPRED=95;
public static final int ERRCHAR=71;
public static final int BLOCK=76;
public static final int ASSIGN=45;
@ -430,7 +431,7 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
if ( state.backtracking==1 ) {
name = (ID1!=null?ID1.getText():null);
BasicSemanticChecks.checkGrammarName(ID1.token);
BasicSemanticChecks.checkGrammarName(g,ID1.token);
root = (GrammarRootAST)((GrammarAST)retval.start);
}
@ -1583,7 +1584,7 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
public static final BitSet FOLLOW_optionValue_in_option381 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_set_in_optionValue0 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_RULE_in_rule463 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_rule467 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF8L,0x0000001FFFFFFFFFL});
public static final BitSet FOLLOW_ID_in_rule467 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF8L,0x0000003FFFFFFFFFL});
public static final BitSet FOLLOW_RULE_REF_in_ruleref490 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ASSIGN_in_tokenAlias509 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_tokenAlias511 = new BitSet(new long[]{0x0000000000000000L,0x0000000000000008L});
@ -1599,11 +1600,11 @@ public class BasicSemanticTriggers extends org.antlr.v4.runtime.tree.TreeFilter
public static final BitSet FOLLOW_STRING_LITERAL_in_elementOption611 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ID_in_elementOption625 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ALT_in_multiElementAltInTreeGrammar665 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_set_in_multiElementAltInTreeGrammar667 = new BitSet(new long[]{0xFFFFFFFFFFFEFFE0L,0x0000001FFFFFFFFFL});
public static final BitSet FOLLOW_set_in_multiElementAltInTreeGrammar674 = new BitSet(new long[]{0xFFFFFFFFFFFEFFE8L,0x0000001FFFFFFFFFL});
public static final BitSet FOLLOW_set_in_multiElementAltInTreeGrammar667 = new BitSet(new long[]{0xFFFFFFFFFFFEFFE0L,0x0000003FFFFFFFFFL});
public static final BitSet FOLLOW_set_in_multiElementAltInTreeGrammar674 = new BitSet(new long[]{0xFFFFFFFFFFFEFFE8L,0x0000003FFFFFFFFFL});
public static final BitSet FOLLOW_ROOT_in_astOps700 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_BANG_in_astOps713 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_TREE_BEGIN_in_wildcardRoot736 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_WILDCARD_in_wildcardRoot738 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF8L,0x0000001FFFFFFFFFL});
public static final BitSet FOLLOW_WILDCARD_in_wildcardRoot738 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF8L,0x0000003FFFFFFFFFL});
}

View File

@ -1,6 +1,7 @@
COMBINED=91
LT=43
STAR=48
BACKTRACK_SEMPRED=95
BACKTRACK_SEMPRED=96
DOUBLE_ANGLE_STRING_LITERAL=11
FORCED_ACTION=5
ARGLIST=89
@ -10,7 +11,7 @@ SEMPRED=4
ACTION=16
TOKEN_REF=62
RULEMODIFIERS=74
ST_RESULT=99
ST_RESULT=100
RPAREN=41
RET=90
IMPORT=22
@ -23,8 +24,8 @@ ACTION_CHAR_LITERAL=13
GRAMMAR=27
RULEACTIONS=75
WSCHARS=65
INITACTION=91
ALT_REWRITE=100
INITACTION=92
ALT_REWRITE=101
IMPLIES=42
RULE=72
RBRACE=61
@ -35,7 +36,7 @@ THROWS=32
CHAR_RANGE=82
INT=64
EPSILON=83
LIST=97
LIST=98
COLONCOLON=37
WSNLCHARS=18
WS=70
@ -47,7 +48,7 @@ CLOSURE=79
PARSER=25
DOLLAR=53
PROTECTED=28
ELEMENT_OPTIONS=98
ELEMENT_OPTIONS=99
NESTED_ACTION=15
FRAGMENT=23
ID=87
@ -60,7 +61,7 @@ TREE=26
SCOPE=21
ETC=56
COMMA=38
WILDCARD=96
WILDCARD=97
DOC_COMMENT=6
PLUS=49
REWRITE_BLOCK=77
@ -72,7 +73,7 @@ UNICODE_ESC=69
HEX_DIGIT=68
RANGE=55
TOKENS=20
GATED_SEMPRED=93
GATED_SEMPRED=94
RESULT=86
BANG=47
ACTION_STRING_LITERAL=12
@ -86,8 +87,8 @@ COLON=36
QUESTION=46
FINALLY=34
TEMPLATE=35
LABEL=92
SYN_SEMPRED=94
LABEL=93
SYN_SEMPRED=95
ERRCHAR=71
BLOCK=76
ASSIGN=45

View File

@ -1,5 +1,10 @@
package org.antlr.v4.semantics;
import org.antlr.v4.tool.GrammarAST;
import org.antlr.v4.tool.Rule;
import java.util.List;
/** check for the following errors:
*
* RULE_REDEFINITION
@ -18,4 +23,22 @@ TOKEN_ALIAS_REASSIGNMENT
The
*/
public class SymbolCollisionChecks {
public List<Rule> rules;
public List<GrammarAST> terminals;
public List<GrammarAST> aliases;
public List<GrammarAST> scopes;
public List<GrammarAST> actions;
public void check(List<Rule> rules,
List<GrammarAST> terminals,
List<GrammarAST> aliases,
List<GrammarAST> scopes,
List<GrammarAST> actions)
{
checkRuleRedefinition(rules);
}
public void checkRuleRedefinition(List<Rule> rules) {
}
}

View File

@ -75,7 +75,8 @@ public class Grammar {
System.out.println("import "+t.getText());
}
try {
Grammar g = tool.load(importedGrammarName+".g");
GrammarRootAST ast = tool.load(importedGrammarName+".g");
Grammar g = new Grammar(tool, ast);
g.parent = this;
importedGrammars.add(g);
}
@ -158,7 +159,7 @@ public class Grammar {
buf.append(name);
qualifiedName = buf.toString();
}
if ( getType()==ANTLRParser.GRAMMAR ||
if ( getType()==ANTLRParser.COMBINED ||
(getType()==ANTLRParser.LEXER && implicitLexer) )
{
suffix = Grammar.getGrammarTypeToFileNameSuffix(getType());
@ -182,7 +183,6 @@ public class Grammar {
public String getTypeString() {
if ( ast==null ) return null;
if ( getType()==ANTLRParser.GRAMMAR ) return "combined";
return ANTLRParser.tokenNames[getType()].toLowerCase();
}
@ -192,7 +192,8 @@ public class Grammar {
case ANTLRParser.PARSER : return "Parser";
case ANTLRParser.TREE : return "";
// if combined grammar, gen Parser and Lexer will be done later
case ANTLRParser.GRAMMAR : return "Parser";
// TODO: we are separate now right?
case ANTLRParser.COMBINED : return "Parser";
default :
return "<invalid>";
}

View File

@ -2,9 +2,9 @@ package org.antlr.v4.tool;
import org.antlr.runtime.CommonToken;
import org.antlr.runtime.Token;
import org.antlr.runtime.tree.Tree;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.tree.CommonTree;
import org.antlr.runtime.tree.Tree;
public class GrammarAST extends CommonTree {
public GrammarAST() {;}