@Test void validRuleMultipleReplacements() { final List<Token> tokens = Arrays.asList( new Token(REDUCTION, "reduction", 0), new Token(IDENTIFIER, "TestRule_123", 10), new Token(COLON, ":", 22), new Token(IDENTIFIER, "x", 26), new Token(PLUS, "+", 28), new Token(IDENTIFIER, "y", 30), new Token(TIMES, "*", 32), new Token(IDENTIFIER, "z", 34), new Token(EQUALS, "=", 36), new Token(MINUS, "-", 38), new Token(LEFT_PAREN, "(", 39), new Token(IDENTIFIER, "a_123", 40), new Token(PLUS_MINUS, "+-", 46), new Token(NUMBER, "3", 49), new Token(DIVIDE, "/", 51), new Token(NUMBER, "2.2", 53), new Token(RIGHT_PAREN, ")", 56), new Token(ARROW, "->", 58), new Token(LEFT_BRACKET, "[", 61), new Token(IDENTIFIER, "x", 67), new Token(POWER, "^", 68), new Token(IDENTIFIER, "a_123", 69), new Token(EQUALS, "=", 75), new Token(COS, "cos", 77), new Token(LEFT_PAREN, "(", 80), new Token(PI, "pi", 81), new Token(RIGHT_PAREN, ")", 83), new Token(MINUS, "-", 85), new Token(LOG, "log", 87), new Token(LEFT_PAREN, "(", 90), new Token(E, "e", 91), new Token(COMMA, ",", 92), new Token(E, "e", 94), new Token(RIGHT_PAREN, ")", 95), new Token(COMMA, ",", 96), new Token(UNDEFINED, "undefined", 113), new Token(COMMA, ",", 122), new Token(RIGHT_BRACKET, "]", 138), new Token(EOF, "", 140) ); final Parser parser = new Parser(tokens, errors::add); final Pattern target = new EquationPattern( new SumPattern( new SubFunctionPattern("x"), new MultiplicationPattern( new SubFunctionPattern("y"), new SubFunctionPattern("z") ) ), new NegativePattern(new SumSubtractionPattern( new SubFunctionPattern("a_123"), new DivisionPattern( new NumberPattern(new BigDecimal(3)), new NumberPattern(new BigDecimal("2.2")) ) )) ); final Pattern replacement1 = new EquationPattern( new PowerPattern( new SubFunctionPattern("x"), new SubFunctionPattern("a_123") ), new SubtractionPattern( new CosinePattern(new ConstantPattern(MathematicalSymbols.PI)), new LogarithmPattern( new ConstantPattern(MathematicalSymbols.EULER_NUMBER), new ConstantPattern(MathematicalSymbols.EULER_NUMBER) ) ) ); final Pattern replacement2 = new UndefinedPattern(); final List<PatternRule> expected = Collections.singletonList(new PatternRule( "TestRule_123", RuleType.REDUCTION, target, replacement1, replacement2 )); 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);  }