got error message stuff in better shape. started semantics pipeline
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6631]
This commit is contained in:
parent
493177c04e
commit
f04dab7b83
|
@ -0,0 +1,3 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project />
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<java version="1.6.0_15" class="java.beans.XMLDecoder">
|
||||||
|
<object class="com.jformdesigner.model.FormModel">
|
||||||
|
<void property="contentType">
|
||||||
|
<string>form/swing</string>
|
||||||
|
</void>
|
||||||
|
<void property="root">
|
||||||
|
<object class="com.jformdesigner.model.FormRoot">
|
||||||
|
<void method="add">
|
||||||
|
<object class="com.jformdesigner.model.FormWindow">
|
||||||
|
<string>javax.swing.JFrame</string>
|
||||||
|
<object class="com.jformdesigner.model.FormLayoutManager">
|
||||||
|
<class>java.awt.GridLayout</class>
|
||||||
|
<void method="setProperty">
|
||||||
|
<string>columns</string>
|
||||||
|
<int>1</int>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
<void method="setProperty">
|
||||||
|
<string>title</string>
|
||||||
|
<string>ANTLR AST Viewer</string>
|
||||||
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<object class="com.jformdesigner.model.FormContainer">
|
||||||
|
<string>javax.swing.JScrollPane</string>
|
||||||
|
<object class="com.jformdesigner.model.FormLayoutManager">
|
||||||
|
<class>javax.swing.JScrollPane</class>
|
||||||
|
</object>
|
||||||
|
<void property="name">
|
||||||
|
<string>scrollPane1</string>
|
||||||
|
</void>
|
||||||
|
<void method="add">
|
||||||
|
<object class="com.jformdesigner.model.FormComponent">
|
||||||
|
<string>javax.swing.JTree</string>
|
||||||
|
<void property="name">
|
||||||
|
<string>tree</string>
|
||||||
|
</void>
|
||||||
|
<void method="auxiliary">
|
||||||
|
<void method="setProperty">
|
||||||
|
<string>JavaCodeGenerator.variableModifiers</string>
|
||||||
|
<int>1</int>
|
||||||
|
</void>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
<void property="name">
|
||||||
|
<string>this</string>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
<object class="com.jformdesigner.model.FormLayoutConstraints">
|
||||||
|
<null/>
|
||||||
|
<void method="setProperty">
|
||||||
|
<string>location</string>
|
||||||
|
<object class="java.awt.Point">
|
||||||
|
<int>0</int>
|
||||||
|
<int>0</int>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
<void method="setProperty">
|
||||||
|
<string>size</string>
|
||||||
|
<object class="java.awt.Dimension">
|
||||||
|
<int>400</int>
|
||||||
|
<int>300</int>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</void>
|
||||||
|
</object>
|
||||||
|
</java>
|
|
@ -65,9 +65,8 @@ CANNOT_GEN_DOT_FILE(arg,exception,stackTrace) ::=
|
||||||
"cannot write DFA DOT file <arg>: <exception>"
|
"cannot write DFA DOT file <arg>: <exception>"
|
||||||
BAD_ACTION_AST_STRUCTURE(exception,stackTrace) ::=
|
BAD_ACTION_AST_STRUCTURE(exception,stackTrace) ::=
|
||||||
"bad internal tree structure for action '<arg>': <exception>"
|
"bad internal tree structure for action '<arg>': <exception>"
|
||||||
BAD_AST_STRUCTURE(arg,exception,stackTrace) ::= <<
|
BAD_AST_STRUCTURE(arg,msg) ::= <<
|
||||||
bad internal tree structure '<arg>': <exception>
|
bad internal tree structure '<arg>': <msg>
|
||||||
<stackTrace; separator="\n">
|
|
||||||
>>
|
>>
|
||||||
FILE_AND_GRAMMAR_NAME_DIFFER(arg,arg2) ::=
|
FILE_AND_GRAMMAR_NAME_DIFFER(arg,arg2) ::=
|
||||||
"file <arg2> contains grammar <arg>; names must be identical"
|
"file <arg2> contains grammar <arg>; names must be identical"
|
||||||
|
@ -206,7 +205,7 @@ MISSING_AST_TYPE_IN_TREE_GRAMMAR(arg) ::=
|
||||||
"tree grammar <arg> has no ASTLabelType option"
|
"tree grammar <arg> has no ASTLabelType option"
|
||||||
REWRITE_FOR_MULTI_ELEMENT_ALT(arg) ::=
|
REWRITE_FOR_MULTI_ELEMENT_ALT(arg) ::=
|
||||||
"with rewrite=true, alt <arg> not simple node or obvious tree element; text attribute for rule not guaranteed to be correct"
|
"with rewrite=true, alt <arg> not simple node or obvious tree element; text attribute for rule not guaranteed to be correct"
|
||||||
RULE_INVALID_SET(arg) ::=
|
RULE_INVALID_SET(arg) ::=
|
||||||
"Cannot complement rule <arg>; not a simple set or element"
|
"Cannot complement rule <arg>; not a simple set or element"
|
||||||
HETERO_ILLEGAL_IN_REWRITE_ALT(arg) ::=
|
HETERO_ILLEGAL_IN_REWRITE_ALT(arg) ::=
|
||||||
"alts with rewrites can't use heterogeneous types left of ->"
|
"alts with rewrites can't use heterogeneous types left of ->"
|
||||||
|
|
|
@ -2,11 +2,8 @@ package org.antlr.v4;
|
||||||
|
|
||||||
import org.antlr.runtime.*;
|
import org.antlr.runtime.*;
|
||||||
import org.antlr.runtime.tree.*;
|
import org.antlr.runtime.tree.*;
|
||||||
import org.antlr.v4.gui.ASTViewer;
|
import org.antlr.v4.parse.*;
|
||||||
import org.antlr.v4.parse.ANTLRLexer;
|
import org.antlr.v4.semantics.SemanticsPipeline;
|
||||||
import org.antlr.v4.parse.ANTLRParser;
|
|
||||||
import org.antlr.v4.parse.ASTVerifier;
|
|
||||||
import org.antlr.v4.parse.GrammarASTAdaptor;
|
|
||||||
import org.antlr.v4.tool.*;
|
import org.antlr.v4.tool.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -117,7 +114,7 @@ public class Tool {
|
||||||
File outDir = new File(outputDirectory);
|
File outDir = new File(outputDirectory);
|
||||||
haveOutputDir = true;
|
haveOutputDir = true;
|
||||||
if (outDir.exists() && !outDir.isDirectory()) {
|
if (outDir.exists() && !outDir.isDirectory()) {
|
||||||
ErrorManager.msg(Msg.OUTPUT_DIR_IS_FILE, outputDirectory);
|
ErrorManager.error(ErrorType.OUTPUT_DIR_IS_FILE, outputDirectory);
|
||||||
libDirectory = ".";
|
libDirectory = ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +132,7 @@ public class Tool {
|
||||||
}
|
}
|
||||||
File outDir = new File(libDirectory);
|
File outDir = new File(libDirectory);
|
||||||
if (!outDir.exists()) {
|
if (!outDir.exists()) {
|
||||||
ErrorManager.msg(Msg.DIR_NOT_FOUND, libDirectory);
|
ErrorManager.error(ErrorType.DIR_NOT_FOUND, libDirectory);
|
||||||
libDirectory = ".";
|
libDirectory = ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,9 +291,9 @@ public class Tool {
|
||||||
ParserRuleReturnScope r = p.grammarSpec();
|
ParserRuleReturnScope r = p.grammarSpec();
|
||||||
GrammarAST t = (GrammarAST) r.getTree();
|
GrammarAST t = (GrammarAST) r.getTree();
|
||||||
System.out.println(t.toStringTree());
|
System.out.println(t.toStringTree());
|
||||||
String name = t.getChild(0).getText();
|
Grammar g = new Grammar(this, t);
|
||||||
Grammar g = new Grammar(this, name, t);
|
g.fileName = fileName;
|
||||||
grammars.put(name, g);
|
grammars.put(g.name, g);
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,11 +302,8 @@ public class Tool {
|
||||||
Grammar g = load(grammarFileNames.get(0));
|
Grammar g = load(grammarFileNames.get(0));
|
||||||
g.loadImportedGrammars();
|
g.loadImportedGrammars();
|
||||||
//g.ast.inspect();
|
//g.ast.inspect();
|
||||||
// use buffered node stream as we will look around in stream
|
SemanticsPipeline sem = new SemanticsPipeline();
|
||||||
// to give good error messages.
|
sem.process(g);
|
||||||
BufferedTreeNodeStream nodes = new BufferedTreeNodeStream(astAdaptor,g.ast);
|
|
||||||
ASTVerifier walker = new ASTVerifier(nodes);
|
|
||||||
walker.grammarSpec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void version() {
|
private static void version() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRLexer.g 2010-01-27 17:02:05
|
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRLexer.g 2010-01-30 14:28:45
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[The "BSD licence"]
|
[The "BSD licence"]
|
||||||
|
@ -269,7 +269,7 @@ public class ANTLRLexer extends Lexer {
|
||||||
if ( (( input.LA(2) != '/')) ) {
|
if ( (( input.LA(2) != '/')) ) {
|
||||||
alt3=1;
|
alt3=1;
|
||||||
}
|
}
|
||||||
else if ( ((( true )||(( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') )))) ) {
|
else if ( (((( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') ))||( true ))) ) {
|
||||||
alt3=2;
|
alt3=2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRParser.g 2010-01-27 17:02:07
|
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRParser.g 2010-01-30 14:28:48
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[The "BSD licence"]
|
[The "BSD licence"]
|
||||||
|
@ -292,7 +292,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: prequelConstruct, id, DOC_COMMENT, rules, grammarType
|
// elements: grammarType, DOC_COMMENT, prequelConstruct, rules, id
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -784,7 +784,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: option, OPTIONS
|
// elements: OPTIONS, option
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -1572,7 +1572,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ASSIGN, lit, TOKEN_REF
|
// elements: lit, ASSIGN, TOKEN_REF
|
||||||
// token labels: lit
|
// token labels: lit
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -1713,7 +1713,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ACTION, id, SCOPE
|
// elements: ACTION, SCOPE, id
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -1858,7 +1858,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ACTION, actionScopeName, id, AT
|
// elements: ACTION, id, actionScopeName, AT
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -2357,7 +2357,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: altListAsBlock, rulePrequel, ARG_ACTION, id, ruleModifiers, DOC_COMMENT, ruleReturns, exceptionGroup
|
// elements: ruleReturns, exceptionGroup, ruleModifiers, DOC_COMMENT, id, altListAsBlock, rulePrequel, ARG_ACTION
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -2583,7 +2583,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ARG_ACTION, ACTION, CATCH
|
// elements: ACTION, ARG_ACTION, CATCH
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -2666,7 +2666,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: FINALLY, ACTION
|
// elements: ACTION, FINALLY
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -3110,7 +3110,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: SCOPE, ACTION
|
// elements: ACTION, SCOPE
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -3189,7 +3189,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: id, SCOPE
|
// elements: SCOPE, id
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -3288,7 +3288,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: AT, ACTION, id
|
// elements: id, ACTION, AT
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -4243,7 +4243,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: labeledElement, ebnfSuffix
|
// elements: ebnfSuffix, labeledElement
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -4582,7 +4582,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ebnfSuffix, treeSpec
|
// elements: treeSpec, ebnfSuffix
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -5586,7 +5586,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: terminal, id
|
// elements: id, terminal
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -5785,7 +5785,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: notTerminal, NOT
|
// elements: NOT, notTerminal
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -6092,7 +6092,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ACTION, optionsSpec, altList, ra
|
// elements: optionsSpec, altList, ra, ACTION
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -6273,7 +6273,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ARG_ACTION, op, RULE_REF
|
// elements: op, RULE_REF, ARG_ACTION
|
||||||
// token labels: op
|
// token labels: op
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -6313,7 +6313,7 @@ public class ANTLRParser extends Parser {
|
||||||
{
|
{
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: RULE_REF, ARG_ACTION
|
// elements: ARG_ACTION, RULE_REF
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -6694,7 +6694,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ARG_ACTION, elementOptions, TOKEN_REF
|
// elements: elementOptions, ARG_ACTION, TOKEN_REF
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -6886,7 +6886,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ROOT, terminal
|
// elements: terminal, ROOT
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -6923,7 +6923,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: terminal, BANG
|
// elements: BANG, terminal
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -7440,7 +7440,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: rewriteAlt, SEMPRED, rewriteAlt, SEMPRED
|
// elements: rewriteAlt, rewriteAlt, SEMPRED, SEMPRED
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -7899,7 +7899,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ebnfSuffix, rewriteTreeAtom
|
// elements: rewriteTreeAtom, ebnfSuffix
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -8395,7 +8395,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ebnfSuffix, rewriteTreeAlt
|
// elements: rewriteTreeAlt, ebnfSuffix
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -8716,7 +8716,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: rewriteTemplateArgs, TEMPLATE, str
|
// elements: str, rewriteTemplateArgs, TEMPLATE
|
||||||
// token labels: str
|
// token labels: str
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -8865,7 +8865,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: id, rewriteTemplateArgs
|
// elements: rewriteTemplateArgs, id
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
@ -9223,7 +9223,7 @@ public class ANTLRParser extends Parser {
|
||||||
|
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
// elements: ACTION, id
|
// elements: id, ACTION
|
||||||
// token labels:
|
// token labels:
|
||||||
// rule labels: retval
|
// rule labels: retval
|
||||||
// token list labels:
|
// token list labels:
|
||||||
|
|
|
@ -31,7 +31,7 @@ tree grammar ASTVerifier;
|
||||||
options {
|
options {
|
||||||
language = Java;
|
language = Java;
|
||||||
tokenVocab = ANTLRParser;
|
tokenVocab = ANTLRParser;
|
||||||
ASTLabelType = ASTGrammar;
|
ASTLabelType = GrammarAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include the copyright in this source and also the generated source
|
// Include the copyright in this source and also the generated source
|
||||||
|
@ -63,6 +63,7 @@ options {
|
||||||
*/
|
*/
|
||||||
package org.antlr.v4.parse;
|
package org.antlr.v4.parse;
|
||||||
import org.antlr.v4.tool.*;
|
import org.antlr.v4.tool.*;
|
||||||
|
import org.antlr.v4.runtime.tree.CommonTree; // use updated v4 one not v3
|
||||||
}
|
}
|
||||||
|
|
||||||
@members {
|
@members {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,7 +25,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Check the basic semantics of the input. We check for:
|
/** Check the basic semantics of the input. We check for:
|
||||||
|
|
||||||
FILE_AND_GRAMMAR_NAME_DIFFER
|
FILE_AND_GRAMMAR_NAME_DIFFER
|
||||||
RULE_REDEFINITION(MessageSeverity.ERROR, true, true),
|
RULE_REDEFINITION(MessageSeverity.ERROR, true, true),
|
||||||
LEXER_RULES_NOT_ALLOWED(MessageSeverity.ERROR, true, true),
|
LEXER_RULES_NOT_ALLOWED(MessageSeverity.ERROR, true, true),
|
||||||
|
@ -68,7 +67,7 @@ tree grammar BasicSemanticsChecker;
|
||||||
options {
|
options {
|
||||||
language = Java;
|
language = Java;
|
||||||
tokenVocab = ANTLRParser;
|
tokenVocab = ANTLRParser;
|
||||||
ASTLabelType = ASTGrammar;
|
ASTLabelType = GrammarAST;
|
||||||
filter = true;
|
filter = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,30 +98,27 @@ options {
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.antlr.v4.parse;
|
package org.antlr.v4.semantics;
|
||||||
import org.antlr.v4.tool.*;
|
import org.antlr.v4.tool.*;
|
||||||
}
|
}
|
||||||
|
|
||||||
topdown
|
topdown
|
||||||
:
|
: grammarSpec
|
||||||
|
| optionsSpec
|
||||||
|
| tokensSpec
|
||||||
;
|
;
|
||||||
|
|
||||||
grammarSpec
|
grammarSpec
|
||||||
: ^(grammarType ID DOC_COMMENT? prequelConstruct* rules)
|
: ^(grammarType ID .*)
|
||||||
|
{
|
||||||
|
System.out.println("gname = "+$ID.text);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
grammarType
|
grammarType
|
||||||
: LEXER_GRAMMAR | PARSER_GRAMMAR | TREE_GRAMMAR | COMBINED_GRAMMAR
|
: LEXER_GRAMMAR | PARSER_GRAMMAR | TREE_GRAMMAR | COMBINED_GRAMMAR
|
||||||
;
|
;
|
||||||
|
|
||||||
prequelConstruct
|
|
||||||
: optionsSpec
|
|
||||||
| delegateGrammars
|
|
||||||
| tokensSpec
|
|
||||||
| attrScope
|
|
||||||
| action
|
|
||||||
;
|
|
||||||
|
|
||||||
optionsSpec
|
optionsSpec
|
||||||
: ^(OPTIONS option+)
|
: ^(OPTIONS option+)
|
||||||
;
|
;
|
||||||
|
@ -139,15 +135,6 @@ optionValue
|
||||||
| STAR
|
| STAR
|
||||||
;
|
;
|
||||||
|
|
||||||
delegateGrammars
|
|
||||||
: ^(IMPORT delegateGrammar+)
|
|
||||||
;
|
|
||||||
|
|
||||||
delegateGrammar
|
|
||||||
: ^(ASSIGN ID ID)
|
|
||||||
| ID
|
|
||||||
;
|
|
||||||
|
|
||||||
tokensSpec
|
tokensSpec
|
||||||
: ^(TOKENS tokenSpec+)
|
: ^(TOKENS tokenSpec+)
|
||||||
;
|
;
|
||||||
|
@ -159,257 +146,5 @@ tokenSpec
|
||||||
| RULE_REF
|
| RULE_REF
|
||||||
;
|
;
|
||||||
|
|
||||||
attrScope
|
rule: ^( RULE ID .*)
|
||||||
: ^(SCOPE ID ACTION)
|
|
||||||
;
|
|
||||||
|
|
||||||
action
|
|
||||||
: ^(AT ID? ID ACTION)
|
|
||||||
;
|
|
||||||
|
|
||||||
rules
|
|
||||||
: ^(RULES rule*)
|
|
||||||
;
|
;
|
||||||
|
|
||||||
rule: ^( RULE ID DOC_COMMENT? ruleModifiers? ARG_ACTION?
|
|
||||||
ruleReturns? rulePrequel* altListAsBlock exceptionGroup
|
|
||||||
)
|
|
||||||
;
|
|
||||||
|
|
||||||
exceptionGroup
|
|
||||||
: exceptionHandler* finallyClause?
|
|
||||||
;
|
|
||||||
|
|
||||||
exceptionHandler
|
|
||||||
: ^(CATCH ARG_ACTION ACTION)
|
|
||||||
;
|
|
||||||
|
|
||||||
finallyClause
|
|
||||||
: ^(FINALLY ACTION)
|
|
||||||
;
|
|
||||||
|
|
||||||
rulePrequel
|
|
||||||
: throwsSpec
|
|
||||||
| ruleScopeSpec
|
|
||||||
| optionsSpec
|
|
||||||
| ruleAction
|
|
||||||
;
|
|
||||||
|
|
||||||
ruleReturns
|
|
||||||
: ^(RETURNS ARG_ACTION)
|
|
||||||
;
|
|
||||||
throwsSpec
|
|
||||||
: ^(THROWS ID+)
|
|
||||||
;
|
|
||||||
|
|
||||||
ruleScopeSpec
|
|
||||||
: ^(SCOPE ACTION)
|
|
||||||
| ^(SCOPE ID+)
|
|
||||||
;
|
|
||||||
|
|
||||||
ruleAction
|
|
||||||
: ^(AT ID ACTION)
|
|
||||||
;
|
|
||||||
|
|
||||||
ruleModifiers
|
|
||||||
: ^(RULEMODIFIERS ruleModifier+)
|
|
||||||
;
|
|
||||||
|
|
||||||
ruleModifier
|
|
||||||
: PUBLIC
|
|
||||||
| PRIVATE
|
|
||||||
| PROTECTED
|
|
||||||
| FRAGMENT
|
|
||||||
;
|
|
||||||
|
|
||||||
altList
|
|
||||||
: alternative+
|
|
||||||
;
|
|
||||||
|
|
||||||
altListAsBlock
|
|
||||||
: ^(BLOCK altList)
|
|
||||||
;
|
|
||||||
|
|
||||||
alternative
|
|
||||||
: ^(ALT_REWRITE alternative rewrite)
|
|
||||||
| ^(ALT EPSILON)
|
|
||||||
| elements
|
|
||||||
;
|
|
||||||
|
|
||||||
elements
|
|
||||||
: ^(ALT element+)
|
|
||||||
;
|
|
||||||
|
|
||||||
element
|
|
||||||
: labeledElement
|
|
||||||
| atom
|
|
||||||
| ebnf
|
|
||||||
| ACTION
|
|
||||||
| SEMPRED
|
|
||||||
| GATED_SEMPRED
|
|
||||||
| treeSpec
|
|
||||||
;
|
|
||||||
|
|
||||||
labeledElement
|
|
||||||
: ^(ASSIGN ID (atom|block))
|
|
||||||
| ^(PLUS_ASSIGN ID (atom|block))
|
|
||||||
;
|
|
||||||
|
|
||||||
treeSpec
|
|
||||||
: ^(TREE_BEGIN element+)
|
|
||||||
;
|
|
||||||
|
|
||||||
ebnf: ^(blockSuffix block)
|
|
||||||
| block
|
|
||||||
;
|
|
||||||
|
|
||||||
blockSuffix
|
|
||||||
: ebnfSuffix
|
|
||||||
| ROOT
|
|
||||||
| IMPLIES
|
|
||||||
| BANG
|
|
||||||
;
|
|
||||||
|
|
||||||
ebnfSuffix
|
|
||||||
: OPTIONAL
|
|
||||||
| CLOSURE
|
|
||||||
| POSITIVE_CLOSURE
|
|
||||||
;
|
|
||||||
|
|
||||||
atom: ^(ROOT range)
|
|
||||||
| ^(BANG range)
|
|
||||||
| ^(ROOT notSet)
|
|
||||||
| ^(BANG notSet)
|
|
||||||
| range
|
|
||||||
| ^(DOT ID terminal)
|
|
||||||
| ^(DOT ID ruleref)
|
|
||||||
| terminal
|
|
||||||
| ruleref
|
|
||||||
;
|
|
||||||
|
|
||||||
notSet
|
|
||||||
: ^(NOT notTerminal)
|
|
||||||
| ^(NOT block)
|
|
||||||
;
|
|
||||||
|
|
||||||
notTerminal
|
|
||||||
: CHAR_LITERAL
|
|
||||||
| TOKEN_REF
|
|
||||||
| STRING_LITERAL
|
|
||||||
;
|
|
||||||
|
|
||||||
block
|
|
||||||
: ^(BLOCK optionsSpec? ruleAction* ACTION? altList)
|
|
||||||
;
|
|
||||||
|
|
||||||
ruleref
|
|
||||||
: ^(ROOT RULE_REF ARG_ACTION?)
|
|
||||||
| ^(BANG RULE_REF ARG_ACTION?)
|
|
||||||
| ^(RULE_REF ARG_ACTION?)
|
|
||||||
;
|
|
||||||
|
|
||||||
range
|
|
||||||
: ^(RANGE rangeElement rangeElement)
|
|
||||||
;
|
|
||||||
|
|
||||||
rangeElement
|
|
||||||
: CHAR_LITERAL
|
|
||||||
| STRING_LITERAL
|
|
||||||
| RULE_REF
|
|
||||||
| TOKEN_REF
|
|
||||||
;
|
|
||||||
|
|
||||||
terminal
|
|
||||||
: ^(CHAR_LITERAL elementOptions)
|
|
||||||
| CHAR_LITERAL
|
|
||||||
| ^(STRING_LITERAL elementOptions)
|
|
||||||
| STRING_LITERAL
|
|
||||||
| ^(TOKEN_REF elementOptions)
|
|
||||||
| TOKEN_REF
|
|
||||||
| ^(WILDCARD elementOptions)
|
|
||||||
| WILDCARD
|
|
||||||
| ^(ROOT terminal)
|
|
||||||
| ^(BANG terminal)
|
|
||||||
;
|
|
||||||
|
|
||||||
elementOptions
|
|
||||||
: ^(ELEMENT_OPTIONS elementOption+)
|
|
||||||
;
|
|
||||||
|
|
||||||
elementOption
|
|
||||||
: ID
|
|
||||||
| ^(ASSIGN ID ID)
|
|
||||||
| ^(ASSIGN ID STRING_LITERAL)
|
|
||||||
;
|
|
||||||
|
|
||||||
rewrite
|
|
||||||
: predicatedRewrite* nakedRewrite
|
|
||||||
;
|
|
||||||
|
|
||||||
predicatedRewrite
|
|
||||||
: ^(ST_RESULT SEMPRED rewriteAlt)
|
|
||||||
| ^(RESULT SEMPRED rewriteAlt)
|
|
||||||
;
|
|
||||||
|
|
||||||
nakedRewrite
|
|
||||||
: ^(ST_RESULT rewriteAlt)
|
|
||||||
| ^(RESULT rewriteAlt)
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteAlt
|
|
||||||
: rewriteTemplate
|
|
||||||
| rewriteTreeAlt
|
|
||||||
| ETC
|
|
||||||
| EPSILON
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteTreeAlt
|
|
||||||
: ^(ALT rewriteTreeElement+)
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteTreeElement
|
|
||||||
: rewriteTreeAtom
|
|
||||||
| rewriteTree
|
|
||||||
| rewriteTreeEbnf
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteTreeAtom
|
|
||||||
: CHAR_LITERAL
|
|
||||||
| ^(TOKEN_REF ARG_ACTION)
|
|
||||||
| TOKEN_REF
|
|
||||||
| RULE_REF
|
|
||||||
| STRING_LITERAL
|
|
||||||
| LABEL
|
|
||||||
| ACTION
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteTreeEbnf
|
|
||||||
: ^(ebnfSuffix ^(BLOCK rewriteTreeAlt))
|
|
||||||
;
|
|
||||||
rewriteTree
|
|
||||||
: ^(TREE_BEGIN rewriteTreeAtom rewriteTreeElement* )
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteTemplate
|
|
||||||
: ^(TEMPLATE rewriteTemplateArgs? DOUBLE_QUOTE_STRING_LITERAL)
|
|
||||||
| ^(TEMPLATE rewriteTemplateArgs? DOUBLE_ANGLE_STRING_LITERAL)
|
|
||||||
| rewriteTemplateRef
|
|
||||||
| rewriteIndirectTemplateHead
|
|
||||||
| ACTION
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteTemplateRef
|
|
||||||
: ^(TEMPLATE ID rewriteTemplateArgs?)
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteIndirectTemplateHead
|
|
||||||
: ^(TEMPLATE ACTION rewriteTemplateArgs?)
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteTemplateArgs
|
|
||||||
: ^(ARGLIST rewriteTemplateArg+)
|
|
||||||
;
|
|
||||||
|
|
||||||
rewriteTemplateArg
|
|
||||||
: ^(ARG ID ACTION)
|
|
||||||
;
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package org.antlr.v4.semantics;
|
||||||
|
|
||||||
|
import org.antlr.runtime.RecognitionException;
|
||||||
|
import org.antlr.runtime.tree.BufferedTreeNodeStream;
|
||||||
|
import org.antlr.v4.Tool;
|
||||||
|
import org.antlr.v4.parse.ASTVerifier;
|
||||||
|
import org.antlr.v4.tool.ErrorManager;
|
||||||
|
import org.antlr.v4.tool.ErrorType;
|
||||||
|
import org.antlr.v4.tool.Grammar;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
public class SemanticsPipeline {
|
||||||
|
public void process(Grammar g) {
|
||||||
|
// VALIDATE AST STRUCTURE
|
||||||
|
// use buffered node stream as we will look around in stream
|
||||||
|
// to give good error messages.
|
||||||
|
// TODO: send errors to buffer not stderr
|
||||||
|
BufferedTreeNodeStream nodes = new BufferedTreeNodeStream(Tool.astAdaptor,g.ast);
|
||||||
|
ASTVerifier walker = new ASTVerifier(nodes);
|
||||||
|
try {walker.grammarSpec();}
|
||||||
|
catch (RecognitionException re) {
|
||||||
|
ErrorManager.error(ErrorType.BAD_AST_STRUCTURE, re.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// DO BASIC / EASY SEMANTIC CHECKS
|
||||||
|
nodes.reset();
|
||||||
|
BasicSemanticsChecker basics = new BasicSemanticsChecker(nodes);
|
||||||
|
basics.downup(g.ast);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,12 @@ package org.antlr.v4.tool;
|
||||||
|
|
||||||
import org.antlr.runtime.CommonToken;
|
import org.antlr.runtime.CommonToken;
|
||||||
import org.antlr.runtime.tree.CommonTree;
|
import org.antlr.runtime.tree.CommonTree;
|
||||||
import org.antlr.tool.ToolMessage;
|
|
||||||
import org.stringtemplate.ST;
|
import org.stringtemplate.ST;
|
||||||
import org.stringtemplate.STGroup;
|
import org.stringtemplate.STGroup;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/** Defines all the errors ANTLR can generator for both the tool and for
|
/** Defines all the errors ANTLR can generator for both the tool and for
|
||||||
* issues with a grammar.
|
* issues with a grammar.
|
||||||
*
|
*
|
||||||
|
@ -47,6 +49,15 @@ public class ErrorManager {
|
||||||
/** The group of templates that represent the current message format. */
|
/** The group of templates that represent the current message format. */
|
||||||
private static STGroup format;
|
private static STGroup format;
|
||||||
|
|
||||||
|
/** Messages should be sensitive to the locale. */
|
||||||
|
private static Locale locale;
|
||||||
|
private static String formatName;
|
||||||
|
|
||||||
|
/** From a msgID how can I get the name of the template that describes
|
||||||
|
* the error or warning?
|
||||||
|
*/
|
||||||
|
private static String[] idToMessageTemplateName = new String[ErrorType.values().length];
|
||||||
|
|
||||||
static ANTLRErrorListener theDefaultErrorListener = new ANTLRErrorListener() {
|
static ANTLRErrorListener theDefaultErrorListener = new ANTLRErrorListener() {
|
||||||
public void info(String msg) {
|
public void info(String msg) {
|
||||||
if (formatWantsSingleLineMessage()) {
|
if (formatWantsSingleLineMessage()) {
|
||||||
|
@ -91,6 +102,10 @@ public class ErrorManager {
|
||||||
public static boolean formatWantsSingleLineMessage() {
|
public static boolean formatWantsSingleLineMessage() {
|
||||||
return format.getInstanceOf("wantsSingleLineMessage").toString().equals("true");
|
return format.getInstanceOf("wantsSingleLineMessage").toString().equals("true");
|
||||||
}
|
}
|
||||||
|
public static ST getMessageTemplate(ErrorType etype) {
|
||||||
|
String msgName = idToMessageTemplateName[etype.ordinal()];
|
||||||
|
return messages.getInstanceOf(msgName);
|
||||||
|
}
|
||||||
|
|
||||||
public static void resetErrorState() {
|
public static void resetErrorState() {
|
||||||
}
|
}
|
||||||
|
@ -99,44 +114,58 @@ public class ErrorManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void internalError(String error, Throwable e) {
|
||||||
|
StackTraceElement location = getLastNonErrorManagerCodeLocation(e);
|
||||||
|
String msg = "Exception "+e+"@"+location+": "+error;
|
||||||
|
theDefaultErrorListener.error(new ToolMessage(ErrorType.INTERNAL_ERROR, msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void internalError(String error) {
|
||||||
|
StackTraceElement location =
|
||||||
|
getLastNonErrorManagerCodeLocation(new Exception());
|
||||||
|
String msg = location+": "+error;
|
||||||
|
theDefaultErrorListener.error(new ToolMessage(ErrorType.INTERNAL_ERROR, msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raise a predefined message with some number of paramters for the StringTemplate but for which there
|
* Raise a predefined message with some number of paramters for the StringTemplate but for which there
|
||||||
* is no location information possible.
|
* is no location information possible.
|
||||||
* @param msg The Message Descriptor
|
* @param errorType The Message Descriptor
|
||||||
* @param args The arguments to pass to the StringTemplate
|
* @param args The arguments to pass to the StringTemplate
|
||||||
*/
|
*/
|
||||||
public static void msg(Msg msg, Object... args) {
|
public static void error(ErrorType errorType, Object... args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raise a predefined message with some number of parameters for the StringTemplate
|
* Raise a predefined message with some number of parameters for the StringTemplate
|
||||||
* with error information supplied explicitly.
|
* with error information supplied explicitly.
|
||||||
*
|
*
|
||||||
* @param msg The Message Descriptor
|
* @param errorType The Message Descriptor
|
||||||
* @param args The arguments to pass to the StringTemplate
|
* @param args The arguments to pass to the StringTemplate
|
||||||
*/
|
*/
|
||||||
public static void msg(Msg msg, int line, int column, int absOffset, int endLine, int endColumn, int endAbsOffset, Object... args) {
|
public static void error(ErrorType errorType, int line, int column, int absOffset, int endLine, int endColumn, int endAbsOffset, Object... args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raise a predefined message with some number of paramters for the StringTemplate, for which there is a CommonToken
|
* Raise a predefined message with some number of paramters for the StringTemplate, for which there is a CommonToken
|
||||||
* that can give us the location information.
|
* that can give us the location information.
|
||||||
* @param msg The message descriptor.
|
* @param errorType The message descriptor.
|
||||||
* @param t The token that contains our location information
|
* @param t The token that contains our location information
|
||||||
* @param args The varargs array of values that will be set in the StrngTemplate as arg0, arg1, ... argn
|
* @param args The varargs array of values that will be set in the StrngTemplate as arg0, arg1, ... argn
|
||||||
*/
|
*/
|
||||||
public static void msg(Msg msg, CommonToken t, Object... args) {
|
public static void error(ErrorType errorType, CommonToken t, Object... args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a message when we have a node stream and AST node that we can extract location
|
* Construct a message when we have a node stream and AST node that we can extract location
|
||||||
* from and possbily some arguments for the StringTemplate that will construct this message.
|
* from and possbily some arguments for the StringTemplate that will construct this message.
|
||||||
*
|
*
|
||||||
* @param msg The message descriptor
|
* @param errorType The message descriptor
|
||||||
* @param node The node that gives us the information we need
|
* @param node The node that gives us the information we need
|
||||||
* @param args The varargs array of values that will be set in the StrngTemplate as arg0, arg1, ... argn
|
* @param args The varargs array of values that will be set in the StrngTemplate as arg0, arg1, ... argn
|
||||||
*/
|
*/
|
||||||
public static void msg(Msg msg, CommonTree node, Object... args) {
|
public static void error(ErrorType errorType, CommonTree node, Object... args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Process a new message by sending it on to the error listener associated with the current thread
|
/** Process a new message by sending it on to the error listener associated with the current thread
|
||||||
|
@ -149,4 +178,115 @@ public class ErrorManager {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return first non ErrorManager code location for generating messages */
|
||||||
|
private static StackTraceElement getLastNonErrorManagerCodeLocation(Throwable e) {
|
||||||
|
StackTraceElement[] stack = e.getStackTrace();
|
||||||
|
int i = 0;
|
||||||
|
for (; i < stack.length; i++) {
|
||||||
|
StackTraceElement t = stack[i];
|
||||||
|
if ( t.toString().indexOf("ErrorManager")<0 ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StackTraceElement location = stack[i];
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
// S U P P O R T C O D E
|
||||||
|
|
||||||
|
protected static boolean initIdToMessageNameMapping() {
|
||||||
|
// make sure a message exists, even if it's just to indicate a problem
|
||||||
|
for (int i = 0; i < idToMessageTemplateName.length; i++) {
|
||||||
|
idToMessageTemplateName[i] = "INVALID MESSAGE ID: "+i;
|
||||||
|
}
|
||||||
|
// get list of fields and use it to fill in idToMessageTemplateName mapping
|
||||||
|
Field[] fields = ErrorManager.class.getFields();
|
||||||
|
for (int i = 0; i < fields.length; i++) {
|
||||||
|
Field f = fields[i];
|
||||||
|
String fieldName = f.getName();
|
||||||
|
if ( !fieldName.startsWith("MSG_") ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String templateName =
|
||||||
|
fieldName.substring("MSG_".length(),fieldName.length());
|
||||||
|
int msgID = 0;
|
||||||
|
try {
|
||||||
|
// get the constant value from this class object
|
||||||
|
msgID = f.getInt(ErrorManager.class);
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException iae) {
|
||||||
|
System.err.println("cannot get const value for "+f.getName());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( fieldName.startsWith("MSG_") ) {
|
||||||
|
idToMessageTemplateName[msgID] = templateName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Use reflection to find list of MSG_ fields and then verify a
|
||||||
|
* template exists for each one from the locale's group.
|
||||||
|
*/
|
||||||
|
protected static boolean verifyMessages() {
|
||||||
|
boolean ok = true;
|
||||||
|
Field[] fields = ErrorManager.class.getFields();
|
||||||
|
for (int i = 0; i < fields.length; i++) {
|
||||||
|
Field f = fields[i];
|
||||||
|
String fieldName = f.getName();
|
||||||
|
String templateName =
|
||||||
|
fieldName.substring("MSG_".length(),fieldName.length());
|
||||||
|
if ( fieldName.startsWith("MSG_") ) {
|
||||||
|
if ( !messages.isDefined(templateName) ) {
|
||||||
|
System.err.println("Message "+templateName+" in locale "+
|
||||||
|
locale+" not found");
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check for special templates
|
||||||
|
if (!messages.isDefined("warning")) {
|
||||||
|
System.err.println("Message template 'warning' not found in locale "+ locale);
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
if (!messages.isDefined("error")) {
|
||||||
|
System.err.println("Message template 'error' not found in locale "+ locale);
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Verify the message format template group */
|
||||||
|
protected static boolean verifyFormat() {
|
||||||
|
boolean ok = true;
|
||||||
|
if (!format.isDefined("location")) {
|
||||||
|
System.err.println("Format template 'location' not found in " + formatName);
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
if (!format.isDefined("message")) {
|
||||||
|
System.err.println("Format template 'message' not found in " + formatName);
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
if (!format.isDefined("report")) {
|
||||||
|
System.err.println("Format template 'report' not found in " + formatName);
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** If there are errors during ErrorManager init, we have no choice
|
||||||
|
* but to go to System.err.
|
||||||
|
*/
|
||||||
|
static void rawError(String msg) {
|
||||||
|
System.err.println(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rawError(String msg, Throwable e) {
|
||||||
|
rawError(msg);
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void panic() {
|
||||||
|
throw new Error("ANTLR ErrorManager panic");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ package org.antlr.v4.tool;
|
||||||
*
|
*
|
||||||
* @author Jim Idle - Temporal Wave LLC (jimi@temporal-wave.com)
|
* @author Jim Idle - Temporal Wave LLC (jimi@temporal-wave.com)
|
||||||
*/
|
*/
|
||||||
public enum MessageSeverity {
|
public enum ErrorSeverity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How to describe informational messages
|
* How to describe informational messages
|
||||||
|
@ -72,7 +72,7 @@ public enum MessageSeverity {
|
||||||
*
|
*
|
||||||
* @param text The human readable string representing the serverity level
|
* @param text The human readable string representing the serverity level
|
||||||
*/
|
*/
|
||||||
private MessageSeverity(String text) {
|
private ErrorSeverity(String text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,221 @@
|
||||||
|
/*
|
||||||
|
[The "BSD licence"]
|
||||||
|
Copyright (c) 2005-2008 Terence Parr
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package org.antlr.v4.tool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A complex enumeration of all the error messages that the tool can issue.
|
||||||
|
*
|
||||||
|
* When adding error messages, also add a description of the message to the
|
||||||
|
* Wiki with a location under the Wiki page
|
||||||
|
* <a href="http://www.antlr.org/wiki/display/ANTLR3/Errors+Reported+by+the+ANTLR+Tool">Errors Reported by the ANTLR Tool</a>.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Jim Idle <jimi@temporal-wave.com>
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public enum ErrorType {
|
||||||
|
CANNOT_WRITE_FILE(ErrorSeverity.ERROR, true, true),
|
||||||
|
CANNOT_CLOSE_FILE(ErrorSeverity.ERROR, true, true),
|
||||||
|
CANNOT_FIND_TOKENS_FILE(ErrorSeverity.ERROR, true, true),
|
||||||
|
ERROR_READING_TOKENS_FILE(ErrorSeverity.ERROR, true, true),
|
||||||
|
DIR_NOT_FOUND(ErrorSeverity.ERROR, true, true),
|
||||||
|
OUTPUT_DIR_IS_FILE(ErrorSeverity.ERROR, true, true),
|
||||||
|
CANNOT_OPEN_FILE(ErrorSeverity.ERROR, true, true),
|
||||||
|
FILE_AND_GRAMMAR_NAME_DIFFER(ErrorSeverity.ERROR, true, true),
|
||||||
|
FILENAME_EXTENSION_ERROR(ErrorSeverity.ERROR, true, true),
|
||||||
|
|
||||||
|
INTERNAL_ERROR(ErrorSeverity.ERROR, true, true),
|
||||||
|
INTERNAL_WARNING(ErrorSeverity.ERROR, true, true),
|
||||||
|
ERROR_CREATING_ARTIFICIAL_RULE(ErrorSeverity.ERROR, true, true),
|
||||||
|
TOKENS_FILE_SYNTAX_ERROR(ErrorSeverity.ERROR, true, true),
|
||||||
|
CANNOT_GEN_DOT_FILE(ErrorSeverity.ERROR, true, true),
|
||||||
|
BAD_AST_STRUCTURE(ErrorSeverity.ERROR, true, true),
|
||||||
|
|
||||||
|
// Code generation errors
|
||||||
|
MISSING_CODE_GEN_TEMPLATES(ErrorSeverity.ERROR, false, true),
|
||||||
|
CANNOT_CREATE_TARGET_GENERATOR(ErrorSeverity.ERROR, false, true),
|
||||||
|
|
||||||
|
// Grammar errors
|
||||||
|
SYNTAX_ERROR(ErrorSeverity.ERROR, true, true),
|
||||||
|
RULE_REDEFINITION(ErrorSeverity.ERROR, true, true),
|
||||||
|
LEXER_RULES_NOT_ALLOWED(ErrorSeverity.ERROR, true, true),
|
||||||
|
PARSER_RULES_NOT_ALLOWED(ErrorSeverity.ERROR, true, true),
|
||||||
|
CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL(ErrorSeverity.ERROR, true, true),
|
||||||
|
NO_TOKEN_DEFINITION(ErrorSeverity.ERROR, true, true),
|
||||||
|
UNDEFINED_RULE_REF(ErrorSeverity.ERROR, true, true),
|
||||||
|
LITERAL_NOT_ASSOCIATED_WITH_LEXER_RULE(ErrorSeverity.ERROR, true, true),
|
||||||
|
CANNOT_ALIAS_TOKENS_IN_LEXER(ErrorSeverity.ERROR, true, true),
|
||||||
|
ATTRIBUTE_REF_NOT_IN_RULE(ErrorSeverity.ERROR, true, true),
|
||||||
|
INVALID_RULE_SCOPE_ATTRIBUTE_REF(ErrorSeverity.ERROR, true, true),
|
||||||
|
UNKNOWN_SIMPLE_ATTRIBUTE(ErrorSeverity.ERROR, true, true),
|
||||||
|
INVALID_RULE_PARAMETER_REF(ErrorSeverity.ERROR, true, true),
|
||||||
|
UNKNOWN_RULE_ATTRIBUTE(ErrorSeverity.ERROR, true, true),
|
||||||
|
ISOLATED_RULE_SCOPE(ErrorSeverity.ERROR, true, true),
|
||||||
|
SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE(ErrorSeverity.ERROR, true, true),
|
||||||
|
LABEL_CONFLICTS_WITH_RULE(ErrorSeverity.ERROR, true, true),
|
||||||
|
LABEL_CONFLICTS_WITH_TOKEN(ErrorSeverity.ERROR, true, true),
|
||||||
|
LABEL_CONFLICTS_WITH_RULE_SCOPE_ATTRIBUTE(ErrorSeverity.ERROR, true, true),
|
||||||
|
LABEL_CONFLICTS_WITH_RULE_ARG_RETVAL(ErrorSeverity.ERROR, true, true),
|
||||||
|
ATTRIBUTE_CONFLICTS_WITH_RULE(ErrorSeverity.ERROR, true, true),
|
||||||
|
ATTRIBUTE_CONFLICTS_WITH_RULE_ARG_RETVAL(ErrorSeverity.ERROR, true, true),
|
||||||
|
LABEL_TYPE_CONFLICT(ErrorSeverity.ERROR, true, true),
|
||||||
|
ARG_RETVAL_CONFLICT(ErrorSeverity.ERROR, true, true),
|
||||||
|
NONUNIQUE_REF(ErrorSeverity.ERROR, true, true),
|
||||||
|
FORWARD_ELEMENT_REF(ErrorSeverity.ERROR, true, true),
|
||||||
|
MISSING_RULE_ARGS(ErrorSeverity.ERROR, true, true),
|
||||||
|
RULE_HAS_NO_ARGS(ErrorSeverity.ERROR, true, true),
|
||||||
|
ARGS_ON_TOKEN_REF(ErrorSeverity.ERROR, true, true),
|
||||||
|
RULE_REF_AMBIG_WITH_RULE_IN_ALT(ErrorSeverity.ERROR, true, true),
|
||||||
|
ILLEGAL_OPTION(ErrorSeverity.ERROR, true, true),
|
||||||
|
LIST_LABEL_INVALID_UNLESS_RETVAL_STRUCT(ErrorSeverity.ERROR, true, true),
|
||||||
|
UNDEFINED_TOKEN_REF_IN_REWRITE(ErrorSeverity.ERROR, true, true),
|
||||||
|
REWRITE_ELEMENT_NOT_PRESENT_ON_LHS(ErrorSeverity.ERROR, true, true),
|
||||||
|
UNDEFINED_LABEL_REF_IN_REWRITE(ErrorSeverity.ERROR, true, true),
|
||||||
|
NO_GRAMMAR_START_RULE(ErrorSeverity.ERROR, true, true),
|
||||||
|
EMPTY_COMPLEMENT(ErrorSeverity.ERROR, true, true),
|
||||||
|
UNKNOWN_DYNAMIC_SCOPE(ErrorSeverity.ERROR, true, true),
|
||||||
|
UNKNOWN_DYNAMIC_SCOPE_ATTRIBUTE(ErrorSeverity.ERROR, true, true),
|
||||||
|
ISOLATED_RULE_ATTRIBUTE(ErrorSeverity.ERROR, true, true),
|
||||||
|
INVALID_ACTION_SCOPE(ErrorSeverity.ERROR, true, true),
|
||||||
|
ACTION_REDEFINITION(ErrorSeverity.ERROR, true, true),
|
||||||
|
INVALID_TEMPLATE_ACTION(ErrorSeverity.ERROR, true, true),
|
||||||
|
ARG_INIT_VALUES_ILLEGAL(ErrorSeverity.ERROR, true, true),
|
||||||
|
REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION(ErrorSeverity.ERROR, true, true),
|
||||||
|
NO_RULES(ErrorSeverity.ERROR, true, true),
|
||||||
|
WRITE_TO_READONLY_ATTR(ErrorSeverity.ERROR, true, true),
|
||||||
|
MISSING_AST_TYPE_IN_TREE_GRAMMAR(ErrorSeverity.ERROR, true, true),
|
||||||
|
REWRITE_FOR_MULTI_ELEMENT_ALT(ErrorSeverity.ERROR, true, true),
|
||||||
|
RULE_INVALID_SET(ErrorSeverity.ERROR, true, true),
|
||||||
|
HETERO_ILLEGAL_IN_REWRITE_ALT(ErrorSeverity.ERROR, true, true),
|
||||||
|
NO_SUCH_GRAMMAR_SCOPE(ErrorSeverity.ERROR, true, true),
|
||||||
|
NO_SUCH_RULE_IN_SCOPE(ErrorSeverity.ERROR, true, true),
|
||||||
|
TOKEN_ALIAS_CONFLICT(ErrorSeverity.ERROR, true, true),
|
||||||
|
TOKEN_ALIAS_REASSIGNMENT(ErrorSeverity.ERROR, true, true),
|
||||||
|
TOKEN_VOCAB_IN_DELEGATE(ErrorSeverity.ERROR, true, true),
|
||||||
|
INVALID_IMPORT(ErrorSeverity.ERROR, true, true),
|
||||||
|
IMPORTED_TOKENS_RULE_EMPTY(ErrorSeverity.ERROR, true, true),
|
||||||
|
IMPORT_NAME_CLASH(ErrorSeverity.ERROR, true, true),
|
||||||
|
AST_OP_WITH_NON_AST_OUTPUT_OPTION(ErrorSeverity.ERROR, true, true),
|
||||||
|
AST_OP_IN_ALT_WITH_REWRITE(ErrorSeverity.ERROR, true, true),
|
||||||
|
WILDCARD_AS_ROOT(ErrorSeverity.ERROR, true, true),
|
||||||
|
CONFLICTING_OPTION_IN_TREE_FILTER(ErrorSeverity.ERROR, true, true),
|
||||||
|
/** Documentation comment is unterminated */
|
||||||
|
UNTERMINATED_DOC_COMMENT(ErrorSeverity.ERROR, true, true),
|
||||||
|
|
||||||
|
// Dependency sorting errors
|
||||||
|
//
|
||||||
|
/** t1.g -> t2.g -> t3.g ->t1.g */
|
||||||
|
CIRCULAR_DEPENDENCY(ErrorSeverity.ERROR, true, true),
|
||||||
|
|
||||||
|
// Simple informational messages
|
||||||
|
//
|
||||||
|
/** A standby generic message that jsut spits out the arguments it is given */
|
||||||
|
GENERIC_INFO(ErrorSeverity.INFO, false, false),
|
||||||
|
/** How to print out the version of the ANTLR tool that we are */
|
||||||
|
ANTLR_VERSION(ErrorSeverity.INFO, false, false),
|
||||||
|
|
||||||
|
// Command line tool errors/warnings
|
||||||
|
/** -fo option was incorrectly formed */
|
||||||
|
MISSING_OUTPUT_FO(ErrorSeverity.WARNING, false, false),
|
||||||
|
/** -lib option is missing a directory argument */
|
||||||
|
MISSING_LIBDIR(ErrorSeverity.WARNING, false, false),
|
||||||
|
/** -format option was not given the name of a message format */
|
||||||
|
MISSING_FORMAT(ErrorSeverity.WARNING, false, false),
|
||||||
|
/** Max state count missing from the option */
|
||||||
|
MISSING_MAXSTATES(ErrorSeverity.WARNING, false, false),
|
||||||
|
/** Max labels in a switch argument is missing */
|
||||||
|
MISSING_MAXSWITCH(ErrorSeverity.WARNING, false, false),
|
||||||
|
/** Min labels in a switch argument is missing */
|
||||||
|
MISSING_MINSWITCH(ErrorSeverity.WARNING, false, false),
|
||||||
|
/** Missing recursion limit argument */
|
||||||
|
MISSING_MAXRECUR(ErrorSeverity.WARNING, false, false),
|
||||||
|
/** Missing max edges argument */
|
||||||
|
MISSING_MAXEDGE(ErrorSeverity.WARNING, false, false),
|
||||||
|
/** Misng ms timeout argument */
|
||||||
|
MISSING_MAXTIME(ErrorSeverity.WARNING, false, false),
|
||||||
|
|
||||||
|
// Help messages
|
||||||
|
HELP_USAGE(ErrorSeverity.INFO, false, false),
|
||||||
|
HELP_EXTENDED(ErrorSeverity.INFO, false, false),
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local storage for the severity level of the message
|
||||||
|
*/
|
||||||
|
private ErrorSeverity severity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the severity level of this message
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ErrorSeverity getSeverity() {
|
||||||
|
return severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal storage for the flag that indicates whether this particular message
|
||||||
|
* should abort the analysis phase or not.
|
||||||
|
*/
|
||||||
|
private Boolean abortsAnalysis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the raising of this error messsage should abort the
|
||||||
|
* analysis phase (or prevent it from starting).
|
||||||
|
*
|
||||||
|
* @return true if this message should abort the analysis phase
|
||||||
|
*/
|
||||||
|
public Boolean abortsAnalysis() {
|
||||||
|
return abortsAnalysis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the raising of this error message aborts code
|
||||||
|
* generation or not.
|
||||||
|
*/
|
||||||
|
private Boolean abortsCodegen;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the raising of this error message aborts code
|
||||||
|
* generation or not.
|
||||||
|
*
|
||||||
|
* @return true if this message should abort code generation
|
||||||
|
*/
|
||||||
|
public Boolean abortsCodegen() {
|
||||||
|
return abortsCodegen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local constructor produces an instance of the entries in this Enum
|
||||||
|
*/
|
||||||
|
private ErrorType(ErrorSeverity severity, boolean abortsAnalysis, boolean abortsCodegen) {
|
||||||
|
this.severity = severity;
|
||||||
|
this.abortsAnalysis = abortsAnalysis;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,13 +16,14 @@ public class Grammar {
|
||||||
public String name;
|
public String name;
|
||||||
public GrammarAST ast;
|
public GrammarAST ast;
|
||||||
public String text; // testing only
|
public String text; // testing only
|
||||||
|
public String fileName;
|
||||||
|
|
||||||
protected List<Grammar> importedGrammars;
|
protected List<Grammar> importedGrammars;
|
||||||
protected Map<String, Rule> rules = new HashMap<String, Rule>();
|
protected Map<String, Rule> rules = new HashMap<String, Rule>();
|
||||||
|
|
||||||
public Grammar(Tool tool, String name, GrammarAST ast) {
|
public Grammar(Tool tool, GrammarAST ast) {
|
||||||
this.tool = tool;
|
this.tool = tool;
|
||||||
this.name = name;
|
this.name = ast.getChild(0).getText();
|
||||||
this.ast = ast;
|
this.ast = ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,14 @@
|
||||||
package org.antlr.v4.tool;
|
package org.antlr.v4.tool;
|
||||||
|
|
||||||
import org.antlr.runtime.Token;
|
import org.antlr.runtime.Token;
|
||||||
import org.antlr.runtime.tree.CommonTree;
|
import org.antlr.v4.runtime.tree.CommonTree;
|
||||||
import org.antlr.runtime.tree.Tree;
|
import org.antlr.runtime.tree.Tree;
|
||||||
import org.antlr.v4.gui.ASTViewer;
|
|
||||||
|
|
||||||
public class GrammarAST extends CommonTree {
|
public class GrammarAST extends CommonTree {
|
||||||
public GrammarAST() {;}
|
public GrammarAST() {;}
|
||||||
public GrammarAST(Token t) { super(t); }
|
public GrammarAST(Token t) { super(t); }
|
||||||
public GrammarAST(GrammarAST node) { super(node); }
|
public GrammarAST(GrammarAST node) { super(node); }
|
||||||
|
|
||||||
public void inspect() {
|
|
||||||
ASTViewer viewer = new ASTViewer(this);
|
|
||||||
viewer.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tree dupNode() {
|
public Tree dupNode() {
|
||||||
return new GrammarAST(this);
|
return new GrammarAST(this);
|
||||||
|
|
|
@ -1,5 +1,89 @@
|
||||||
package org.antlr.v4.tool;
|
package org.antlr.v4.tool;
|
||||||
|
|
||||||
|
import org.stringtemplate.ST;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
public class Message {
|
public class Message {
|
||||||
|
// msgST is the actual text of the message
|
||||||
|
public ST msgST;
|
||||||
|
// these are for supporting different output formats
|
||||||
|
public ST locationST;
|
||||||
|
public ST reportST;
|
||||||
|
public ST messageFormatST;
|
||||||
|
|
||||||
|
public ErrorType errorType;
|
||||||
|
public Object[] args;
|
||||||
|
public Throwable e;
|
||||||
|
// used for location template
|
||||||
|
public String file;
|
||||||
|
public int line = -1;
|
||||||
|
public int column = -1;
|
||||||
|
|
||||||
|
public Message() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message(ErrorType errorType) {
|
||||||
|
this.errorType = errorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message(ErrorType errorType, Object... args) {
|
||||||
|
this(errorType);
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message(ErrorType errorType, Throwable e, Object... args) {
|
||||||
|
this(errorType, args);
|
||||||
|
this.e = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return a new template instance every time someone tries to print
|
||||||
|
* a Message.
|
||||||
|
*/
|
||||||
|
public ST getMessageTemplate() {
|
||||||
|
return ErrorManager.getMessageTemplate(errorType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
// setup the location
|
||||||
|
locationST = ErrorManager.getLocationFormat();
|
||||||
|
reportST = ErrorManager.getReportFormat();
|
||||||
|
messageFormatST = ErrorManager.getMessageFormat();
|
||||||
|
ST messageST = getMessageTemplate();
|
||||||
|
|
||||||
|
if ( args!=null ) { // fill in arg1, arg2, ...
|
||||||
|
for (int i=0; i<args.length; i++) {
|
||||||
|
messageST.add("args"+(i+1), args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( e!=null ) {
|
||||||
|
messageST.add("exception", e);
|
||||||
|
messageST.add("stackTrace", e.getStackTrace());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean locationValid = false;
|
||||||
|
if (line != -1) {
|
||||||
|
locationST.add("line", line);
|
||||||
|
locationValid = true;
|
||||||
|
}
|
||||||
|
if (column != -1) {
|
||||||
|
locationST.add("column", column);
|
||||||
|
locationValid = true;
|
||||||
|
}
|
||||||
|
if (file != null) {
|
||||||
|
locationST.add("file", file);
|
||||||
|
locationValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
messageFormatST.add("id", errorType);
|
||||||
|
messageFormatST.add("text", messageST);
|
||||||
|
|
||||||
|
if (locationValid) {
|
||||||
|
reportST.add("location", locationST);
|
||||||
|
}
|
||||||
|
reportST.add("message", messageFormatST);
|
||||||
|
reportST.add("type", errorType.getSeverity());
|
||||||
|
|
||||||
|
return reportST.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,222 +0,0 @@
|
||||||
/*
|
|
||||||
[The "BSD licence"]
|
|
||||||
Copyright (c) 2005-2008 Terence Parr
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
1. Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
3. The name of the author may not be used to endorse or promote products
|
|
||||||
derived from this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package org.antlr.v4.tool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A complex enumeration of all the error messages that the tool can issue.
|
|
||||||
*
|
|
||||||
* When adding error messages, also add a description of the message to the
|
|
||||||
* Wiki with a location under the Wiki page
|
|
||||||
* <a href="http://www.antlr.org/wiki/display/ANTLR3/Errors+Reported+by+the+ANTLR+Tool">Errors Reported by the ANTLR Tool</a>.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Jim Idle <jimi@temporal-wave.com>
|
|
||||||
* @since 4.0
|
|
||||||
*/
|
|
||||||
public enum Msg {
|
|
||||||
|
|
||||||
CANNOT_WRITE_FILE(MessageSeverity.ERROR, true, true),
|
|
||||||
CANNOT_CLOSE_FILE(MessageSeverity.ERROR, true, true),
|
|
||||||
CANNOT_FIND_TOKENS_FILE(MessageSeverity.ERROR, true, true),
|
|
||||||
ERROR_READING_TOKENS_FILE(MessageSeverity.ERROR, true, true),
|
|
||||||
DIR_NOT_FOUND(MessageSeverity.ERROR, true, true),
|
|
||||||
OUTPUT_DIR_IS_FILE(MessageSeverity.ERROR, true, true),
|
|
||||||
CANNOT_OPEN_FILE(MessageSeverity.ERROR, true, true),
|
|
||||||
FILE_AND_GRAMMAR_NAME_DIFFER(MessageSeverity.ERROR, true, true),
|
|
||||||
FILENAME_EXTENSION_ERROR(MessageSeverity.ERROR, true, true),
|
|
||||||
|
|
||||||
INTERNAL_ERROR(MessageSeverity.ERROR, true, true),
|
|
||||||
INTERNAL_WARNING(MessageSeverity.ERROR, true, true),
|
|
||||||
ERROR_CREATING_ARTIFICIAL_RULE(MessageSeverity.ERROR, true, true),
|
|
||||||
TOKENS_FILE_SYNTAX_ERROR(MessageSeverity.ERROR, true, true),
|
|
||||||
CANNOT_GEN_DOT_FILE(MessageSeverity.ERROR, true, true),
|
|
||||||
BAD_AST_STRUCTURE(MessageSeverity.ERROR, true, true),
|
|
||||||
|
|
||||||
// Code generation errors
|
|
||||||
MISSING_CODE_GEN_TEMPLATES(MessageSeverity.ERROR, false, true),
|
|
||||||
CANNOT_CREATE_TARGET_GENERATOR(MessageSeverity.ERROR, false, true),
|
|
||||||
|
|
||||||
// Grammar errors
|
|
||||||
SYNTAX_ERROR(MessageSeverity.ERROR, true, true),
|
|
||||||
RULE_REDEFINITION(MessageSeverity.ERROR, true, true),
|
|
||||||
LEXER_RULES_NOT_ALLOWED(MessageSeverity.ERROR, true, true),
|
|
||||||
PARSER_RULES_NOT_ALLOWED(MessageSeverity.ERROR, true, true),
|
|
||||||
CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL(MessageSeverity.ERROR, true, true),
|
|
||||||
NO_TOKEN_DEFINITION(MessageSeverity.ERROR, true, true),
|
|
||||||
UNDEFINED_RULE_REF(MessageSeverity.ERROR, true, true),
|
|
||||||
LITERAL_NOT_ASSOCIATED_WITH_LEXER_RULE(MessageSeverity.ERROR, true, true),
|
|
||||||
CANNOT_ALIAS_TOKENS_IN_LEXER(MessageSeverity.ERROR, true, true),
|
|
||||||
ATTRIBUTE_REF_NOT_IN_RULE(MessageSeverity.ERROR, true, true),
|
|
||||||
INVALID_RULE_SCOPE_ATTRIBUTE_REF(MessageSeverity.ERROR, true, true),
|
|
||||||
UNKNOWN_SIMPLE_ATTRIBUTE(MessageSeverity.ERROR, true, true),
|
|
||||||
INVALID_RULE_PARAMETER_REF(MessageSeverity.ERROR, true, true),
|
|
||||||
UNKNOWN_RULE_ATTRIBUTE(MessageSeverity.ERROR, true, true),
|
|
||||||
ISOLATED_RULE_SCOPE(MessageSeverity.ERROR, true, true),
|
|
||||||
SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE(MessageSeverity.ERROR, true, true),
|
|
||||||
LABEL_CONFLICTS_WITH_RULE(MessageSeverity.ERROR, true, true),
|
|
||||||
LABEL_CONFLICTS_WITH_TOKEN(MessageSeverity.ERROR, true, true),
|
|
||||||
LABEL_CONFLICTS_WITH_RULE_SCOPE_ATTRIBUTE(MessageSeverity.ERROR, true, true),
|
|
||||||
LABEL_CONFLICTS_WITH_RULE_ARG_RETVAL(MessageSeverity.ERROR, true, true),
|
|
||||||
ATTRIBUTE_CONFLICTS_WITH_RULE(MessageSeverity.ERROR, true, true),
|
|
||||||
ATTRIBUTE_CONFLICTS_WITH_RULE_ARG_RETVAL(MessageSeverity.ERROR, true, true),
|
|
||||||
LABEL_TYPE_CONFLICT(MessageSeverity.ERROR, true, true),
|
|
||||||
ARG_RETVAL_CONFLICT(MessageSeverity.ERROR, true, true),
|
|
||||||
NONUNIQUE_REF(MessageSeverity.ERROR, true, true),
|
|
||||||
FORWARD_ELEMENT_REF(MessageSeverity.ERROR, true, true),
|
|
||||||
MISSING_RULE_ARGS(MessageSeverity.ERROR, true, true),
|
|
||||||
RULE_HAS_NO_ARGS(MessageSeverity.ERROR, true, true),
|
|
||||||
ARGS_ON_TOKEN_REF(MessageSeverity.ERROR, true, true),
|
|
||||||
RULE_REF_AMBIG_WITH_RULE_IN_ALT(MessageSeverity.ERROR, true, true),
|
|
||||||
ILLEGAL_OPTION(MessageSeverity.ERROR, true, true),
|
|
||||||
LIST_LABEL_INVALID_UNLESS_RETVAL_STRUCT(MessageSeverity.ERROR, true, true),
|
|
||||||
UNDEFINED_TOKEN_REF_IN_REWRITE(MessageSeverity.ERROR, true, true),
|
|
||||||
REWRITE_ELEMENT_NOT_PRESENT_ON_LHS(MessageSeverity.ERROR, true, true),
|
|
||||||
UNDEFINED_LABEL_REF_IN_REWRITE(MessageSeverity.ERROR, true, true),
|
|
||||||
NO_GRAMMAR_START_RULE(MessageSeverity.ERROR, true, true),
|
|
||||||
EMPTY_COMPLEMENT(MessageSeverity.ERROR, true, true),
|
|
||||||
UNKNOWN_DYNAMIC_SCOPE(MessageSeverity.ERROR, true, true),
|
|
||||||
UNKNOWN_DYNAMIC_SCOPE_ATTRIBUTE(MessageSeverity.ERROR, true, true),
|
|
||||||
ISOLATED_RULE_ATTRIBUTE(MessageSeverity.ERROR, true, true),
|
|
||||||
INVALID_ACTION_SCOPE(MessageSeverity.ERROR, true, true),
|
|
||||||
ACTION_REDEFINITION(MessageSeverity.ERROR, true, true),
|
|
||||||
INVALID_TEMPLATE_ACTION(MessageSeverity.ERROR, true, true),
|
|
||||||
ARG_INIT_VALUES_ILLEGAL(MessageSeverity.ERROR, true, true),
|
|
||||||
REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION(MessageSeverity.ERROR, true, true),
|
|
||||||
NO_RULES(MessageSeverity.ERROR, true, true),
|
|
||||||
WRITE_TO_READONLY_ATTR(MessageSeverity.ERROR, true, true),
|
|
||||||
MISSING_AST_TYPE_IN_TREE_GRAMMAR(MessageSeverity.ERROR, true, true),
|
|
||||||
REWRITE_FOR_MULTI_ELEMENT_ALT(MessageSeverity.ERROR, true, true),
|
|
||||||
RULE_INVALID_SET(MessageSeverity.ERROR, true, true),
|
|
||||||
HETERO_ILLEGAL_IN_REWRITE_ALT(MessageSeverity.ERROR, true, true),
|
|
||||||
NO_SUCH_GRAMMAR_SCOPE(MessageSeverity.ERROR, true, true),
|
|
||||||
NO_SUCH_RULE_IN_SCOPE(MessageSeverity.ERROR, true, true),
|
|
||||||
TOKEN_ALIAS_CONFLICT(MessageSeverity.ERROR, true, true),
|
|
||||||
TOKEN_ALIAS_REASSIGNMENT(MessageSeverity.ERROR, true, true),
|
|
||||||
TOKEN_VOCAB_IN_DELEGATE(MessageSeverity.ERROR, true, true),
|
|
||||||
INVALID_IMPORT(MessageSeverity.ERROR, true, true),
|
|
||||||
IMPORTED_TOKENS_RULE_EMPTY(MessageSeverity.ERROR, true, true),
|
|
||||||
IMPORT_NAME_CLASH(MessageSeverity.ERROR, true, true),
|
|
||||||
AST_OP_WITH_NON_AST_OUTPUT_OPTION(MessageSeverity.ERROR, true, true),
|
|
||||||
AST_OP_IN_ALT_WITH_REWRITE(MessageSeverity.ERROR, true, true),
|
|
||||||
WILDCARD_AS_ROOT(MessageSeverity.ERROR, true, true),
|
|
||||||
CONFLICTING_OPTION_IN_TREE_FILTER(MessageSeverity.ERROR, true, true),
|
|
||||||
/** Documentation comment is unterminated */
|
|
||||||
UNTERMINATED_DOC_COMMENT(MessageSeverity.ERROR, true, true),
|
|
||||||
|
|
||||||
// Dependency sorting errors
|
|
||||||
//
|
|
||||||
/** t1.g -> t2.g -> t3.g ->t1.g */
|
|
||||||
CIRCULAR_DEPENDENCY(MessageSeverity.ERROR, true, true),
|
|
||||||
|
|
||||||
// Simple informational messages
|
|
||||||
//
|
|
||||||
/** A standby generic message that jsut spits out the arguments it is given */
|
|
||||||
GENERIC_INFO(MessageSeverity.INFO, false, false),
|
|
||||||
/** How to print out the version of the ANTLR tool that we are */
|
|
||||||
ANTLR_VERSION(MessageSeverity.INFO, false, false),
|
|
||||||
|
|
||||||
// Command line tool errors/warnings
|
|
||||||
/** -fo option was incorrectly formed */
|
|
||||||
MISSING_OUTPUT_FO(MessageSeverity.WARNING, false, false),
|
|
||||||
/** -lib option is missing a directory argument */
|
|
||||||
MISSING_LIBDIR(MessageSeverity.WARNING, false, false),
|
|
||||||
/** -format option was not given the name of a message format */
|
|
||||||
MISSING_FORMAT(MessageSeverity.WARNING, false, false),
|
|
||||||
/** Max state count missing from the option */
|
|
||||||
MISSING_MAXSTATES(MessageSeverity.WARNING, false, false),
|
|
||||||
/** Max labels in a switch argument is missing */
|
|
||||||
MISSING_MAXSWITCH(MessageSeverity.WARNING, false, false),
|
|
||||||
/** Min labels in a switch argument is missing */
|
|
||||||
MISSING_MINSWITCH(MessageSeverity.WARNING, false, false),
|
|
||||||
/** Missing recursion limit argument */
|
|
||||||
MISSING_MAXRECUR(MessageSeverity.WARNING, false, false),
|
|
||||||
/** Missing max edges argument */
|
|
||||||
MISSING_MAXEDGE(MessageSeverity.WARNING, false, false),
|
|
||||||
/** Misng ms timeout argument */
|
|
||||||
MISSING_MAXTIME(MessageSeverity.WARNING, false, false),
|
|
||||||
|
|
||||||
// Help messages
|
|
||||||
HELP_USAGE(MessageSeverity.INFO, false, false),
|
|
||||||
HELP_EXTENDED(MessageSeverity.INFO, false, false),
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local storage for the severity level of the message
|
|
||||||
*/
|
|
||||||
private MessageSeverity severity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the severity level of this message
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public MessageSeverity getSeverity() {
|
|
||||||
return severity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal storage for the flag that indicates whether this particular message
|
|
||||||
* should abort the analysis phase or not.
|
|
||||||
*/
|
|
||||||
private Boolean abortsAnalysis;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether the raising of this error messsage should abort the
|
|
||||||
* analysis phase (or prevent it from starting).
|
|
||||||
*
|
|
||||||
* @return true if this message should abort the analysis phase
|
|
||||||
*/
|
|
||||||
public Boolean abortsAnalysis() {
|
|
||||||
return abortsAnalysis;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether the raising of this error message aborts code
|
|
||||||
* generation or not.
|
|
||||||
*/
|
|
||||||
private Boolean abortsCodegen;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether the raising of this error message aborts code
|
|
||||||
* generation or not.
|
|
||||||
*
|
|
||||||
* @return true if this message should abort code generation
|
|
||||||
*/
|
|
||||||
public Boolean abortsCodegen() {
|
|
||||||
return abortsCodegen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local constructor produces an instance of the entries in this Enum
|
|
||||||
*/
|
|
||||||
private Msg(MessageSeverity severity, boolean abortsAnalysis, boolean abortsCodegen) {
|
|
||||||
this.severity = severity;
|
|
||||||
this.abortsAnalysis = abortsAnalysis;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.antlr.v4.tool;
|
||||||
|
|
||||||
|
/** A generic message from the tool such as "file not found" type errors; there
|
||||||
|
* is no reason to create a special object for each error unlike the grammar
|
||||||
|
* errors, which may be rather complex.
|
||||||
|
*
|
||||||
|
* Sometimes you need to pass in a filename or something to say it is "bad".
|
||||||
|
* Allow a generic object to be passed in and the string template can deal
|
||||||
|
* with just printing it or pulling a property out of it.
|
||||||
|
*/
|
||||||
|
public class ToolMessage extends Message {
|
||||||
|
public ToolMessage(ErrorType errorType) {
|
||||||
|
super(errorType);
|
||||||
|
}
|
||||||
|
public ToolMessage(ErrorType errorType, Object... args) {
|
||||||
|
super(errorType, null, args);
|
||||||
|
}
|
||||||
|
public ToolMessage(ErrorType errorType, Throwable e, Object... args) {
|
||||||
|
super(errorType, e, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +0,0 @@
|
||||||
package org.antlr.v4.test;
|
|
||||||
|
|
||||||
import org.antlr.gunit.gUnitBaseTest;
|
|
||||||
|
|
||||||
public class TestANTLR extends gUnitBaseTest {
|
|
||||||
|
|
||||||
public void setUp() {
|
|
||||||
this.packagePath = "./org/antlr/v4/test";
|
|
||||||
this.lexerPath = "org.antlr.v4.test.ANTLRLexer";
|
|
||||||
this.parserPath = "org.antlr.v4.test.ANTLRParser";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue