public Either<java.util.Set<ParseFailedException>, Term> apply(TermCons tc) { if (tc.production().klabel().isDefined() && tc.production().klabel().get().name().equals("#KRewrite")) { String msg = "Rewrite is not allowed to be an immediate child of " + parent.production().klabel().get() + " Use parentheses: (x)=>(y) to set the proper scope of the operations."; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, tc.source().get(), tc.location().get()); return Left.apply(Sets.newHashSet(new PriorityException(kex))); } return Right.apply(tc); } }
public Either<java.util.Set<ParseFailedException>, Term> apply(TermCons tc) { if (tc.production().klabel().isDefined() && tc.production().klabel().get().name().equals("#KSequence")) { String msg = "~> is not allowed to be an immediate child of " + parent.production().klabel().get() + " Use parentheses: (x)~>(y) to set the proper scope of the operations."; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, tc.source().get(), tc.location().get()); return Left.apply(Sets.newHashSet(new PriorityException(kex))); } return Right.apply(tc); } }
public Either<java.util.Set<ParseFailedException>, Term> apply(TermCons tc) { if (tc.production().items().apply(tc.production().items().size() - 1) instanceof NonTerminal) { String msg = parent.production().klabel().get() + " is not allowed to be an immediate child of cast." + " Use parentheses: (x):Sort to set the proper scope of the operations."; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, tc.source().get(), tc.location().get()); return Left.apply(Sets.newHashSet(new PriorityException(kex))); } return Right.apply(tc); } }
public Either<java.util.Set<ParseFailedException>, Term> apply(TermCons tc) { if (tc.production().att().contains("bracket")) return Right.apply(tc); //if (Side.RIGHT == side && !(tc.production().items().apply(0) instanceof NonTerminal)) return Right.apply(tc); //if (Side.LEFT == side && !(tc.production().items().apply(tc.production().items().size() - 1) instanceof NonTerminal)) return Right.apply(tc); Tag parentLabel = new Tag(parent.production().klabel().get().name()); Tag localLabel = new Tag(tc.production().klabel().get().name()); if (priorities.lessThan(parentLabel, localLabel)) { String msg = "Priority filter exception. Cannot use " + localLabel + " as a child of " + parentLabel; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, tc.source().get(), tc.location().get()); return Left.apply(Sets.newHashSet(new PriorityException(kex))); } if (leftAssoc.contains(new Tuple2<>(parentLabel, localLabel)) && Side.RIGHT == side) { String msg = "Associativity filter exception. Cannot use " + localLabel + " as a right child of " + parentLabel; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, tc.source().get(), tc.location().get()); return Left.apply(Sets.newHashSet(new PriorityException(kex))); } if (rigthAssoc.contains(new Tuple2<>(parentLabel, localLabel)) && Side.LEFT == side) { String msg = "Associativity filter exception. Cannot use " + localLabel + " as a left child of " + parentLabel; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, tc.source().get(), tc.location().get()); return Left.apply(Sets.newHashSet(new PriorityException(kex))); } return Right.apply(tc); } }
@Override public Either<Set<ParseFailedException>, Term> apply(TermCons tc) { if (overloads.elements().contains(tc.production()) && tc.items().isEmpty()) { Set<Production> candidates = stream(overloads.elements()).filter(p -> p.klabel().isDefined() && p.klabelAtt().equals(tc.production().klabelAtt()) && overloads.lessThanEq(p, tc.production())).collect(Collectors.toSet()); candidates = overloads.minimal(candidates); if (candidates.size() != 1) { KException ex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.INNER_PARSER, "Overloaded term does not have a least sort. Possible sorts: " + candidates, tc.source().orElse(null), tc.location().orElse(null)); return Left.apply(Sets.newHashSet(new ParseFailedException(ex))); } Production prod = candidates.iterator().next(); prod = Production(prod.klabel(), prod.sort(), prod.items(), prod.att().add("originalPrd", Production.class, tc.production())); return super.apply(TermCons.apply(tc.items(), prod, tc.location(), tc.source())); } return super.apply(tc); } }
Set<Sort> least = subsorts.minimal(stream(listSorts).filter(s -> subsorts.greaterThanEq(lists.get(s).get(0).childSort, childSort) && subsorts.lessThanEq(s, expectedSort)).collect(Collectors.toList())); if (least.size() != 1) { KException ex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.INNER_PARSER, "Overloaded term does not have a least sort. Possible sorts: " + least, tc.source().orElse(null), tc.location().orElse(null)); return new Tuple2<>(Left.apply(Sets.newHashSet(new ParseFailedException(ex))), warnings); Set<Sort> leastTerm = subsorts.minimal(stream(listSorts).filter(s -> subsorts.lessThanEq(s, expectedSort)).collect(Collectors.toList())); if (leastTerm.size() != 1) { KException ex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.INNER_PARSER, "List terminator for overloaded term does not have a least sort. Possible sorts: " + leastTerm, tc.source().orElse(null), tc.location().orElse(null)); return new Tuple2<>(Left.apply(Sets.newHashSet(new ParseFailedException(ex))), warnings); tc = TermCons.apply(ConsPStack.from(newItems), tc.production(), tc.location(), tc.source());
@Override public Either<Set<ParseFailedException>, Term> apply(TermCons tc) { Either<Set<ParseFailedException>, Term> vis; if (tc.production().isSyntacticSubsort() && tc.production().klabel().isEmpty()) { // eliminating syntactic subsort vis = apply(tc.get(0)); } else if (!tc.production().att().contains("bracket") && tc.production().klabel().isEmpty()) { return Left.apply(Sets.newHashSet(new ParseFailedException(new KException( KException.ExceptionType.ERROR, KException.KExceptionGroup.INNER_PARSER, "Only subsort productions are allowed to have no #klabel attribute", tc.source().get(), tc.location().get())))); } else { // invalidate the hashCode cache vis = super.apply(tc); } return vis; }