@Override public Production shallowCopy() { return new Production(this); }
/** * Gets the KLabel corresponding to this production. A production has a * KLabel if and only if the production flattens in KORE to a term which is of sort * KItem (ie, is a function or a constructor). * @return */ public String getKLabel(boolean kore) { String klabel = getAttribute("klabel"); if (klabel == null && (isSyntacticSubsort() || containsAttribute("token") || containsAttribute("bracket"))) { return null; } else if (klabel == null || (kore && getAttribute("symbol") == null)) { klabel = getPrefixLabel(kore); } return klabel.replace(" ", ""); }
@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; }
/** * Returns the KLabel for the list terminator. * Constructed as '.List{"<list_klabel>"} * Should be called only if isListDecl is true. * @return String representation of the separator KLabel. */ public String getTerminatorKLabel(boolean kore) { assert isListDecl(); return ".List{" + StringUtil.enquoteCString(getKLabel(kore)) + "}" + (kore ? "_" + getSort().name() : ""); }
public void addProduction(Production p, boolean kore) { if (p.getKLabel(false) != null) { tags.put(p.getKLabel(false), p); } for (Attribute<?> a : p.getAttributes().values()) { tags.put(a.getKey().toString(), p); } } }
.getProductions().stream().filter(p -> p.getKLabel(kore) != null).map(p -> Tag(p.getKLabel(kore))) .collect(Collectors.toSet())); if (p.containsAttribute("reject")) // skip productions of the old reject type continue; if (p.getItems().size() == 1 && p.getItems().get(0) instanceof UserList) { applyUserList(res, sort, p, (UserList) p.getItems().get(0)); } else { List<ProductionItem> items = new ArrayList<>(); for (org.kframework.kil.ProductionItem it : p.getItems()) { if (it instanceof NonTerminal) { NonTerminal nt = (NonTerminal)it; } else if (it instanceof Lexical) { String regex; if (p.containsAttribute("regex")) regex = p.getAttribute("regex"); else regex = ((Lexical) it).getLexicalRule(); if (p.getKLabel(kore) == null) prod = Production( sort, else prod = Production( KLabel(p.getKLabel(kore)), sort,
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); } } } } } } } }
Production prod = new Production(new NonTerminal(Sort(""), Optional.empty()), items); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LSQUARE: if (klabel != null && prod.getAttribute("klabel") == null) { prod.addAttribute("klabel", klabel);
public void applyUserList(Set<org.kframework.definition.Sentence> res, org.kframework.kore.Sort sort, Production p, UserList userList) { // Transform list declarations of the form Es ::= List{E, ","} into something representable in kore org.kframework.kore.Sort elementSort = userList.getSort(); org.kframework.attributes.Att attrs = convertAttributes(p).add(Att.userList(), userList.getListType()); String kilProductionId = "" + System.identityHashCode(p); Att attrsWithKilProductionId = attrs.add(PRODUCTION_ID, kilProductionId); org.kframework.definition.Production prod1, prod3; // Es ::= E "," Es prod1 = Production(KLabel(p.getKLabel(kore)), sort, Seq(NonTerminal(elementSort), Terminal(userList.getSeparator()), NonTerminal(sort)), attrsWithKilProductionId.add("right")); // Es ::= ".Es" prod3 = Production(KLabel(p.getTerminatorKLabel(kore)), sort, Seq(Terminal("." + sort.toString())), attrsWithKilProductionId.remove("format").remove("strict").add("klabel", p.getTerminatorKLabel(false))); res.add(prod1); res.add(prod3); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((items == null) ? 0 : items.hashCode()); result = prime * result + ((getAttribute("klabel") == null) ? 0 : getAttribute("klabel").hashCode()); result = prime * result + ((sort == null) ? 0 : sort.hashCode()); result = prime * result + ((binderMap == null) ? 0 : binderMap.hashCode()); return result; }
public scala.collection.Set<Tag> toTags(List<Tag> labels, ASTNode loc) { return immutable(labels.stream().flatMap(l -> { java.util.Set<Production> productions = context.tags.get(l.name()); if (productions.isEmpty()) throw KEMException.outerParserError("Could not find any productions for tag: " + l.name(), loc.getSource(), loc.getLocation()); return productions.stream().map(p -> Tag(p.getKLabel(kore))); }).collect(Collectors.toSet())); }
@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()); } }
} else if (!items.equals(other.items)) return false; if (getAttribute("klabel") == null) { if (other.getAttribute("klabel") != null) return false; } else if (!getAttribute("klabel").equals(other.getAttribute("klabel"))) return false; if (sort == null) {
@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()); }