fixed for new atn serialization

This commit is contained in:
Terence Parr 2012-09-04 20:04:50 -07:00
parent 5c70d5072a
commit 7c955e3cae
1 changed files with 203 additions and 212 deletions

View File

@ -43,18 +43,17 @@ public class TestATNSerialization extends BaseTest {
"a : A B ;");
String expecting =
"max type 2\n" +
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:BASIC 0\n" +
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"6:BASIC 0\n" +
"rule 0:0\n" +
"0->2 EPSILON 0,0,0\n" +
"1->6 ATOM -1,0,0\n" +
"2->4 ATOM 1,0,0\n" +
"4->5 ATOM 2,0,0\n" +
"5->1 EPSILON 0,0,0\n";
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:BASIC 0\n" +
"3:BASIC 0\n" +
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"rule 0:0\n" +
"0->2 EPSILON 0,0,0\n" +
"2->3 ATOM 1,0,0\n" +
"3->4 ATOM 2,0,0\n" +
"4->1 EPSILON 0,0,0\n";
ATN atn = createATN(g);
String result = ATNSerializer.getDecoded(g, atn);
assertEquals(expecting, result);
@ -66,18 +65,17 @@ public class TestATNSerialization extends BaseTest {
"a : A EOF ;");
String expecting =
"max type 1\n" +
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:BASIC 0\n" +
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"6:BASIC 0\n" +
"rule 0:0\n" +
"0->2 EPSILON 0,0,0\n" +
"1->6 ATOM -1,0,0\n" +
"2->4 ATOM 1,0,0\n" +
"4->5 ATOM -1,0,0\n" +
"5->1 EPSILON 0,0,0\n";
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:BASIC 0\n" +
"3:BASIC 0\n" +
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"rule 0:0\n" +
"0->2 EPSILON 0,0,0\n" +
"2->3 ATOM 1,0,0\n" +
"3->4 ATOM -1,0,0\n" +
"4->1 EPSILON 0,0,0\n";
ATN atn = createATN(g);
String result = ATNSerializer.getDecoded(g, atn);
assertEquals(expecting, result);
@ -89,17 +87,16 @@ public class TestATNSerialization extends BaseTest {
"a : (A|EOF) ;");
String expecting =
"max type 1\n" +
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:BASIC 0\n" +
"3:BASIC 0\n" +
"4:BASIC 0\n" +
"rule 0:0\n" +
"0:EOF..EOF, A..A\n" +
"0->2 EPSILON 0,0,0\n" +
"1->4 ATOM -1,0,0\n" +
"2->3 SET 0,0,0\n" +
"3->1 EPSILON 0,0,0\n";
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:BASIC 0\n" +
"3:BASIC 0\n" +
"4:BASIC 0\n" +
"rule 0:0\n" +
"0:EOF..EOF, A..A\n" +
"0->2 EPSILON 0,0,0\n" +
"2->3 SET 0,0,0\n" +
"3->1 EPSILON 0,0,0\n";
ATN atn = createATN(g);
String result = ATNSerializer.getDecoded(g, atn);
assertEquals(expecting, result);
@ -120,7 +117,6 @@ public class TestATNSerialization extends BaseTest {
"rule 0:0\n" +
"0:A..A\n" +
"0->2 EPSILON 0,0,0\n" +
"1->4 ATOM -1,0,0\n" +
"2->3 NOT_SET 0,0,0\n" +
"3->1 EPSILON 0,0,0\n";
ATN atn = createATN(g);
@ -144,7 +140,6 @@ public class TestATNSerialization extends BaseTest {
"4:BASIC 0\n" +
"rule 0:0\n" +
"0->2 EPSILON 0,0,0\n" +
"1->4 ATOM -1,0,0\n" +
"2->3 WILDCARD 0,0,0\n" +
"3->1 EPSILON 0,0,0\n";
ATN atn = createATN(g);
@ -168,7 +163,6 @@ public class TestATNSerialization extends BaseTest {
"10:BASIC 0\n" +
"rule 0:0\n" +
"0->8 EPSILON 0,0,0\n" +
"1->10 ATOM -1,0,0\n" +
"2->9 ATOM 1,0,0\n" +
"4->6 ATOM 1,0,0\n" +
"6->9 ATOM 2,0,0\n" +
@ -223,28 +217,27 @@ public class TestATNSerialization extends BaseTest {
"a : A+ B ;");
String expecting =
"max type 2\n" +
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:BASIC 0\n" +
"4:PLUS_BLOCK_START 0\n" +
"5:BLOCK_END 0\n" +
"6:PLUS_LOOP_BACK 0\n" +
"7:LOOP_END 0 6\n" +
"8:BASIC 0\n" +
"9:BASIC 0\n" +
"10:BASIC 0\n" +
"rule 0:0\n" +
"0->4 EPSILON 0,0,0\n" +
"1->10 ATOM -1,0,0\n" +
"2->5 ATOM 1,0,0\n" +
"4->2 EPSILON 0,0,0\n" +
"5->6 EPSILON 0,0,0\n" +
"6->4 EPSILON 0,0,0\n" +
"6->7 EPSILON 0,0,0\n" +
"7->8 EPSILON 0,0,0\n" +
"8->9 ATOM 2,0,0\n" +
"9->1 EPSILON 0,0,0\n" +
"0:6 1\n";
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:BASIC 0\n" +
"3:PLUS_BLOCK_START 0 4\n" +
"4:BLOCK_END 0\n" +
"5:PLUS_LOOP_BACK 0\n" +
"6:LOOP_END 0 5\n" +
"7:BASIC 0\n" +
"8:BASIC 0\n" +
"9:BASIC 0\n" +
"rule 0:0\n" +
"0->3 EPSILON 0,0,0\n" +
"2->4 ATOM 1,0,0\n" +
"3->2 EPSILON 0,0,0\n" +
"4->5 EPSILON 0,0,0\n" +
"5->3 EPSILON 0,0,0\n" +
"5->6 EPSILON 0,0,0\n" +
"6->7 EPSILON 0,0,0\n" +
"7->8 ATOM 2,0,0\n" +
"8->1 EPSILON 0,0,0\n" +
"0:5 1\n";
ATN atn = createATN(g);
String result = ATNSerializer.getDecoded(g, atn);
assertEquals(expecting, result);
@ -257,25 +250,23 @@ public class TestATNSerialization extends BaseTest {
"e : E ;\n");
String expecting =
"max type 1\n" +
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:RULE_START 1\n" +
"3:RULE_STOP 1\n" +
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"6:BASIC 1\n" +
"7:BASIC 1\n" +
"8:BASIC 1\n" +
"rule 0:0\n" +
"rule 1:2\n" +
"0->4 EPSILON 0,0,0\n" +
"1->8 ATOM -1,0,0\n" +
"2->6 EPSILON 0,0,0\n" +
"3->5 EPSILON 0,0,0\n" +
"4->5 RULE 2,1,0\n" +
"5->1 EPSILON 0,0,0\n" +
"6->7 ATOM 1,0,0\n" +
"7->3 EPSILON 0,0,0\n";
"0:RULE_START 0\n" +
"1:RULE_STOP 0\n" +
"2:RULE_START 1\n" +
"3:RULE_STOP 1\n" +
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"6:BASIC 1\n" +
"7:BASIC 1\n" +
"8:BASIC 1\n" +
"rule 0:0\n" +
"rule 1:2\n" +
"0->4 EPSILON 0,0,0\n" +
"2->6 EPSILON 0,0,0\n" +
"4->5 RULE 2,1,0\n" +
"5->1 EPSILON 0,0,0\n" +
"6->7 ATOM 1,0,0\n" +
"7->3 EPSILON 0,0,0\n";
ATN atn = createATN(g);
String result = ATNSerializer.getDecoded(g, atn);
assertEquals(expecting, result);
@ -343,20 +334,20 @@ public class TestATNSerialization extends BaseTest {
"INT : 'a' EOF ;\n");
String expecting =
"max type 1\n" +
"0:TOKEN_START -1\n" +
"1:RULE_START 0\n" +
"2:RULE_STOP 0\n" +
"3:BASIC 0\n" +
"5:BASIC 0\n" +
"6:BASIC 0\n" +
"rule 0:1 1,-1\n" +
"mode 0:0\n" +
"0->1 EPSILON 0,0,0\n" +
"1->3 EPSILON 0,0,0\n" +
"3->5 ATOM 97,0,0\n" +
"5->6 ATOM -1,0,0\n" +
"6->2 EPSILON 0,0,0\n" +
"0:0 1\n";
"0:TOKEN_START -1\n" +
"1:RULE_START 0\n" +
"2:RULE_STOP 0\n" +
"3:BASIC 0\n" +
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"rule 0:1 1,-1\n" +
"mode 0:0\n" +
"0->1 EPSILON 0,0,0\n" +
"1->3 EPSILON 0,0,0\n" +
"3->4 ATOM 97,0,0\n" +
"4->5 ATOM -1,0,0\n" +
"5->2 EPSILON 0,0,0\n" +
"0:0 1\n";
ATN atn = createATN(lg);
String result = ATNSerializer.getDecoded(lg, atn);
assertEquals(expecting, result);
@ -399,26 +390,26 @@ public class TestATNSerialization extends BaseTest {
"INT : '0'..'9'+ ;\n");
String expecting =
"max type 1\n" +
"0:TOKEN_START -1\n" +
"1:RULE_START 0\n" +
"2:RULE_STOP 0\n" +
"3:BASIC 0\n" +
"5:PLUS_BLOCK_START 0\n" +
"6:BLOCK_END 0\n" +
"7:PLUS_LOOP_BACK 0\n" +
"8:LOOP_END 0 7\n" +
"rule 0:1 1,-1\n" +
"mode 0:0\n" +
"0->1 EPSILON 0,0,0\n" +
"1->5 EPSILON 0,0,0\n" +
"3->6 RANGE 48,57,0\n" +
"5->3 EPSILON 0,0,0\n" +
"6->7 EPSILON 0,0,0\n" +
"7->5 EPSILON 0,0,0\n" +
"7->8 EPSILON 0,0,0\n" +
"8->2 EPSILON 0,0,0\n" +
"0:0 1\n" +
"1:7 1\n";
"0:TOKEN_START -1\n" +
"1:RULE_START 0\n" +
"2:RULE_STOP 0\n" +
"3:BASIC 0\n" +
"4:PLUS_BLOCK_START 0 5\n" +
"5:BLOCK_END 0\n" +
"6:PLUS_LOOP_BACK 0\n" +
"7:LOOP_END 0 6\n" +
"rule 0:1 1,-1\n" +
"mode 0:0\n" +
"0->1 EPSILON 0,0,0\n" +
"1->4 EPSILON 0,0,0\n" +
"3->5 RANGE 48,57,0\n" +
"4->3 EPSILON 0,0,0\n" +
"5->6 EPSILON 0,0,0\n" +
"6->4 EPSILON 0,0,0\n" +
"6->7 EPSILON 0,0,0\n" +
"7->2 EPSILON 0,0,0\n" +
"0:0 1\n" +
"1:6 1\n";
ATN atn = createATN(lg);
String result = ATNSerializer.getDecoded(lg, atn);
assertEquals(expecting, result);
@ -432,40 +423,40 @@ public class TestATNSerialization extends BaseTest {
"C : 'c' {c} ;\n");
String expecting =
"max type 3\n" +
"0:TOKEN_START -1\n" +
"1:RULE_START 0\n" +
"2:RULE_STOP 0\n" +
"3:RULE_START 1\n" +
"4:RULE_STOP 1\n" +
"5:RULE_START 2\n" +
"6:RULE_STOP 2\n" +
"7:BASIC 0\n" +
"9:BASIC 0\n" +
"10:BASIC 0\n" +
"11:BASIC 1\n" +
"12:BASIC 1\n" +
"13:BASIC 2\n" +
"15:BASIC 2\n" +
"16:BASIC 2\n" +
"rule 0:1 1,0\n" +
"rule 1:3 2,-1\n" +
"rule 2:5 3,1\n" +
"mode 0:0\n" +
"0->1 EPSILON 0,0,0\n" +
"0->3 EPSILON 0,0,0\n" +
"0->5 EPSILON 0,0,0\n" +
"1->7 EPSILON 0,0,0\n" +
"3->11 EPSILON 0,0,0\n" +
"5->13 EPSILON 0,0,0\n" +
"7->9 ATOM 97,0,0\n" +
"9->10 ACTION 0,0,0\n" +
"10->2 EPSILON 0,0,0\n" +
"11->12 ATOM 98,0,0\n" +
"12->4 EPSILON 0,0,0\n" +
"13->15 ATOM 99,0,0\n" +
"15->16 ACTION 2,1,0\n" +
"16->6 EPSILON 0,0,0\n" +
"0:0 1\n";
"0:TOKEN_START -1\n" +
"1:RULE_START 0\n" +
"2:RULE_STOP 0\n" +
"3:RULE_START 1\n" +
"4:RULE_STOP 1\n" +
"5:RULE_START 2\n" +
"6:RULE_STOP 2\n" +
"7:BASIC 0\n" +
"8:BASIC 0\n" +
"9:BASIC 0\n" +
"10:BASIC 1\n" +
"11:BASIC 1\n" +
"12:BASIC 2\n" +
"13:BASIC 2\n" +
"14:BASIC 2\n" +
"rule 0:1 1,0\n" +
"rule 1:3 2,-1\n" +
"rule 2:5 3,1\n" +
"mode 0:0\n" +
"0->1 EPSILON 0,0,0\n" +
"0->3 EPSILON 0,0,0\n" +
"0->5 EPSILON 0,0,0\n" +
"1->7 EPSILON 0,0,0\n" +
"3->10 EPSILON 0,0,0\n" +
"5->12 EPSILON 0,0,0\n" +
"7->8 ATOM 97,0,0\n" +
"8->9 ACTION 0,0,0\n" +
"9->2 EPSILON 0,0,0\n" +
"10->11 ATOM 98,0,0\n" +
"11->4 EPSILON 0,0,0\n" +
"12->13 ATOM 99,0,0\n" +
"13->14 ACTION 2,1,0\n" +
"14->6 EPSILON 0,0,0\n" +
"0:0 1\n";
ATN atn = createATN(lg);
String result = ATNSerializer.getDecoded(lg, atn);
assertEquals(expecting, result);
@ -552,55 +543,55 @@ public class TestATNSerialization extends BaseTest {
"JUNK : . {more();} ;\n");
String expecting =
"max type 3\n" +
"0:TOKEN_START -1\n" +
"1:TOKEN_START -1\n" +
"2:RULE_START 0\n" +
"3:RULE_STOP 0\n" +
"4:RULE_START 1\n" +
"5:RULE_STOP 1\n" +
"6:RULE_START 2\n" +
"7:RULE_STOP 2\n" +
"8:BASIC 0\n" +
"10:PLUS_BLOCK_START 0\n" +
"11:BLOCK_END 0\n" +
"12:PLUS_LOOP_BACK 0\n" +
"13:LOOP_END 0 12\n" +
"14:BASIC 1\n" +
"15:BASIC 1\n" +
"16:BASIC 1\n" +
"17:BASIC 1\n" +
"18:BASIC 1\n" +
"19:BASIC 2\n" +
"21:BASIC 2\n" +
"22:BASIC 2\n" +
"rule 0:2 1,-1\n" +
"rule 1:4 2,0\n" +
"rule 2:6 3,1\n" +
"mode 0:0\n" +
"mode 1:1\n" +
"0->2 EPSILON 0,0,0\n" +
"1->4 EPSILON 0,0,0\n" +
"1->6 EPSILON 0,0,0\n" +
"2->10 EPSILON 0,0,0\n" +
"4->14 EPSILON 0,0,0\n" +
"6->19 EPSILON 0,0,0\n" +
"8->11 RANGE 97,122,0\n" +
"10->8 EPSILON 0,0,0\n" +
"11->12 EPSILON 0,0,0\n" +
"12->10 EPSILON 0,0,0\n" +
"12->13 EPSILON 0,0,0\n" +
"13->3 EPSILON 0,0,0\n" +
"14->15 ATOM 42,0,0\n" +
"15->16 ATOM 47,0,0\n" +
"16->17 EPSILON 0,0,0\n" +
"17->18 ACTION 1,0,0\n" +
"18->5 EPSILON 0,0,0\n" +
"19->21 WILDCARD 0,0,0\n" +
"21->22 ACTION 2,1,0\n" +
"22->7 EPSILON 0,0,0\n" +
"0:0 1\n" +
"1:1 1\n" +
"2:12 1\n";
"0:TOKEN_START -1\n" +
"1:TOKEN_START -1\n" +
"2:RULE_START 0\n" +
"3:RULE_STOP 0\n" +
"4:RULE_START 1\n" +
"5:RULE_STOP 1\n" +
"6:RULE_START 2\n" +
"7:RULE_STOP 2\n" +
"8:BASIC 0\n" +
"9:PLUS_BLOCK_START 0 10\n" +
"10:BLOCK_END 0\n" +
"11:PLUS_LOOP_BACK 0\n" +
"12:LOOP_END 0 11\n" +
"13:BASIC 1\n" +
"14:BASIC 1\n" +
"15:BASIC 1\n" +
"16:BASIC 1\n" +
"17:BASIC 1\n" +
"18:BASIC 2\n" +
"19:BASIC 2\n" +
"20:BASIC 2\n" +
"rule 0:2 1,-1\n" +
"rule 1:4 2,0\n" +
"rule 2:6 3,1\n" +
"mode 0:0\n" +
"mode 1:1\n" +
"0->2 EPSILON 0,0,0\n" +
"1->4 EPSILON 0,0,0\n" +
"1->6 EPSILON 0,0,0\n" +
"2->9 EPSILON 0,0,0\n" +
"4->13 EPSILON 0,0,0\n" +
"6->18 EPSILON 0,0,0\n" +
"8->10 RANGE 97,122,0\n" +
"9->8 EPSILON 0,0,0\n" +
"10->11 EPSILON 0,0,0\n" +
"11->9 EPSILON 0,0,0\n" +
"11->12 EPSILON 0,0,0\n" +
"12->3 EPSILON 0,0,0\n" +
"13->14 ATOM 42,0,0\n" +
"14->15 ATOM 47,0,0\n" +
"15->16 EPSILON 0,0,0\n" +
"16->17 ACTION 1,0,0\n" +
"17->5 EPSILON 0,0,0\n" +
"18->19 WILDCARD 0,0,0\n" +
"19->20 ACTION 2,1,0\n" +
"20->7 EPSILON 0,0,0\n" +
"0:0 1\n" +
"1:1 1\n" +
"2:11 1\n";
ATN atn = createATN(lg);
String result = ATNSerializer.getDecoded(lg, atn);
assertEquals(expecting, result);
@ -612,22 +603,22 @@ public class TestATNSerialization extends BaseTest {
"ID : ~('a'|'b') ~('e'|'p'..'t')\n ;");
String expecting =
"max type 1\n" +
"0:TOKEN_START -1\n" +
"1:RULE_START 0\n" +
"2:RULE_STOP 0\n" +
"3:BASIC 0\n" +
"5:BASIC 0\n" +
"6:BASIC 0\n" +
"rule 0:1 1,-1\n" +
"mode 0:0\n" +
"0:'a'..'b'\n" +
"1:'e'..'e', 'p'..'t'\n" +
"0->1 EPSILON 0,0,0\n" +
"1->3 EPSILON 0,0,0\n" +
"3->5 NOT_SET 0,0,0\n" +
"5->6 NOT_SET 1,0,0\n" +
"6->2 EPSILON 0,0,0\n" +
"0:0 1\n";
"0:TOKEN_START -1\n" +
"1:RULE_START 0\n" +
"2:RULE_STOP 0\n" +
"3:BASIC 0\n" +
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"rule 0:1 1,-1\n" +
"mode 0:0\n" +
"0:'a'..'b'\n" +
"1:'e'..'e', 'p'..'t'\n" +
"0->1 EPSILON 0,0,0\n" +
"1->3 EPSILON 0,0,0\n" +
"3->4 NOT_SET 0,0,0\n" +
"4->5 NOT_SET 1,0,0\n" +
"5->2 EPSILON 0,0,0\n" +
"0:0 1\n";
ATN atn = createATN(lg);
String result = ATNSerializer.getDecoded(lg, atn);
assertEquals(expecting, result);