public void visit(Syntax syntax) { this.sort = syntax.getDeclaredSort().getRealSort(); syntax.getPriorityBlocks().forEach(pb -> pb.getProductions().forEach(this::visit)); }
@Override public Syntax shallowCopy() { return new Syntax(this); } }
@Test public void testLexicalRules() throws Exception { // TODO: remove once the new parser is fully functional String def = "module TEST syntax Str ::= Token{((~[\\'\\n\\r\\\\])|([\\\\]~[\\n\\r]))*} endmodule"; List<DefinitionItem> defItemList = Outer.parse(Source.apply("generated by OuterParsingTests"), def, null); Module mod = (Module) defItemList.get(0); Syntax syn = (Syntax) mod.getItems().get(0); Lexical lex = (Lexical) syn.getPriorityBlocks().get(0).getProductions().get(0).getItems().get(0); Assert.assertEquals("((~[\\'\\n\\r\\\\])|([\\\\]~[\\n\\r]))*", lex.getLexicalRule()); }
case LOWER_ID: nonTerminal = SortID(); Syntax syn = new Syntax(nonTerminal); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LSQUARE: PriorityBlock(pblocks); syn.setPriorityBlocks(pblocks); break; case LSQUARE:
@Override public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (!(obj instanceof Syntax)) return false; Syntax syn = (Syntax) obj; if (!syn.getDeclaredSort().equals(this.sort)) return false; if (syn.priorityBlocks.size() != priorityBlocks.size()) return false; for (int i = 0; i < syn.priorityBlocks.size(); i++) { if (!syn.priorityBlocks.get(i).equals(priorityBlocks.get(i))) return false; } return true; }
@Test public void testLexicalRules2() throws Exception { // TODO: remove once the new parser is fully functional String def = "module TEST syntax Str ::= Token{{[a]|[b] \".\"}+NT~[x]*} endmodule"; List<DefinitionItem> defItemList = Outer.parse(Source.apply("generated by OuterParsingTests"), def, null); Module mod = (Module) defItemList.get(0); Syntax syn = (Syntax) mod.getItems().get(0); Lexical lex = (Lexical) syn.getPriorityBlocks().get(0).getProductions().get(0).getItems().get(0); Assert.assertEquals("{[a]|[b] \".\"}+NTDz~[x]*", lex.getLexicalRule()); } }
private static void check(ModuleItem i) { if (i instanceof Syntax) { Syntax s = (Syntax) i; for (PriorityBlock b : s.getPriorityBlocks()) { for (Production p : b.getProductions()) { if (p.getItems().size() == 1 && p.getItems().get(0) instanceof UserList) { // Syntax Es ::= List{E,""} Sort listSort = s.getDeclaredSort().getSort(); // Es Sort elemSort = ((UserList) p.getItems().get(0)).getSort(); // E if (isBaseSort(listSort)) { throw KEMException.compilerError(listSort + " can not be extended to be a list sort.", p); } if (listSort.equals(elemSort)) { throw KEMException.compilerError("Circular lists are not allowed.", p); } } else { for (ProductionItem it : p.getItems()) { if (it instanceof UserList) { // Syntax Es ::= ... List{E,""} ... throw KEMException.compilerError("Inline list declarations are not allowed.", it); } } } } } } } }
public Set<org.kframework.definition.Sentence> apply(Syntax s) { Set<org.kframework.definition.Sentence> res = new HashSet<>(); org.kframework.kore.Sort sort = s.getDeclaredSort().getSort(); if (s.getPriorityBlocks().size() == 0) { res.add(SyntaxSort(sort, convertAttributes(s))); return res; .collect(Collectors.toSet())); if (s.getPriorityBlocks().size() > 1) { res.add(SyntaxPriority(immutable(s.getPriorityBlocks().stream().map(applyToTags) .collect(Collectors.toList())))); for (PriorityBlock b : s.getPriorityBlocks()) { if (!b.getAssoc().equals("")) { Value assoc = applyAssoc(b.getAssoc());