From 09ad4bcb0a2f0e66a402ecbc2c23b293ab97f727 Mon Sep 17 00:00:00 2001 From: sharwell Date: Tue, 22 Nov 2011 15:32:53 -0800 Subject: [PATCH] v4: Remove dependency on v3 tool (still depends on v3 runtime) [git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9431] --- .../org/antlr/v4/parse/LeftRecursiveRuleAnalyzer.java | 2 +- tool/src/org/antlr/v4/parse/ScopeParser.java | 11 +++++------ tool/src/org/antlr/v4/parse/TokenVocabParser.java | 11 +++++------ tool/src/org/antlr/v4/semantics/SymbolCollector.java | 6 +++--- tool/test/org/antlr/v4/test/TestScopeParsing.java | 3 ++- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/tool/src/org/antlr/v4/parse/LeftRecursiveRuleAnalyzer.java b/tool/src/org/antlr/v4/parse/LeftRecursiveRuleAnalyzer.java index 66eef156d..f2db87347 100644 --- a/tool/src/org/antlr/v4/parse/LeftRecursiveRuleAnalyzer.java +++ b/tool/src/org/antlr/v4/parse/LeftRecursiveRuleAnalyzer.java @@ -351,7 +351,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { if ( retvals==null ) return; // complicated since we must be target-independent - AttributeDict args = ScopeParser.parseTypedArgList(retvals.token.getText()); + AttributeDict args = ScopeParser.parseTypedArgList(retvals.token.getText(), tool.errMgr); for (String name : args.attributes.keySet()) { ST setRetValST = diff --git a/tool/src/org/antlr/v4/parse/ScopeParser.java b/tool/src/org/antlr/v4/parse/ScopeParser.java index d4cfcd276..01edf05ce 100644 --- a/tool/src/org/antlr/v4/parse/ScopeParser.java +++ b/tool/src/org/antlr/v4/parse/ScopeParser.java @@ -29,7 +29,6 @@ package org.antlr.v4.parse; -import org.antlr.tool.ErrorManager; import org.antlr.v4.tool.*; import java.util.*; @@ -56,9 +55,9 @@ public class ScopeParser { * * convert to an attribute scope. */ - public static AttributeDict parseTypedArgList(String s) { return parse(s, ','); } + public static AttributeDict parseTypedArgList(String s, ErrorManager errMgr) { return parse(s, ',', errMgr); } - public static AttributeDict parse(String s, char separator) { + public static AttributeDict parse(String s, char separator, ErrorManager errMgr) { int i = 0; int n = s.length(); AttributeDict dict = new AttributeDict(); @@ -81,7 +80,7 @@ public class ScopeParser { String def = buf.toString(); //System.out.println("def="+ def); if ( def.trim().length()>0 ) { - Attribute a = parseAttributeDef(def); + Attribute a = parseAttributeDef(def, errMgr); dict.add(a); } } @@ -93,7 +92,7 @@ public class ScopeParser { * but if the separator is ',' you cannot use ',' in the initvalue * unless you escape use "\," escape. */ - public static Attribute parseAttributeDef(String decl) { + public static Attribute parseAttributeDef(String decl, ErrorManager errMgr) { if ( decl==null ) return null; Attribute attr = new Attribute(); boolean inID = false; @@ -122,7 +121,7 @@ public class ScopeParser { start = 0; } if ( start<0 ) { - ErrorManager.error(ErrorManager.MSG_CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL,decl); + errMgr.toolError(ErrorType.CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL,decl); } // walk forwards looking for end of an ID int stop=-1; diff --git a/tool/src/org/antlr/v4/parse/TokenVocabParser.java b/tool/src/org/antlr/v4/parse/TokenVocabParser.java index e8f21e8db..65480784e 100644 --- a/tool/src/org/antlr/v4/parse/TokenVocabParser.java +++ b/tool/src/org/antlr/v4/parse/TokenVocabParser.java @@ -29,14 +29,13 @@ package org.antlr.v4.parse; -import org.antlr.codegen.CodeGenerator; -import org.antlr.misc.Utils; import org.antlr.v4.Tool; import org.antlr.v4.tool.ErrorType; import java.io.*; import java.util.LinkedHashMap; import java.util.Map; +import org.antlr.v4.codegen.CodeGenerator; /** */ public class TokenVocabParser { @@ -79,7 +78,7 @@ public class TokenVocabParser { else { tool.errMgr.toolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR, vocabName + CodeGenerator.VOCAB_FILE_EXTENSION, - Utils.integer(lineNum)); + lineNum); while ( tokenizer.nextToken() != StreamTokenizer.TT_EOL ) {;} token = tokenizer.nextToken(); continue; @@ -88,7 +87,7 @@ public class TokenVocabParser { if ( token != '=' ) { tool.errMgr.toolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR, vocabName+CodeGenerator.VOCAB_FILE_EXTENSION, - Utils.integer(lineNum)); + lineNum); while ( tokenizer.nextToken() != StreamTokenizer.TT_EOL ) {;} token = tokenizer.nextToken(); continue; @@ -97,7 +96,7 @@ public class TokenVocabParser { if ( token != StreamTokenizer.TT_NUMBER ) { tool.errMgr.toolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR, vocabName+CodeGenerator.VOCAB_FILE_EXTENSION, - Utils.integer(lineNum)); + lineNum); while ( tokenizer.nextToken() != StreamTokenizer.TT_EOL ) {;} token = tokenizer.nextToken(); continue; @@ -111,7 +110,7 @@ public class TokenVocabParser { if ( token != StreamTokenizer.TT_EOL ) { tool.errMgr.toolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR, vocabName+CodeGenerator.VOCAB_FILE_EXTENSION, - Utils.integer(lineNum)); + lineNum); while ( tokenizer.nextToken() != StreamTokenizer.TT_EOL ) {;} token = tokenizer.nextToken(); continue; diff --git a/tool/src/org/antlr/v4/semantics/SymbolCollector.java b/tool/src/org/antlr/v4/semantics/SymbolCollector.java index 876fc985e..cb61e5be2 100644 --- a/tool/src/org/antlr/v4/semantics/SymbolCollector.java +++ b/tool/src/org/antlr/v4/semantics/SymbolCollector.java @@ -112,20 +112,20 @@ public class SymbolCollector extends GrammarTreeVisitor { currentRule = r; if ( arg!=null ) { - r.args = ScopeParser.parseTypedArgList(arg.getText()); + r.args = ScopeParser.parseTypedArgList(arg.getText(), g.tool.errMgr); r.args.type = AttributeDict.DictType.ARG; r.args.ast = arg; arg.resolver = r.alt[currentOuterAltNumber]; } if ( returns!=null ) { - r.retvals = ScopeParser.parseTypedArgList(returns.getText()); + r.retvals = ScopeParser.parseTypedArgList(returns.getText(), g.tool.errMgr); r.retvals.type = AttributeDict.DictType.RET; r.retvals.ast = returns; } if ( locals!=null ) { - r.locals = ScopeParser.parseTypedArgList(locals.getText()); + r.locals = ScopeParser.parseTypedArgList(locals.getText(), g.tool.errMgr); r.locals.type = AttributeDict.DictType.LOCAL; r.locals.ast = returns; } diff --git a/tool/test/org/antlr/v4/test/TestScopeParsing.java b/tool/test/org/antlr/v4/test/TestScopeParsing.java index 8c93bd378..4dbbdcec9 100644 --- a/tool/test/org/antlr/v4/test/TestScopeParsing.java +++ b/tool/test/org/antlr/v4/test/TestScopeParsing.java @@ -1,6 +1,7 @@ package org.antlr.v4.test; import org.antlr.v4.parse.ScopeParser; +import org.antlr.v4.tool.ErrorManager; import org.junit.Test; public class TestScopeParsing extends BaseTest { @@ -24,7 +25,7 @@ public class TestScopeParsing extends BaseTest { for (int i = 0; i < argPairs.length; i+=2) { String input = argPairs[i]; String expected = argPairs[i+1]; - String actual = ScopeParser.parseTypedArgList(input).attributes.toString(); + String actual = ScopeParser.parseTypedArgList(input, new ErrorManager(null)).attributes.toString(); assertEquals(expected, actual); } }