forked from jasder/antlr
got -no prefix options working. rm'd dup error from toolError(); rm dbg print
This commit is contained in:
parent
100b530201
commit
d00ec9d227
|
@ -8,11 +8,5 @@ e : e '*' e -> Mult
|
|||
| '(' e ')' -> Parens
|
||||
;
|
||||
|
||||
x : A -> Foo
|
||||
| B
|
||||
;
|
||||
|
||||
y : Y -> Mult ;
|
||||
|
||||
INT : [0-9]+ ;
|
||||
WS : [ \t\n]+ -> skip ;
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import org.antlr.v4.runtime.tree.*;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public interface AVisitor<T> {
|
||||
T visit(AParser.MultContext ctx);
|
||||
T visit(AParser.ParensContext ctx);
|
||||
T visit(AParser.sContext ctx);
|
||||
T visit(AParser.FooContext ctx);
|
||||
T visit(AParser.AddContext ctx);
|
||||
T visit(AParser.IntContext ctx);
|
||||
}
|
|
@ -186,8 +186,10 @@ public class Tool {
|
|||
grammarFiles.add(arg);
|
||||
continue;
|
||||
}
|
||||
boolean found = false;
|
||||
for (Option o : optionDefs) {
|
||||
if ( arg.equals(o.name) ) {
|
||||
found = true;
|
||||
String argValue = null;
|
||||
if ( o.argType==OptionArgType.STRING ) {
|
||||
argValue = args[i];
|
||||
|
@ -198,7 +200,7 @@ public class Tool {
|
|||
try {
|
||||
Field f = c.getField(o.fieldName);
|
||||
if ( argValue==null ) {
|
||||
if ( o.fieldName.startsWith("-no-") ) f.setBoolean(this, false);
|
||||
if ( arg.startsWith("-no-") ) f.setBoolean(this, false);
|
||||
else f.setBoolean(this, true);
|
||||
}
|
||||
else f.set(this, argValue);
|
||||
|
@ -208,6 +210,9 @@ public class Tool {
|
|||
}
|
||||
}
|
||||
}
|
||||
if ( !found ) {
|
||||
errMgr.toolError(ErrorType.INVALID_CMDLINE_ARG, arg);
|
||||
}
|
||||
}
|
||||
if ( outputDirectory!=null ) {
|
||||
if (outputDirectory.endsWith("/") ||
|
||||
|
|
|
@ -46,9 +46,11 @@ public class CodeGenPipeline {
|
|||
}
|
||||
else {
|
||||
gen.writeRecognizer(gen.generateParser());
|
||||
if ( g.tool.gen_listener) {
|
||||
if ( g.tool.gen_listener ) {
|
||||
gen.writeListener(gen.generateListener());
|
||||
gen.writeBaseListener(gen.generateBaseListener());
|
||||
}
|
||||
if ( g.tool.gen_visitor ) {
|
||||
gen.writeVisitor(gen.generateVisitor());
|
||||
gen.writeBaseVisitor(gen.generateBaseVisitor());
|
||||
}
|
||||
|
|
|
@ -250,7 +250,6 @@ public class BasicSemanticChecks extends GrammarTreeVisitor {
|
|||
for (int i=0; i< nalts; i++) {
|
||||
AltAST altAST = (AltAST)blk.getChild(i);
|
||||
if ( altAST.altLabel!=null ) {
|
||||
System.out.println("alt label "+altAST.altLabel);
|
||||
ruleToAltLabels.map(rule.getRuleName(), altAST.altLabel);
|
||||
String altLabel = altAST.altLabel.getText();
|
||||
String prevRuleForLabel = altLabelToRuleName.get(altLabel);
|
||||
|
@ -266,11 +265,9 @@ public class BasicSemanticChecks extends GrammarTreeVisitor {
|
|||
}
|
||||
}
|
||||
}
|
||||
System.out.println(rule.getRuleName()+" has "+ nalts +" alts");
|
||||
List<GrammarAST> altLabels = ruleToAltLabels.get(rule.getRuleName());
|
||||
int numAltLabels = 0;
|
||||
if ( altLabels!=null ) numAltLabels = altLabels.size();
|
||||
System.out.println("labels="+altLabels);
|
||||
if ( numAltLabels>0 && nalts != numAltLabels ) {
|
||||
g.tool.errMgr.grammarError(ErrorType.RULE_WITH_TOO_FEW_ALT_LABELS,
|
||||
g.fileName, rule.getToken(), rule.getRuleName());
|
||||
|
|
|
@ -30,11 +30,16 @@
|
|||
package org.antlr.v4.tool;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.stringtemplate.v4.*;
|
||||
import org.stringtemplate.v4.misc.*;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STErrorListener;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STGroupFile;
|
||||
import org.stringtemplate.v4.misc.ErrorBuffer;
|
||||
import org.stringtemplate.v4.misc.STMessage;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ErrorManager {
|
||||
public static final String FORMATS_DIR = "org/antlr/v4/tool/templates/messages/formats/";
|
||||
|
@ -190,7 +195,6 @@ public class ErrorManager {
|
|||
public void toolError(ErrorType errorType, Object... args) {
|
||||
ToolMessage msg = new ToolMessage(errorType, args);
|
||||
emit(errorType, msg);
|
||||
tool.error(msg);
|
||||
}
|
||||
|
||||
public void toolError(ErrorType errorType, Throwable e, Object... args) {
|
||||
|
|
|
@ -43,8 +43,9 @@ package org.antlr.v4.tool;
|
|||
public enum ErrorType {
|
||||
INVALID(0, "<INVALID>", ErrorSeverity.ERROR),
|
||||
|
||||
// Tool errors
|
||||
CANNOT_WRITE_FILE(1, "cannot write file <arg>: <arg2>", ErrorSeverity.ERROR),
|
||||
// CANNOT_CLOSE_FILE(2, "cannot close file <arg>", ErrorSeverity.ERROR),
|
||||
INVALID_CMDLINE_ARG(2, "unknown command-line option <arg>", ErrorSeverity.ERROR),
|
||||
CANNOT_FIND_TOKENS_FILE(3, "cannot find tokens file <arg>", ErrorSeverity.ERROR),
|
||||
ERROR_READING_TOKENS_FILE(4, "cannot find tokens file <arg>: <arg2>", ErrorSeverity.ERROR),
|
||||
DIR_NOT_FOUND(5, "directory not found: <arg>", ErrorSeverity.ERROR),
|
||||
|
|
Loading…
Reference in New Issue