@Test public void patternShouldAddDefaultCase() { Value pattern = matcher("scotch.test.oneOrZero", t(1), arg("#0", t(2)), pattern("scotch.test.(oneOrZero#0)", asList(equal(arg("#0", t(3)), literal(1))), literal(true)), pattern("scotch.test.(oneOrZero#1)", asList(equal(arg("#0", t(10)), literal(0))), literal(true)) ); SymbolGenerator generator = new DefaultSymbolGenerator() {{ startTypesAt(14); }}; assertThat(pattern.reducePatterns(new DefaultPatternReducer(generator)), is(fn("scotch.test.oneOrZero", arg("#0", t(2)), conditional( apply( apply(id("scotch.data.eq.(==)", t(14)), arg("#0", t(3)), t(15)), literal(1), t(16) ), scope("scotch.test.(oneOrZero#0)", literal(true)), conditional( apply( apply(id("scotch.data.eq.(==)", t(17)), arg("#0", t(10)), t(18)), literal(0), t(19) ), scope("scotch.test.(oneOrZero#1)", literal(true)), raise("Incomplete match", t(20)), t(21) ), t(22) )))); }
private PatternState pattern() { return patterns.peek(); }
DefaultPatternReducer implements PatternReducer { private PatternState pattern() { return patterns.peek(); } }
DefaultPatternReducer implements PatternReducer { private PatternState pattern() { return patterns.peek(); } DefaultPatternReducer(SymbolGenerator generator); }
DefaultPatternReducer implements PatternReducer { private PatternState pattern() { return patterns.peek(); } DefaultPatternReducer(SymbolGenerator generator); @Override void addAssignment(CaptureMatch capture); @Override void addCondition(Value argument, Value value); @Override void addCondition(IsConstructor constructor); @Override void addTaggedArgument(Value taggedArgument); @Override void beginPattern(PatternMatcher matcher); @Override void beginPatternCase(PatternCase patternCase); @Override void endPattern(); @Override void endPatternCase(); @Override Value getTaggedArgument(Value argument); @Override void markFunction(FunctionValue function); @Override Value reducePattern(); }
DefaultPatternReducer implements PatternReducer { private PatternState pattern() { return patterns.peek(); } DefaultPatternReducer(SymbolGenerator generator); @Override void addAssignment(CaptureMatch capture); @Override void addCondition(Value argument, Value value); @Override void addCondition(IsConstructor constructor); @Override void addTaggedArgument(Value taggedArgument); @Override void beginPattern(PatternMatcher matcher); @Override void beginPatternCase(PatternCase patternCase); @Override void endPattern(); @Override void endPatternCase(); @Override Value getTaggedArgument(Value argument); @Override void markFunction(FunctionValue function); @Override Value reducePattern();  }