@Test void parseSimple() { Term term = SUT.parse(IOUtils.toInputStream("payload.lengthInBytes+4", Charset.defaultCharset())); assertThat(term, not(nullValue())); assertThat(term, instanceOf(BinaryTerm.class)); BinaryTerm binaryTerm = (BinaryTerm) term; assertVariableLiteral( binaryTerm.getA(), "payload", null, lengthInBytesVariableLiteral -> assertVariableLiteral( lengthInBytesVariableLiteral, "lengthInBytes" ) ); assertNumericLiteral(binaryTerm.getB(), 4L); assertThat(binaryTerm.getOperation(), is("+")); }
public Term parse(InputStream source) { ExpressionLexer lexer; try { lexer = new ExpressionLexer(CharStreams.fromStream(source)); } catch (IOException e) { throw new RuntimeException(e); } ExpressionStringListener listener = new ExpressionStringListener(); new ParseTreeWalker().walk(listener, new ExpressionParser(new CommonTokenStream(lexer)).expressionString()); return listener.getRoot(); }
ExpressionStringParser { public Term parse(InputStream source) { ExpressionLexer lexer; try { lexer = new ExpressionLexer(CharStreams.fromStream(source)); } catch (IOException e) { throw new RuntimeException(e); } ExpressionStringListener listener = new ExpressionStringListener(); new ParseTreeWalker().walk(listener, new ExpressionParser(new CommonTokenStream(lexer)).expressionString()); return listener.getRoot(); } }
ExpressionStringParser { public Term parse(InputStream source) { ExpressionLexer lexer; try { lexer = new ExpressionLexer(CharStreams.fromStream(source)); } catch (IOException e) { throw new RuntimeException(e); } ExpressionStringListener listener = new ExpressionStringListener(); new ParseTreeWalker().walk(listener, new ExpressionParser(new CommonTokenStream(lexer)).expressionString()); return listener.getRoot(); }  }
ExpressionStringParser { public Term parse(InputStream source) { ExpressionLexer lexer; try { lexer = new ExpressionLexer(CharStreams.fromStream(source)); } catch (IOException e) { throw new RuntimeException(e); } ExpressionStringListener listener = new ExpressionStringListener(); new ParseTreeWalker().walk(listener, new ExpressionParser(new CommonTokenStream(lexer)).expressionString()); return listener.getRoot(); }  Term parse(InputStream source); }
ExpressionStringParser { public Term parse(InputStream source) { ExpressionLexer lexer; try { lexer = new ExpressionLexer(CharStreams.fromStream(source)); } catch (IOException e) { throw new RuntimeException(e); } ExpressionStringListener listener = new ExpressionStringListener(); new ParseTreeWalker().walk(listener, new ExpressionParser(new CommonTokenStream(lexer)).expressionString()); return listener.getRoot(); }  Term parse(InputStream source);  }