diff --git a/kernel/src/main/java/org/kframework/compile/ResolveFreshConstants.java b/kernel/src/main/java/org/kframework/compile/ResolveFreshConstants.java index b1d2b7e126e..80e50245e7a 100644 --- a/kernel/src/main/java/org/kframework/compile/ResolveFreshConstants.java +++ b/kernel/src/main/java/org/kframework/compile/ResolveFreshConstants.java @@ -249,8 +249,7 @@ public Module resolve(Module m) { if (m.name().equals(def.mainModule().name())) { if (!m.definedKLabels().contains(KLabels.GENERATED_TOP_CELL)) { RuleGrammarGenerator gen = new RuleGrammarGenerator(def); - ParseInModule mod = - RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(m), true, files); + ParseInModule mod = RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(m), files); ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(m); Sort topCellSort; try { @@ -283,8 +282,7 @@ public Module resolve(Module m) { } if (m.localKLabels().contains(KLabels.GENERATED_TOP_CELL)) { RuleGrammarGenerator gen = new RuleGrammarGenerator(def); - ParseInModule mod = - RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(m), true, files); + ParseInModule mod = RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(m), files); Set newSentences = GenerateSentencesFromConfigDecl.gen( freshCell, BooleanUtils.TRUE, Att.empty(), mod.getExtensionModule()); diff --git a/kernel/src/main/java/org/kframework/kast/KastFrontEnd.java b/kernel/src/main/java/org/kframework/kast/KastFrontEnd.java index 668c9e259dd..07eb2272d21 100644 --- a/kernel/src/main/java/org/kframework/kast/KastFrontEnd.java +++ b/kernel/src/main/java/org/kframework/kast/KastFrontEnd.java @@ -139,8 +139,7 @@ public int run() { String stringToParse = FileUtil.read(options.stringToParse()); Source source = options.source(); - try (ParseInModule parseInModule = - RuleGrammarGenerator.getCombinedGrammar(mod, true, null)) { + try (ParseInModule parseInModule = RuleGrammarGenerator.getCombinedGrammar(mod, null)) { if (options.debugTokens) System.out.println(parseInModule.tokenizeString(stringToParse, source)); else { @@ -155,7 +154,7 @@ public int run() { // syntax // like casts, projections and others Module unparsingMod = parseInModule.getExtensionModule(); - K parsed = new TreeNodesToKORE(Outer::parseSort, true).down(res._1().right().get()); + K parsed = new TreeNodesToKORE(Outer::parseSort).down(res._1().right().get()); if (options.expandMacros) { parsed = diff --git a/kernel/src/main/java/org/kframework/kompile/CompiledDefinition.java b/kernel/src/main/java/org/kframework/kompile/CompiledDefinition.java index befc33a363f..c1ad8c3a749 100644 --- a/kernel/src/main/java/org/kframework/kompile/CompiledDefinition.java +++ b/kernel/src/main/java/org/kframework/kompile/CompiledDefinition.java @@ -233,7 +233,7 @@ public K parseSingleTerm( Source source, boolean partialParseDebug) { try (ParseInModule parseInModule = - RuleGrammarGenerator.getCombinedGrammar(module, true, files, partialParseDebug)) { + RuleGrammarGenerator.getCombinedGrammar(module, files, partialParseDebug)) { Tuple2, K>, Set> res = parseInModule.parseString(s, programStartSymbol, startSymbolLocation, source); kem.addAllKException( @@ -241,19 +241,18 @@ public K parseSingleTerm( if (res._1().isLeft()) { throw res._1().left().get().iterator().next(); } - return new TreeNodesToKORE(Outer::parseSort, true).down(res._1().right().get()); + return new TreeNodesToKORE(Outer::parseSort).down(res._1().right().get()); } } public String showTokens(Module module, FileUtil files, String s, Source source) { - try (ParseInModule parseInModule = - RuleGrammarGenerator.getCombinedGrammar(module, true, files)) { + try (ParseInModule parseInModule = RuleGrammarGenerator.getCombinedGrammar(module, files)) { return parseInModule.tokenizeString(s, source); } } public Module getExtensionModule(Module module, FileUtil files) { - return RuleGrammarGenerator.getCombinedGrammar(module, true, files).getExtensionModule(); + return RuleGrammarGenerator.getCombinedGrammar(module, files).getExtensionModule(); } public Rule compilePatternIfAbsent( diff --git a/kernel/src/main/java/org/kframework/kompile/DefinitionParsing.java b/kernel/src/main/java/org/kframework/kompile/DefinitionParsing.java index 9c3d537ea02..3accece5257 100644 --- a/kernel/src/main/java/org/kframework/kompile/DefinitionParsing.java +++ b/kernel/src/main/java/org/kframework/kompile/DefinitionParsing.java @@ -441,7 +441,7 @@ private Definition resolveConfigBubbles(Definition def) { ParseCache cache = loadCache(configParserModule); try (ParseInModule parser = RuleGrammarGenerator.getCombinedGrammar( - cache.module(), true, profileRules, files, options.debugTypeInference)) { + cache.module(), profileRules, files, options.debugTypeInference)) { // each parser gets its own scanner because config labels can conflict with user // tokens parser.getScanner(globalOptions); @@ -507,7 +507,6 @@ private Definition resolveConfigBubbles(Definition def) { Module extMod = RuleGrammarGenerator.getCombinedGrammar( gen.getConfigGrammar(module), - true, profileRules, files, options.debugTypeInference) @@ -551,14 +550,7 @@ private Definition resolveNonConfigBubbles( ParseCache cache = loadCache(ruleParserModule); try (ParseInModule parser = RuleGrammarGenerator.getCombinedGrammar( - cache.module(), - true, - profileRules, - false, - true, - files, - options.debugTypeInference, - false)) { + cache.module(), profileRules, false, true, files, options.debugTypeInference, false)) { Scanner scanner; if (deserializeScanner) { scanner = new Scanner(parser, globalOptions, files.resolveKompiled("scanner")); @@ -590,11 +582,10 @@ private Module resolveNonConfigBubbles(Module module, Scanner scanner, RuleGramm try (ParseInModule parser = needNewScanner ? RuleGrammarGenerator.getCombinedGrammar( - cache.module(), true, profileRules, files, options.debugTypeInference) + cache.module(), profileRules, files, options.debugTypeInference) : RuleGrammarGenerator.getCombinedGrammar( cache.module(), scanner, - true, profileRules, false, files, @@ -682,8 +673,7 @@ private Definition resolveCachedBubbles(Definition def, boolean isRule) { registerWarnings(parse.warnings()); KApply k = (KApply) - new TreeNodesToKORE(Outer::parseSort, true) - .down(parse.parse()); + new TreeNodesToKORE(Outer::parseSort).down(parse.parse()); return Stream.of(Pair.of(b, upSentence(k, b.sentenceType()))); } return Stream.of(); @@ -794,7 +784,6 @@ public Rule parseRule(CompiledDefinition compiledDef, String contents, Source so try (ParseInModule parser = RuleGrammarGenerator.getCombinedGrammar( gen.getRuleGrammar(compiledDef.getParsedDefinition().mainModule()), - true, profileRules, false, true, @@ -961,7 +950,7 @@ private Stream parseBubble( b.contents(), new ParsedSentence( k, new HashSet<>(result._2()), new HashSet<>(), startLine, startColumn, source)); - k = (KApply) new TreeNodesToKORE(Outer::parseSort, true).down(k); + k = (KApply) new TreeNodesToKORE(Outer::parseSort).down(k); return Stream.of(k); } else { cache.put( diff --git a/kernel/src/main/java/org/kframework/parser/KRead.java b/kernel/src/main/java/org/kframework/parser/KRead.java index 2992b08d9ca..45b890cdef8 100644 --- a/kernel/src/main/java/org/kframework/parser/KRead.java +++ b/kernel/src/main/java/org/kframework/parser/KRead.java @@ -79,7 +79,7 @@ public void createBisonParser( boolean library) { Stopwatch sw = new Stopwatch(globalOptions); try (ParseInModule parseInModule = - RuleGrammarGenerator.getCombinedGrammar(mod, true, false, true, false, files)) { + RuleGrammarGenerator.getCombinedGrammar(mod, false, true, false, files)) { try (Scanner scanner = parseInModule.getScanner(kem.options)) { File scannerFile = files.resolveTemp("scanner.l"); File scanHdr = files.resolveTemp("scanner.h"); diff --git a/kernel/src/main/java/org/kframework/parser/inner/ParseInModule.java b/kernel/src/main/java/org/kframework/parser/inner/ParseInModule.java index 9a71cc3d75f..5630b4b86c2 100644 --- a/kernel/src/main/java/org/kframework/parser/inner/ParseInModule.java +++ b/kernel/src/main/java/org/kframework/parser/inner/ParseInModule.java @@ -58,7 +58,6 @@ public class ParseInModule implements Serializable, AutoCloseable { private volatile Module parsingModule; private volatile EarleyParser parser = null; - private final boolean strict; private final boolean profileRules; private final boolean isBison; private final boolean forGlobalScanner; @@ -68,7 +67,6 @@ public class ParseInModule implements Serializable, AutoCloseable { ParseInModule( Module seedModule, - boolean strict, boolean profileRules, boolean isBison, boolean forGlobalScanner, @@ -81,7 +79,6 @@ public class ParseInModule implements Serializable, AutoCloseable { null, null, null, - strict, profileRules, isBison, forGlobalScanner, @@ -93,7 +90,6 @@ public class ParseInModule implements Serializable, AutoCloseable { ParseInModule( Module seedModule, Scanner scanner, - boolean strict, boolean profileRules, boolean isBison, boolean forGlobalScanner, @@ -106,7 +102,6 @@ public class ParseInModule implements Serializable, AutoCloseable { null, null, scanner, - strict, profileRules, isBison, forGlobalScanner, @@ -121,7 +116,6 @@ private ParseInModule( Module disambModule, Module parsingModule, Scanner scanner, - boolean strict, boolean profileRules, boolean isBison, boolean forGlobalScanner, @@ -133,7 +127,6 @@ private ParseInModule( this.disambModule = disambModule; this.parsingModule = parsingModule; this.scanner = scanner; - this.strict = strict; this.profileRules = profileRules; this.isBison = isBison; this.forGlobalScanner = forGlobalScanner; @@ -350,9 +343,7 @@ public Tuple2, K>, Set> parseString( parseInfo = Left.apply(result._1().left().get()); } else { parseInfo = - Right.apply( - new TreeNodesToKORE(Outer::parseSort, inferSortChecks && strict) - .apply(result._1().right().get())); + Right.apply(new TreeNodesToKORE(Outer::parseSort).apply(result._1().right().get())); } return new Tuple2<>(parseInfo, result._2()); } @@ -430,7 +421,7 @@ private Tuple2, Term>, Set> parseStringTe rez = new TypeInferenceVisitor( - currentInferencer, startSymbol, strict && inferSortChecks, true, isAnywhere) + currentInferencer, startSymbol, inferSortChecks, true, isAnywhere) .apply(rez3); if (rez.isLeft()) return new Tuple2<>(rez, warn); endTypeInf = profileRules ? System.currentTimeMillis() : 0; @@ -439,7 +430,7 @@ private Tuple2, Term>, Set> parseStringTe if (rez.isLeft()) return new Tuple2<>(rez, warn); rez3 = new PushAmbiguitiesDownAndPreferAvoid(disambModule.overloads()).apply(rez.right().get()); - rez = new AmbFilterError(strict && inferSortChecks).apply(rez3); + rez = new AmbFilterError().apply(rez3); if (rez.isLeft()) return new Tuple2<>(rez, warn); Tuple2, Term>, Set> rez2 = new AddEmptyLists(disambModule, startSymbol).apply(rez.right().get()); @@ -500,11 +491,11 @@ public static Term disambiguateForUnparse(Module mod, Term ambiguity) { rez = new TypeInferenceVisitor(inferencer, Sorts.K(), false, false, false).apply(rez3); } if (rez.isLeft()) { - rez2 = new AmbFilter(false).apply(rez3); + rez2 = new AmbFilter().apply(rez3); return rez2._1().right().get(); } rez3 = new PushAmbiguitiesDownAndPreferAvoid(mod.overloads()).apply(rez.right().get()); - rez2 = new AmbFilter(false).apply(rez3); + rez2 = new AmbFilter().apply(rez3); return rez2._1().right().get(); } } diff --git a/kernel/src/main/java/org/kframework/parser/inner/RuleGrammarGenerator.java b/kernel/src/main/java/org/kframework/parser/inner/RuleGrammarGenerator.java index c36f93e4598..93163bba47b 100644 --- a/kernel/src/main/java/org/kframework/parser/inner/RuleGrammarGenerator.java +++ b/kernel/src/main/java/org/kframework/parser/inner/RuleGrammarGenerator.java @@ -200,48 +200,37 @@ public static boolean isParserSort(Sort s) { } /* use this overload if you don't need to profile rule parse times. */ - public static ParseInModule getCombinedGrammar(Module mod, boolean strict, FileUtil files) { - return getCombinedGrammar(mod, strict, false, false, false, files, null, false); + public static ParseInModule getCombinedGrammar(Module mod, FileUtil files) { + return getCombinedGrammar(mod, false, false, false, files, null, false); } public static ParseInModule getCombinedGrammar( - Module mod, boolean strict, FileUtil files, boolean partialParseDebug) { - return getCombinedGrammar(mod, strict, false, false, false, files, null, partialParseDebug); + Module mod, FileUtil files, boolean partialParseDebug) { + return getCombinedGrammar(mod, false, false, false, files, null, partialParseDebug); } - public static ParseInModule getCombinedGrammar( - Module mod, boolean strict, boolean timing, FileUtil files) { - return getCombinedGrammar(mod, strict, timing, false, false, files, null, false); + public static ParseInModule getCombinedGrammar(Module mod, boolean timing, FileUtil files) { + return getCombinedGrammar(mod, timing, false, false, files, null, false); } public static ParseInModule getCombinedGrammar( - Module mod, boolean strict, boolean timing, FileUtil files, String debugTypeInference) { - return getCombinedGrammar(mod, strict, timing, false, false, files, debugTypeInference, false); + Module mod, boolean timing, FileUtil files, String debugTypeInference) { + return getCombinedGrammar(mod, timing, false, false, files, debugTypeInference, false); } public static ParseInModule getCombinedGrammar( - Module mod, boolean strict, boolean timing, boolean isBison, FileUtil files) { - return getCombinedGrammar(mod, strict, timing, isBison, false, files, null, false); + Module mod, boolean timing, boolean isBison, FileUtil files) { + return getCombinedGrammar(mod, timing, isBison, false, files, null, false); } public static ParseInModule getCombinedGrammar( - Module mod, - boolean strict, - boolean timing, - boolean isBison, - boolean forGlobalScanner, - FileUtil files) { - return getCombinedGrammar(mod, strict, timing, isBison, forGlobalScanner, files, null, false); + Module mod, boolean timing, boolean isBison, boolean forGlobalScanner, FileUtil files) { + return getCombinedGrammar(mod, timing, isBison, forGlobalScanner, files, null, false); } public static ParseInModule getCombinedGrammar( - Module mod, - Scanner scanner, - boolean strict, - boolean timing, - boolean isBison, - FileUtil files) { - return getCombinedGrammar(mod, scanner, strict, timing, isBison, files, null, false); + Module mod, Scanner scanner, boolean timing, boolean isBison, FileUtil files) { + return getCombinedGrammar(mod, scanner, timing, isBison, files, null, false); } // the forGlobalScanner flag tells the ParseInModule class not to exclude @@ -264,7 +253,6 @@ public static ParseInModule getCombinedGrammar( */ public static ParseInModule getCombinedGrammar( Module mod, - boolean strict, boolean timing, boolean isBison, boolean forGlobalScanner, @@ -272,27 +260,19 @@ public static ParseInModule getCombinedGrammar( String debugTypeInference, boolean partialParseDebug) { return new ParseInModule( - mod, - strict, - timing, - isBison, - forGlobalScanner, - files, - debugTypeInference, - partialParseDebug); + mod, timing, isBison, forGlobalScanner, files, debugTypeInference, partialParseDebug); } public static ParseInModule getCombinedGrammar( Module mod, Scanner scanner, - boolean strict, boolean timing, boolean isBison, FileUtil files, String debugTypeInference, boolean partialParseDebug) { return new ParseInModule( - mod, scanner, strict, timing, isBison, false, files, debugTypeInference, partialParseDebug); + mod, scanner, timing, isBison, false, files, debugTypeInference, partialParseDebug); } public static Tuple3 getCombinedGrammarImpl( diff --git a/kernel/src/main/java/org/kframework/parser/inner/disambiguation/AmbFilter.java b/kernel/src/main/java/org/kframework/parser/inner/disambiguation/AmbFilter.java index 9ed5c7e2b33..a2fe9fa429a 100644 --- a/kernel/src/main/java/org/kframework/parser/inner/disambiguation/AmbFilter.java +++ b/kernel/src/main/java/org/kframework/parser/inner/disambiguation/AmbFilter.java @@ -17,11 +17,7 @@ /** Eliminate remaining ambiguities by choosing one of them. */ public class AmbFilter extends SetsGeneralTransformer { - private final boolean strict; - - public AmbFilter(boolean strict) { - this.strict = strict; - } + public AmbFilter() {} @Override public Tuple2, Term>, Set> apply(Ambiguity amb) { @@ -31,7 +27,7 @@ public Tuple2, Term>, Set> apply(Ambiguit for (Term t : amb.items()) { candidate = this.apply(t); K next = - new TreeNodesToKORE(Outer::parseSort, strict) + new TreeNodesToKORE(Outer::parseSort) .apply(new RemoveBracketVisitor().apply(candidate._1().right().get())); if (last != null) { if (!last.equals(next)) { diff --git a/kernel/src/main/java/org/kframework/parser/inner/disambiguation/AmbFilterError.java b/kernel/src/main/java/org/kframework/parser/inner/disambiguation/AmbFilterError.java index 033f8373595..f4de75f1b49 100644 --- a/kernel/src/main/java/org/kframework/parser/inner/disambiguation/AmbFilterError.java +++ b/kernel/src/main/java/org/kframework/parser/inner/disambiguation/AmbFilterError.java @@ -17,11 +17,7 @@ /** Report remaining ambiguities as errors. */ public class AmbFilterError extends SetsTransformerWithErrors { - private final boolean strict; - - public AmbFilterError(boolean strict) { - this.strict = strict; - } + public AmbFilterError() {} @Override public Either, Term> apply(Ambiguity amb) { @@ -34,7 +30,7 @@ public Either, Term> apply(Ambiguity amb) { return candidate; } K next = - new TreeNodesToKORE(Outer::parseSort, strict) + new TreeNodesToKORE(Outer::parseSort) .apply(new RemoveBracketVisitor().apply(candidate.right().get())); if (last != null) { if (!last.equals(next)) { diff --git a/kernel/src/main/java/org/kframework/unparser/KPrint.java b/kernel/src/main/java/org/kframework/unparser/KPrint.java index b681321f98d..90579c0cf1e 100644 --- a/kernel/src/main/java/org/kframework/unparser/KPrint.java +++ b/kernel/src/main/java/org/kframework/unparser/KPrint.java @@ -158,13 +158,13 @@ public byte[] prettyPrint( return serialize(result, outputMode); case PRETTY: Module prettyUnparsingModule = - RuleGrammarGenerator.getCombinedGrammar(module, false, files).getExtensionModule(); + RuleGrammarGenerator.getCombinedGrammar(module, files).getExtensionModule(); return (unparseTerm(result, prettyUnparsingModule, colorize) + "\n").getBytes(); case PROGRAM: { RuleGrammarGenerator gen = new RuleGrammarGenerator(def); Module programUnparsingModule = - RuleGrammarGenerator.getCombinedGrammar(gen.getProgramsGrammar(module), false, files) + RuleGrammarGenerator.getCombinedGrammar(gen.getProgramsGrammar(module), files) .getParsingModule(); return (unparseTerm(result, programUnparsingModule, colorize) + "\n").getBytes(); } @@ -328,7 +328,7 @@ public Optional filterEquality(K term, Multiset vars, Module mod) private K sortCollections(Module mod, K input) { Module unparsingModule = - RuleGrammarGenerator.getCombinedGrammar(mod, false, files).getExtensionModule(); + RuleGrammarGenerator.getCombinedGrammar(mod, files).getExtensionModule(); return new TransformK() { @Override public K apply(KApply k) { @@ -408,7 +408,7 @@ private static K omitTerm(Module mod, KApply kapp) { private K tokenizeTerm(Module mod, KApply kapp) { Module unparsingModule = - RuleGrammarGenerator.getCombinedGrammar(mod, false, files).getExtensionModule(); + RuleGrammarGenerator.getCombinedGrammar(mod, files).getExtensionModule(); String tokenizedTerm = unparseTerm(kapp, unparsingModule, ColorSetting.OFF); Sort finalSort = Sorts.K(); Option termSort = mod.sortFor().get(kapp.klabel()); diff --git a/kernel/src/test/java/org/kframework/kore/compile/GenerateSentencesFromConfigDeclTest.java b/kernel/src/test/java/org/kframework/kore/compile/GenerateSentencesFromConfigDeclTest.java index a81b8d8d54e..c593ad9e5c8 100644 --- a/kernel/src/test/java/org/kframework/kore/compile/GenerateSentencesFromConfigDeclTest.java +++ b/kernel/src/test/java/org/kframework/kore/compile/GenerateSentencesFromConfigDeclTest.java @@ -87,7 +87,7 @@ public void testSingleTop() { Module m1 = Module("CONFIG", Set(Import(def.getModule("KSEQ").get(), true)), Set(prod), Att()); RuleGrammarGenerator parserGen = new RuleGrammarGenerator(def); Module m = - RuleGrammarGenerator.getCombinedGrammar(parserGen.getConfigGrammar(m1), true, files) + RuleGrammarGenerator.getCombinedGrammar(parserGen.getConfigGrammar(m1), files) .getExtensionModule(); Set gen = GenerateSentencesFromConfigDecl.gen(configuration, BooleanUtils.FALSE, Att(), m); diff --git a/kernel/src/test/java/org/kframework/parser/inner/RuleGrammarTest.java b/kernel/src/test/java/org/kframework/parser/inner/RuleGrammarTest.java index b7879671df8..56e627d121b 100644 --- a/kernel/src/test/java/org/kframework/parser/inner/RuleGrammarTest.java +++ b/kernel/src/test/java/org/kframework/parser/inner/RuleGrammarTest.java @@ -66,8 +66,7 @@ private void parseRule(String input, String def, int warnings, boolean expectedE Module test = ParserUtils.parseMainModuleOuterSyntax( def, Source.apply("generated by RuleGrammarTest"), "TEST"); - ParseInModule parser = - RuleGrammarGenerator.getCombinedGrammar(gen.getRuleGrammar(test), true, files); + ParseInModule parser = RuleGrammarGenerator.getCombinedGrammar(gen.getRuleGrammar(test), files); Tuple2, K>, Set> rule = parser.parseString(input, startSymbol, Source.apply("generated by RuleGrammarTest")); printout(rule, warnings, expectedError); @@ -77,8 +76,7 @@ private void parseRule(String input, String def, int warnings, K expectedResult) Module test = ParserUtils.parseMainModuleOuterSyntax( def, Source.apply("generated by RuleGrammarTest"), "TEST"); - ParseInModule parser = - RuleGrammarGenerator.getCombinedGrammar(gen.getRuleGrammar(test), true, files); + ParseInModule parser = RuleGrammarGenerator.getCombinedGrammar(gen.getRuleGrammar(test), files); Tuple2, K>, Set> rule = parser.parseString(input, startSymbol, Source.apply("generated by RuleGrammarTest")); printout(rule, warnings, false); @@ -90,7 +88,7 @@ private void parseConfig(String input, String def, int warnings, boolean expecte ParserUtils.parseMainModuleOuterSyntax( def, Source.apply("generated by RuleGrammarTest"), "TEST"); ParseInModule parser = - RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(test), true, files); + RuleGrammarGenerator.getCombinedGrammar(gen.getConfigGrammar(test), files); Tuple2, K>, Set> rule = parser.parseString(input, startSymbol, Source.apply("generated by RuleGrammarTest")); printout(rule, warnings, expectedError); @@ -102,7 +100,7 @@ private void parseProgram( ParserUtils.parseMainModuleOuterSyntax( def, Source.apply("generated by RuleGrammarTest"), "TEST"); ParseInModule parser = - RuleGrammarGenerator.getCombinedGrammar(gen.getProgramsGrammar(test), true, files); + RuleGrammarGenerator.getCombinedGrammar(gen.getProgramsGrammar(test), files); Tuple2, K>, Set> rule = parser.parseString(input, Sort(startSymbol), Source.apply("generated by RuleGrammarTest")); printout(rule, warnings, expectedError); @@ -114,7 +112,7 @@ private void parseProgram( ParserUtils.parseMainModuleOuterSyntax( def, Source.apply("generated by RuleGrammarTest"), "TEST"); ParseInModule parser = - RuleGrammarGenerator.getCombinedGrammar(gen.getProgramsGrammar(test), true, files); + RuleGrammarGenerator.getCombinedGrammar(gen.getProgramsGrammar(test), files); Tuple2, K>, Set> rule = parser.parseString(input, Sort(startSymbol), Source.apply("generated by RuleGrammarTest")); printout(rule, warnings, false); diff --git a/kernel/src/test/java/org/kframework/parser/inner/disambiguation/AddEmptyListsTest.java b/kernel/src/test/java/org/kframework/parser/inner/disambiguation/AddEmptyListsTest.java index 6769747df8b..3e801348cc0 100644 --- a/kernel/src/test/java/org/kframework/parser/inner/disambiguation/AddEmptyListsTest.java +++ b/kernel/src/test/java/org/kframework/parser/inner/disambiguation/AddEmptyListsTest.java @@ -43,7 +43,7 @@ public void setUp() throws Exception { Module test = ParserUtils.parseMainModuleOuterSyntax( DEF, Source.apply("AddEmptyListsTest test definition"), "TEST"); - parser = RuleGrammarGenerator.getCombinedGrammar(gen.getRuleGrammar(test), true, files); + parser = RuleGrammarGenerator.getCombinedGrammar(gen.getRuleGrammar(test), files); } /* @@ -82,7 +82,7 @@ private void parseTerm(String term, String sort, K expected, int expectWarnings) if (parseResult._1().isLeft()) { Assert.assertTrue("Unexpected parse errors" + parseResult._1().left().get(), false); } - K actual = new TreeNodesToKORE(Outer::parseSort, false).down(parseResult._1().right().get()); + K actual = new TreeNodesToKORE(Outer::parseSort).down(parseResult._1().right().get()); Assert.assertEquals(expected, actual); if (parseResult._2().size() != expectWarnings) { Assert.assertTrue("Unexpected parse warnings" + parseResult._2(), false); diff --git a/kernel/src/test/java/org/kframework/unparser/AddBracketsTest.java b/kernel/src/test/java/org/kframework/unparser/AddBracketsTest.java index 0a095e2c09d..c6ec2759914 100644 --- a/kernel/src/test/java/org/kframework/unparser/AddBracketsTest.java +++ b/kernel/src/test/java/org/kframework/unparser/AddBracketsTest.java @@ -99,7 +99,7 @@ public void testPriorityAndAssoc() { private void unparserTest(String def, String pgm) { Module test = parseModule(def); ParseInModule parser = - RuleGrammarGenerator.getCombinedGrammar(gen.getProgramsGrammar(test), true, files); + RuleGrammarGenerator.getCombinedGrammar(gen.getProgramsGrammar(test), files); K parsed = parseTerm(pgm, parser); KPrint kprint = new KPrint(); String unparsed = kprint.unparseTerm(parsed, test); @@ -110,6 +110,6 @@ private K parseTerm(String pgm, ParseInModule parser) { Tuple2, K>, Set> result = parser.parseString(pgm, Sorts.KItem(), Source.apply("generated by AddBracketsTest")); assertEquals(0, result._2().size()); - return new TreeNodesToKORE(Outer::parseSort, false).down(result._1().right().get()); + return new TreeNodesToKORE(Outer::parseSort).down(result._1().right().get()); } } diff --git a/kore/src/main/scala/org/kframework/parser/TreeNodesToKORE.scala b/kore/src/main/scala/org/kframework/parser/TreeNodesToKORE.scala index 48bd3cb74cd..e59c04ee5c6 100644 --- a/kore/src/main/scala/org/kframework/parser/TreeNodesToKORE.scala +++ b/kore/src/main/scala/org/kframework/parser/TreeNodesToKORE.scala @@ -4,20 +4,19 @@ package org.kframework.parser import java.util import java.util.Optional -import org.kframework.attributes.{Att,HasLocation,Location,Source} +import org.kframework.attributes.{Att, Location, Source} import org.kframework.builtin.Sorts -import org.kframework.definition.{NonTerminal, Production} +import org.kframework.definition.Production import org.kframework.{kore => k} import org.kframework.kore.Unapply._ -import org.kframework.kore.{KORE, _} +import org.kframework.kore._ import org.kframework.utils.errorsystem.KEMException -import org.pcollections.PStack import scala.collection.JavaConverters._ -class TreeNodesToKORE(parseSort: java.util.function.Function[String, Sort], strict: Boolean) { +class TreeNodesToKORE(parseSort: java.util.function.Function[String, Sort]) { - import org.kframework.kore.KORE.{KApply,KLabel,KList,KToken,KVariable,KSequence,KAs,KRewrite,InjectedKLabel} + import org.kframework.kore.KORE.{KApply, KLabel, KList, KToken, KVariable, KSequence, KAs, KRewrite, InjectedKLabel} def apply(t: Term): K = t match { case c@Constant(s, p) => KToken(s, p.sort, locationToAtt(c.location, c.source) diff --git a/kore/src/main/scala/org/kframework/parser/treeNodes.scala b/kore/src/main/scala/org/kframework/parser/treeNodes.scala index fdfece76097..df3346dc007 100644 --- a/kore/src/main/scala/org/kframework/parser/treeNodes.scala +++ b/kore/src/main/scala/org/kframework/parser/treeNodes.scala @@ -21,6 +21,7 @@ trait Term extends HasLocation { trait ProductionReference extends Term { val production: Production var id: Optional[Integer] = Optional.empty() + def setId(id: Optional[Integer]) { this.id = id } @@ -28,11 +29,13 @@ trait ProductionReference extends Term { trait HasChildren { def items: Iterable[Term] + def replaceChildren(newChildren: Collection[Term]): Term } case class Constant private(value: String, production: Production) extends ProductionReference { override def toString = "#token(" + production.sort + "," + StringUtil.enquoteKString(value) + ")" + override lazy val hashCode: Int = scala.runtime.ScalaRunTime._hashCode(Constant.this); } @@ -40,10 +43,12 @@ case class Constant private(value: String, production: Production) extends Produ case class TermCons private(items: PStack[Term], production: Production) extends ProductionReference with HasChildren { def get(i: Int) = items.get(items.size() - 1 - i) + def `with`(i: Int, e: Term) = TermCons(items.`with`(items.size() - 1 - i, e), production, location, source, id) def replaceChildren(newChildren: Collection[Term]) = TermCons(ConsPStack.from(newChildren), production, location, source, id) - override def toString() = new TreeNodesToKORE(s => Sort(s), false).apply(this).toString() + + override def toString() = new TreeNodesToKORE(s => Sort(s)).apply(this).toString() override lazy val hashCode: Int = scala.runtime.ScalaRunTime._hashCode(TermCons.this); } @@ -51,12 +56,14 @@ case class TermCons private(items: PStack[Term], production: Production) case class Ambiguity(items: Set[Term]) extends Term with HasChildren { def replaceChildren(newChildren: Collection[Term]) = Ambiguity(new HashSet[Term](newChildren), location, source) + override def toString() = "amb(" + (items.asScala mkString ",") + ")" + override lazy val hashCode: Int = scala.runtime.ScalaRunTime._hashCode(Ambiguity.this); } object Constant { - def apply(value: String, production: Production, location: Optional[Location], source: Optional[Source]):Constant = { + def apply(value: String, production: Production, location: Optional[Location], source: Optional[Source]): Constant = { val res = Constant(value, production) res.location = location res.source = source @@ -65,7 +72,7 @@ object Constant { } object TermCons { - def apply(items: PStack[Term], production: Production, location: Optional[Location], source: Optional[Source], id: Optional[Integer]):TermCons = { + def apply(items: PStack[Term], production: Production, location: Optional[Location], source: Optional[Source], id: Optional[Integer]): TermCons = { val res = TermCons(items, production) res.location = location res.source = source @@ -73,16 +80,17 @@ object TermCons { res } - def apply(items: PStack[Term], production: Production, location: Optional[Location], source: Optional[Source]):TermCons = { + def apply(items: PStack[Term], production: Production, location: Optional[Location], source: Optional[Source]): TermCons = { TermCons(items, production, location, source, Optional.empty()) } - def apply(items: PStack[Term], production: Production, location: Location, source: Source):TermCons = TermCons(items, production, Optional.of(location), Optional.of(source), Optional.empty()) + def apply(items: PStack[Term], production: Production, location: Location, source: Source): TermCons = TermCons(items, production, Optional.of(location), Optional.of(source), Optional.empty()) } object Ambiguity { @annotation.varargs def apply(items: Term*): Ambiguity = Ambiguity(items.to[mutable.Set].asJava) - def apply(items: Set[Term], location: Optional[Location], source: Optional[Source]):Ambiguity = { + + def apply(items: Set[Term], location: Optional[Location], source: Optional[Source]): Ambiguity = { val res = Ambiguity(items) res.location = location res.source = source