Search in sources :

Example 1 with TokenNavigator

use of kalang.util.TokenNavigator in project kalang by kasonyang.

the class KalangCompilerTest method testTokenNavigator.

private void testTokenNavigator(Token[] tokens, ParseTree tree) {
    TokenNavigator tokenNav = new TokenNavigator(tokens);
    ParseTreeNavigator treeNav = new ParseTreeNavigator(tree);
    assertEquals(0, tokenNav.getCurrentTokenIndex());
    assertEquals("class", treeNav.getParseTree(tokenNav.getCurrentToken()).getText());
    tokenNav.move(5);
    assertEquals("{", tokenNav.getCurrentToken().getText());
    assertEquals(1, tokenNav.getCurrentTokenIndex());
    tokenNav.next(KalangLexer.DEFAULT_TOKEN_CHANNEL);
    assertEquals("}", tokenNav.getCurrentToken().getText());
    tokenNav.move(8);
    assertEquals("}", tokenNav.getCurrentToken().getText());
    assertEquals("}", treeNav.getParseTree(tokenNav.getCurrentToken()).getText());
    assertEquals(3, tokenNav.getCurrentTokenIndex());
}
Also used : TokenNavigator(kalang.util.TokenNavigator) ParseTreeNavigator(kalang.util.ParseTreeNavigator)

Aggregations

ParseTreeNavigator (kalang.util.ParseTreeNavigator)1 TokenNavigator (kalang.util.TokenNavigator)1