Skip to content

Commit bb0c539

Browse files
author
dwightguth
authored
Parsing and Scanning fixes (runtimeverification#780)
* hack to make cell names not collide with terminals * fix bug involving tags in syntax priorities
1 parent 5a87abb commit bb0c539

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

kernel/src/main/java/org/kframework/parser/concrete2kore/ParserUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ private String loadDefinitionText(File definitionFile) {
174174

175175
public Set<Module> loadModules(
176176
Set<Module> previousModules,
177+
Context context,
177178
String definitionText,
178179
Source source,
179180
File currentDirectory,
@@ -187,7 +188,6 @@ public Set<Module> loadModules(
187188
Definition def = new Definition();
188189
def.setItems((List<DefinitionItem>) (Object) kilModules);
189190

190-
Context context = new Context();
191191
new CollectProductionsVisitor(kore, context).visit(def);
192192

193193
KILtoKORE kilToKore = new KILtoKORE(context, false, kore);
@@ -207,7 +207,7 @@ public org.kframework.definition.Definition loadDefinition(
207207
File currentDirectory,
208208
List<File> lookupDirectories,
209209
boolean kore) {
210-
Set<Module> modules = loadModules(previousModules, definitionText, source, currentDirectory, lookupDirectories, new HashSet<>(), kore);
210+
Set<Module> modules = loadModules(previousModules, new Context(), definitionText, source, currentDirectory, lookupDirectories, new HashSet<>(), kore);
211211
Set<Module> allModules = new HashSet<>(modules);
212212
allModules.addAll(previousModules);
213213
Module mainModule = getMainModule(mainModuleName, allModules);
@@ -239,9 +239,10 @@ public org.kframework.definition.Definition loadDefinition(
239239
boolean kore) {
240240
Set<Module> previousModules = new HashSet<>();
241241
Set<File> requiredFiles = new HashSet<>();
242+
Context context = new Context();
242243
if (autoImportDomains)
243-
previousModules.addAll(loadModules(new HashSet<>(), Kompile.REQUIRE_PRELUDE_K, source, currentDirectory, lookupDirectories, requiredFiles, kore));
244-
Set<Module> modules = loadModules(previousModules, definitionText, source, currentDirectory, lookupDirectories, requiredFiles, kore);
244+
previousModules.addAll(loadModules(new HashSet<>(), context, Kompile.REQUIRE_PRELUDE_K, source, currentDirectory, lookupDirectories, requiredFiles, kore));
245+
Set<Module> modules = loadModules(previousModules, context, definitionText, source, currentDirectory, lookupDirectories, requiredFiles, kore);
245246
modules.addAll(previousModules); // add the previous modules, since load modules is not additive
246247
Module mainModule = getMainModule(mainModuleName, modules);
247248
Optional<Module> opt;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,17 @@ public static ParseInModule getCombinedGrammar(Module mod, boolean strict, boole
308308
}).collect(Collectors.toSet());
309309
} else if (addConfigCells) {
310310
// remove cells from parsing config cells so they don't conflict with the production in kast.k
311+
// also add all matching terminals to the #CellName sort
312+
for (Production prod : iterable(mod.productions())) {
313+
for (ProductionItem pi : iterable(prod.items())) {
314+
if (pi instanceof Terminal) {
315+
Terminal t = (Terminal)pi;
316+
if (t.value().matches("[A-Za-z][A-Za-z0-9\\-]*")) {
317+
prods.add(Production(Sorts.CellName(), Seq(t), Att().add("token")));
318+
}
319+
}
320+
}
321+
}
311322
parseProds = Stream.concat(prods.stream(), stream(mod.sentences()).filter(s -> !s.att().contains("cell"))).collect(Collectors.toSet());
312323
} else
313324
parseProds = Stream.concat(prods.stream(), stream(mod.sentences())).collect(Collectors.toSet());

kore/src/main/scala/org/kframework/builtin/Sorts.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ object Sorts {
3636

3737
val Bag = Sort("Bag")
3838
val Cell = Sort("Cell")
39+
val CellName = Sort("#CellName");
3940

4041
val GeneratedTopCell = Sort("GeneratedTopCell")
4142
val GeneratedCounterCell = Sort("GeneratedCounterCell")

ocaml-backend/src/main/java/org/kframework/backend/ocaml/DefinitionToOcaml.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.kframework.definition.Rule;
3535
import org.kframework.definition.Sentence;
3636
import org.kframework.kil.Attribute;
37+
import org.kframework.kil.loader.Context;
3738
import org.kframework.kompile.CompiledDefinition;
3839
import org.kframework.kompile.Kompile;
3940
import org.kframework.kompile.KompileOptions;
@@ -1093,6 +1094,7 @@ private void addOpaqueKLabels(Set<KLabel> klabels) {
10931094
lookupDirectories.add(Kompile.BUILTIN_DIRECTORY);
10941095
java.util.Set<Module> mods = new ParserUtils(files::resolveWorkingDirectory, kem, globalOptions).loadModules(
10951096
new HashSet<>(),
1097+
new Context(),
10961098
"require " + StringUtil.enquoteCString(definitionFile.getPath()),
10971099
Source.apply(definitionFile.getAbsolutePath()),
10981100
definitionFile.getParentFile(),

0 commit comments

Comments
 (0)