@Test void multipleValidRules() { final List<Token> tokens = Arrays.asList( new Token(REDUCTION, "reduction", 0), new Token(IDENTIFIER, "test1", 0), new Token(COLON, ":", 0), new Token(PLUS, "+", 0), new Token(IDENTIFIER, "x", 0), new Token(ARROW, "->", 0), new Token(IDENTIFIER, "x", 0), new Token(EXPANSION, "expansion", 0), new Token(IDENTIFIER, "test2", 0), new Token(COLON, ":", 0), new Token(IDENTIFIER, "x", 0), new Token(ARROW, "->", 0), new Token(MINUS, "-", 0), new Token(MINUS, "-", 0), new Token(IDENTIFIER, "x", 0), new Token(CALCULATION, "calculation", 0), new Token(IDENTIFIER, "test3", 0), new Token(COLON, ":", 0), new Token(NUMBER, "1", 0), new Token(PLUS, "+", 0), new Token(NUMBER, "1", 0), new Token(ARROW, "->", 0), new Token(NUMBER, "2", 0), new Token(EOF, "", 0) ); final Parser parser = new Parser(tokens, errors::add); final List<PatternRule> expected = Arrays.asList( new PatternRule( "test1", RuleType.REDUCTION, new SubFunctionPattern("x"), new SubFunctionPattern("x") ), new PatternRule( "test2", RuleType.EXPANSION, new SubFunctionPattern("x"), new NegativePattern(new NegativePattern(new SubFunctionPattern("x"))) ), new PatternRule( "test3", RuleType.CALCULATION, new SumPattern( new NumberPattern(new BigDecimal(1)), new NumberPattern(new BigDecimal(1)) ), new NumberPattern(new BigDecimal(2)) ) ); assertEquals(expected, parser.parse()); }
public List<PatternRule> parse() { if (used) { throw new IllegalStateException("Parser.parse can only be called once per instance"); } used = true; return rules(); }
Parser { public List<PatternRule> parse() { if (used) { throw new IllegalStateException("Parser.parse can only be called once per instance"); } used = true; return rules(); } }
Parser { public List<PatternRule> parse() { if (used) { throw new IllegalStateException("Parser.parse can only be called once per instance"); } used = true; return rules(); } Parser(final List<Token> tokens, final Consumer<? super DslError> errorReporter); }
Parser { public List<PatternRule> parse() { if (used) { throw new IllegalStateException("Parser.parse can only be called once per instance"); } used = true; return rules(); } Parser(final List<Token> tokens, final Consumer<? super DslError> errorReporter); List<PatternRule> parse(); Token getSubFunctionIdentifier(final SubFunctionPattern subFunction); }
Parser { public List<PatternRule> parse() { if (used) { throw new IllegalStateException("Parser.parse can only be called once per instance"); } used = true; return rules(); } Parser(final List<Token> tokens, final Consumer<? super DslError> errorReporter); List<PatternRule> parse(); Token getSubFunctionIdentifier(final SubFunctionPattern subFunction);  }