package org.simantics.graph.compiler.tests; import org.antlr.runtime.ANTLRStringStream; import org.antlr.runtime.CharStream; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.Token; import org.antlr.runtime.TokenStream; import org.antlr.runtime.tree.Tree; import org.junit.Test; import org.simantics.databoard.util.Range; import org.simantics.graph.compiler.internal.parsing.GraphLexer; import org.simantics.graph.compiler.internal.parsing.GraphParser; public class RangeParsingTest { public static GraphParser parse(String text) { CharStream stream = new ANTLRStringStream(text); GraphLexer lexer = new GraphLexer(stream); TokenStream tokenStream = new CommonTokenStream(lexer); for(int i=1;;++i) { Token token = tokenStream.LT(i); if(token.getType() == GraphParser.EOF) break; System.out.println( GraphParser.tokenNames[token.getType()] + " " + token.getText()); } return new GraphParser(tokenStream); } @Test public void testRangeParsing() throws Exception { Tree tree = (Tree)parse("[1..2.3]").parameterValue().getTree(); System.out.println(tree.toStringTree()); } @Test public void testRangeInDataboard() throws Exception { Range.valueOfUnchecked("[0..1]"); } }