public void visit(Syntax syntax) { this.sort = syntax.getDeclaredSort().getRealSort(); syntax.getPriorityBlocks().forEach(pb -> pb.getProductions().forEach(this::visit)); }
@Override public PriorityBlock shallowCopy() { return new PriorityBlock(this); }
@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; }
.getProductions().stream().filter(p -> p.getKLabel(kore) != null).map(p -> Tag(p.getKLabel(kore))) .collect(Collectors.toSet())); if (!b.getAssoc().equals("")) { Value assoc = applyAssoc(b.getAssoc()); res.add(SyntaxAssociativity(assoc, applyToTags.apply(b))); for (Production p : b.getProductions()) { if (p.containsAttribute("reject")) // skip productions of the old reject type continue;
@Override public int hashCode() { int hash = sort.hashCode(); for (PriorityBlock pb : priorityBlocks) hash += pb.hashCode(); return hash; }
@Override public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (!(obj instanceof PriorityBlock)) return false; PriorityBlock pb = (PriorityBlock) obj; if (!pb.getAssoc().equals(this.assoc)) return false; if (pb.productions.size() != productions.size()) return false; for (int i = 0; i < pb.productions.size(); i++) { if (!pb.productions.get(i).equals(productions.get(i))) return false; } return true; }
@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()); }
Production(prods); pblocks.add(markLoc(loc, new PriorityBlock(assoc, prods)));
@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); } } } } } } } }