v4: Remove dependency on v3 tool (still depends on v3 runtime)
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9431]
This commit is contained in:
parent
cfecf4b109
commit
09ad4bcb0a
|
@ -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 =
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue