-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from jdrem/states-out-of-order-#15
Allow states to be out of order. #15
- Loading branch information
Showing
2 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/net/remgant/tools/parser/test/OutOfSeqStateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.remgant.tools.parser.test; | ||
|
||
import net.remgant.tools.parser.Parser; | ||
import net.remgant.tools.parser.ParserException; | ||
import net.remgant.tools.parser.ParserResult; | ||
import net.remgant.tools.parser.Token; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
|
||
public class OutOfSeqStateTest { | ||
@Test | ||
public void testSkipStates() throws ParserException { | ||
Parser parser = new Parser() { | ||
@Override | ||
protected void init() { | ||
addState(0, Token.MATCH_ANY, 1, null); | ||
addState(1, Token.MATCH_ANY, 100, null); | ||
addState(100, Token.MATCH_ANY, 999, null); | ||
terminalStates = Collections.singleton(999); | ||
} | ||
|
||
@Override | ||
public ParserResult parse(String source) throws ParserException { | ||
init(); | ||
return super.parse(source); | ||
} | ||
}; | ||
parser.parse("a b c"); | ||
parser.printStateDiagram(System.out); | ||
} | ||
|
||
@Test | ||
public void testOutOfOrderStates() throws ParserException { | ||
Parser parser = new Parser() { | ||
@Override | ||
protected void init() { | ||
addState(0, Token.MATCH_ANY, 1, null); | ||
addState(2, Token.MATCH_ANY, 3, null); | ||
addState(1, Token.MATCH_ANY, 2, null); | ||
addState(3, Token.MATCH_ANY, 999, null); | ||
terminalStates = Collections.singleton(999); | ||
} | ||
|
||
@Override | ||
public ParserResult parse(String source) throws ParserException { | ||
init(); | ||
return super.parse(source); | ||
} | ||
}; | ||
|
||
parser.parse("a b c d"); | ||
} | ||
} |