more tests, fixes ANTLR-189. recursion works; rewinds properly.
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6833]
This commit is contained in:
parent
16ad680adb
commit
61603d18a9
|
@ -177,7 +177,7 @@ workLoop:
|
|||
boolean accepted = false;
|
||||
processOneChar:
|
||||
while ( i<closure.size() ) {
|
||||
//System.out.println("input["+input.index()+"]=="+(char)c+" closure="+closure+", i="+i+", reach="+ reach);
|
||||
System.out.println("input["+input.index()+"]=="+(char)c+" closure="+closure+", i="+i+", reach="+ reach);
|
||||
ThreadState t = closure.get(i);
|
||||
ip = t.addr;
|
||||
NFAStack context = t.context;
|
||||
|
@ -260,7 +260,7 @@ processOneChar:
|
|||
input.consume();
|
||||
}
|
||||
else if ( !accepted) {
|
||||
System.err.println("no match for char "+(char)c+" at "+input.index());
|
||||
System.out.println("!!!!! no match for char "+(char)c+" at "+input.index());
|
||||
input.consume();
|
||||
}
|
||||
// else reach.size==0 && matched, don't consume: accepted and
|
||||
|
|
|
@ -95,6 +95,29 @@ public class TestNFABytecodeInterp extends BaseTest {
|
|||
checkMatches(g, "aaxa", expecting);
|
||||
}
|
||||
|
||||
@Test public void testRewindBackToLastGoodMatch() throws Exception {
|
||||
LexerGrammar g = new LexerGrammar(
|
||||
"lexer grammar L;\n" +
|
||||
"A : 'a' 'b'? ;\n"+
|
||||
"B : 'b' ;\n"+
|
||||
"WS : ' ' ;\n");
|
||||
String expecting = "A, WS, A, WS, B, EOF";
|
||||
checkMatches(g, "a ab b", expecting);
|
||||
}
|
||||
|
||||
// fixes http://www.antlr.org/jira/browse/ANTLR-189 from v3
|
||||
@Test public void testRewindBackToLastGoodMatch_DOT_vs_NUM() throws Exception {
|
||||
LexerGrammar g = new LexerGrammar(
|
||||
"lexer grammar L;\n" +
|
||||
"NUM: '0'..'9'+ ('.' '0'..'9'+)? ;\n"+
|
||||
"DOT : '.' ;\n"+
|
||||
"WS : ' ' ;\n");
|
||||
checkMatches(g, "3.14 .", "NUM, WS, DOT, EOF");
|
||||
checkMatches(g, "9", "NUM, EOF");
|
||||
checkMatches(g, ".1", "DOT, NUM, EOF");
|
||||
checkMatches(g, "1.", "NUM, DOT, EOF");
|
||||
}
|
||||
|
||||
public void _template() throws Exception {
|
||||
LexerGrammar g = new LexerGrammar(
|
||||
"\n");
|
||||
|
|
Loading…
Reference in New Issue