@Test public void shouldParseWriteLiteralShort() throws Exception { String scriptFragment = "write 5s"; ScriptParserImpl parser = new ScriptParserImpl(); AstWriteValueNode actual = parser.parseWithStrategy(scriptFragment, WRITE); AstWriteValueNode expected = new AstWriteNodeBuilder() .addShort((short)5).done(); assertEquals(expected, actual); assertEquals(1, actual.getRegionInfo().children.size()); }
public <T extends AstRegion> T parseWithStrategy(String input, ScriptParseStrategy<T> strategy) throws ScriptParseException { T result = null; int newStart = 0; int newEnd = input.length(); CharStream ais = CharStreams.fromString(input); RobotLexer lexer = new RobotLexer(ais); CommonTokenStream tokens = new CommonTokenStream(lexer); final RobotParser parser = new RobotParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); try { result = strategy.parse(parser, factory, context); RegionInfo regionInfo = result.getRegionInfo(); List<RegionInfo> newChildren = regionInfo.children; switch (regionInfo.kind) { case SEQUENTIAL: result.setRegionInfo(newSequential(newChildren, newStart, newEnd)); break; case PARALLEL: result.setRegionInfo(newParallel(newChildren, newStart, newEnd)); break; } } catch (ParseCancellationException pce) { Throwable cause = pce.getCause(); if (cause instanceof RecognitionException) { RecognitionException re = (RecognitionException) cause; throw createScriptParseException(parser, re); } throw pce; } catch (RecognitionException re) { throw createScriptParseException(parser, re); } return result; }
ScriptParserImpl implements ScriptParser { public <T extends AstRegion> T parseWithStrategy(String input, ScriptParseStrategy<T> strategy) throws ScriptParseException { T result = null; int newStart = 0; int newEnd = input.length(); CharStream ais = CharStreams.fromString(input); RobotLexer lexer = new RobotLexer(ais); CommonTokenStream tokens = new CommonTokenStream(lexer); final RobotParser parser = new RobotParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); try { result = strategy.parse(parser, factory, context); RegionInfo regionInfo = result.getRegionInfo(); List<RegionInfo> newChildren = regionInfo.children; switch (regionInfo.kind) { case SEQUENTIAL: result.setRegionInfo(newSequential(newChildren, newStart, newEnd)); break; case PARALLEL: result.setRegionInfo(newParallel(newChildren, newStart, newEnd)); break; } } catch (ParseCancellationException pce) { Throwable cause = pce.getCause(); if (cause instanceof RecognitionException) { RecognitionException re = (RecognitionException) cause; throw createScriptParseException(parser, re); } throw pce; } catch (RecognitionException re) { throw createScriptParseException(parser, re); } return result; } }
ScriptParserImpl implements ScriptParser { public <T extends AstRegion> T parseWithStrategy(String input, ScriptParseStrategy<T> strategy) throws ScriptParseException { T result = null; int newStart = 0; int newEnd = input.length(); CharStream ais = CharStreams.fromString(input); RobotLexer lexer = new RobotLexer(ais); CommonTokenStream tokens = new CommonTokenStream(lexer); final RobotParser parser = new RobotParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); try { result = strategy.parse(parser, factory, context); RegionInfo regionInfo = result.getRegionInfo(); List<RegionInfo> newChildren = regionInfo.children; switch (regionInfo.kind) { case SEQUENTIAL: result.setRegionInfo(newSequential(newChildren, newStart, newEnd)); break; case PARALLEL: result.setRegionInfo(newParallel(newChildren, newStart, newEnd)); break; } } catch (ParseCancellationException pce) { Throwable cause = pce.getCause(); if (cause instanceof RecognitionException) { RecognitionException re = (RecognitionException) cause; throw createScriptParseException(parser, re); } throw pce; } catch (RecognitionException re) { throw createScriptParseException(parser, re); } return result; } ScriptParserImpl();  ScriptParserImpl(ExpressionFactory factory, ExpressionContext context); }
ScriptParserImpl implements ScriptParser { public <T extends AstRegion> T parseWithStrategy(String input, ScriptParseStrategy<T> strategy) throws ScriptParseException { T result = null; int newStart = 0; int newEnd = input.length(); CharStream ais = CharStreams.fromString(input); RobotLexer lexer = new RobotLexer(ais); CommonTokenStream tokens = new CommonTokenStream(lexer); final RobotParser parser = new RobotParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); try { result = strategy.parse(parser, factory, context); RegionInfo regionInfo = result.getRegionInfo(); List<RegionInfo> newChildren = regionInfo.children; switch (regionInfo.kind) { case SEQUENTIAL: result.setRegionInfo(newSequential(newChildren, newStart, newEnd)); break; case PARALLEL: result.setRegionInfo(newParallel(newChildren, newStart, newEnd)); break; } } catch (ParseCancellationException pce) { Throwable cause = pce.getCause(); if (cause instanceof RecognitionException) { RecognitionException re = (RecognitionException) cause; throw createScriptParseException(parser, re); } throw pce; } catch (RecognitionException re) { throw createScriptParseException(parser, re); } return result; } ScriptParserImpl();  ScriptParserImpl(ExpressionFactory factory, ExpressionContext context); ExpressionFactory getExpressionFactory(); ExpressionContext getExpressionContext(); @Override AstScriptNode parse(String input); T parseWithStrategy(String input, ScriptParseStrategy<T> strategy); }
ScriptParserImpl implements ScriptParser { public <T extends AstRegion> T parseWithStrategy(String input, ScriptParseStrategy<T> strategy) throws ScriptParseException { T result = null; int newStart = 0; int newEnd = input.length(); CharStream ais = CharStreams.fromString(input); RobotLexer lexer = new RobotLexer(ais); CommonTokenStream tokens = new CommonTokenStream(lexer); final RobotParser parser = new RobotParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); try { result = strategy.parse(parser, factory, context); RegionInfo regionInfo = result.getRegionInfo(); List<RegionInfo> newChildren = regionInfo.children; switch (regionInfo.kind) { case SEQUENTIAL: result.setRegionInfo(newSequential(newChildren, newStart, newEnd)); break; case PARALLEL: result.setRegionInfo(newParallel(newChildren, newStart, newEnd)); break; } } catch (ParseCancellationException pce) { Throwable cause = pce.getCause(); if (cause instanceof RecognitionException) { RecognitionException re = (RecognitionException) cause; throw createScriptParseException(parser, re); } throw pce; } catch (RecognitionException re) { throw createScriptParseException(parser, re); } return result; } ScriptParserImpl();  ScriptParserImpl(ExpressionFactory factory, ExpressionContext context); ExpressionFactory getExpressionFactory(); ExpressionContext getExpressionContext(); @Override AstScriptNode parse(String input); T parseWithStrategy(String input, ScriptParseStrategy<T> strategy);  }