Skip to content

Commit a1acdfd

Browse files
dwightguthehildenb
authored andcommitted
Fix parsing bugs (runtimeverification#559)
* fix poly prods for KItem sort * fix bug in rewrite priority visitor for nested rewrites in #fun * add tests
1 parent 5804f25 commit a1acdfd

6 files changed

Lines changed: 38 additions & 3 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DEF=test
2+
EXT=test
3+
TESTDIR=.
4+
KOMPILE_FLAGS=-w2e
5+
6+
include ../../../include/ktest.mak
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module TEST-SYNTAX
2+
endmodule
3+
4+
module TEST
5+
imports TEST-SYNTAX
6+
imports INT
7+
imports MAP
8+
imports ID
9+
10+
syntax Type ::= "type"
11+
syntax Foo ::= foo(Map)
12+
13+
rule foo(1 |-> 0 => 1 |-> #fun(T::Type => T |-> T)(type))
14+
15+
16+
endmodule
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DEF=test
2+
EXT=test
3+
TESTDIR=.
4+
5+
include ../../../include/ktest.mak
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module TEST
2+
3+
syntax KItem ::= foo(KItem)
4+
5+
rule foo((foo(G:KItem) => foo(foo(G))))
6+
endmodule

kernel/src/main/java/org/kframework/parser/concrete2kore/disambiguation/CorrectRewritePriorityVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Either<java.util.Set<ParseFailedException>, Term> apply(Ambiguity amb) {
4747
if (rewrites.size() == 0 || rewrites.size() == amb.items().size())
4848
return super.apply(amb);
4949
if (rewrites.size() == 1)
50-
return Right.apply(rewrites.head());
50+
return apply(rewrites.head());
5151
return super.apply(Ambiguity.apply(mutable(rewrites)));
5252
}
5353

kernel/src/main/java/org/kframework/parser/concrete2kore/generator/RuleGrammarGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ public static ParseInModule getCombinedGrammar(Module mod, boolean strict, boole
251251
}
252252
}
253253
}
254-
prods.add(Production(p.klabel(), returnSort, immutable(pis), p.att().add(Constants.ORIGINAL_PRD, Production.class, p)));
254+
if (!(pis.size() == 1 && pis.get(0) instanceof NonTerminal && ((NonTerminal)pis.get(0)).sort().equals(returnSort))) {
255+
prods.add(Production(p.klabel(), returnSort, immutable(pis), p.att().add(Constants.ORIGINAL_PRD, Production.class, p)));
256+
}
255257
}
256258
}
257259
}
@@ -401,7 +403,7 @@ public static List<Set<Integer>> computePositions(String p) {
401403

402404
private static List<List<Sort>> makeAllSortTuples(int size, Module mod) {
403405
List<List<Sort>> res = new ArrayList<>();
404-
List<Sort> allSorts = stream(mod.definedSorts()).filter(s -> !isParserSort(s)).collect(Collectors.toList());
406+
List<Sort> allSorts = stream(mod.definedSorts()).filter(s -> !isParserSort(s) || s.equals(Sorts.KItem())).collect(Collectors.toList());
405407
makeAllSortTuples(size, size, allSorts, res, new int[size]);
406408
return res;
407409
}

0 commit comments

Comments
 (0)