figured out unit test issues; sem pipeline bailed out too early and also setting errorlistener didn't reset error count

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6813]
This commit is contained in:
parrt 2010-04-11 11:26:32 -08:00
parent 2faaf7bc7f
commit c29f0e1d7c
5 changed files with 33 additions and 20 deletions

View File

@ -65,7 +65,8 @@ public class SemanticPipeline {
symcheck.examine(); // side-effect: strip away redef'd rules.
// don't continue if we get symbol errors
if ( ErrorManager.getNumErrors()>0 ) return;
//if ( ErrorManager.getNumErrors()>0 ) return;
// hmm...we don't get missing arg errors and such if we bail out here
// STORE RULES/ACTIONS/SCOPES IN GRAMMAR
for (Rule r : collector.rules) g.defineRule(r);
@ -76,7 +77,7 @@ public class SemanticPipeline {
symcheck.checkRuleArgs(g, collector.rulerefs);
symcheck.checkForQualifiedRuleIssues(g, collector.qualifiedRulerefs);
// don't continue if we get symbol errors
// don't continue if we got symbol errors
if ( ErrorManager.getNumErrors()>0 ) return;
// CHECK ATTRIBUTE EXPRESSIONS FOR SEMANTIC VALIDITY

View File

@ -385,6 +385,7 @@ public class ErrorManager {
* thread.
*/
public static void setErrorListener(ANTLRErrorListener l) {
resetErrorState();
state.get().listener = l;
}

View File

@ -203,6 +203,7 @@ public class Grammar implements AttributeResolver {
}
public void defineRule(Rule r) {
if ( rules.get(r.name)!=null ) return;
rules.put(r.name, r);
r.index = ruleNumber++;
}

View File

@ -61,9 +61,9 @@ public class TestNFAConstruction extends BaseTest {
"A : 'a'..'c' ;"
);
String expecting =
"RuleStart_A_0->s2\n" +
"s2-'a'..'c'->s3\n" +
"s3->RuleStop_A_1\n";
"RuleStart_A_1->s3\n" +
"s3-'a'..'c'->s4\n" +
"s4->RuleStop_A_2\n";
checkRule(g, "A", expecting);
}
@ -73,28 +73,36 @@ public class TestNFAConstruction extends BaseTest {
"A : ('a'..'c' 'h' | 'q' 'j'..'l') ;"
);
String expecting =
"RuleStart_A_0->BlockStart_10\n" +
"BlockStart_10->s2\n" +
"BlockStart_10->s6\n" +
"s2-'a'..'c'->s3\n" +
"s6-'q'->s7\n" +
"s3->s4\n" +
"s7->s8\n" +
"s4-'h'->s5\n" +
"s8-'j'..'l'->s9\n" +
"s5->BlockEnd_11\n" +
"s9->BlockEnd_11\n" +
"BlockEnd_11->RuleStop_A_1\n";
"RuleStart_A_1->BlockStart_11\n" +
"BlockStart_11->s3\n" +
"BlockStart_11->s7\n" +
"s3-'a'..'c'->s4\n" +
"s7-'q'->s8\n" +
"s4->s5\n" +
"s8->s9\n" +
"s5-'h'->s6\n" +
"s9-'j'..'l'->s10\n" +
"s6->BlockEnd_12\n" +
"s10->BlockEnd_12\n" +
"BlockEnd_12->RuleStop_A_2\n";
checkRule(g, "A", expecting);
}
@Test public void testCharSetInParser() throws Exception {
@Test public void testStringLiteralInParser() throws Exception {
Grammar g = new Grammar(
"grammar P;\n"+
"a : A|'b' ;"
);
String expecting =
"\n";
"RuleStart_a_0->BlockStart_6\n" +
"BlockStart_6->s2\n" +
"BlockStart_6->s4\n" +
"s2-A->s3\n" +
"s4-'b'->s5\n" +
"s3->BlockEnd_7\n" +
"s5->BlockEnd_7\n" +
"BlockEnd_7->RuleStop_a_1\n" +
"RuleStop_a_1-EOF->s8\n";
checkRule(g, "a", expecting);
}

View File

@ -32,7 +32,9 @@ public class TestSymbolIssues extends BaseTest {
"error(72): A.g:3:19: cannot alias X; token name already defined\n" +
"error(72): A.g:3:26: cannot alias Y; token name already assigned to 'y'\n" +
"error(72): A.g:3:36: cannot alias Z; token name already defined\n" +
"error(23): A.g:13:43: reference to undefined rule: q"
"error(46): A.g:13:37: rule b has no defined parameters\n" +
"error(23): A.g:13:43: reference to undefined rule: q\n" +
"error(45): A.g:14:31: missing parameter(s) on rule reference: a"
};
static String[] B = {