private static VarKey getVarKey(Constant c) { if (c.value().equals(ResolveAnonVar.ANON_VAR.name())) { return new VarKey(c); // wildcard values are compared including location } else { return new VarKey(Constant.apply(c.value(), c.production(), Optional.empty(), Optional.empty())); } }
@Override public int hashCode() { return var.hashCode(); }
public Either<java.util.Set<ParseFailedException>, Term> apply(Constant c) { if (c.production().sort().equals(Sorts.KVariable())) { Sort declared = decl.get(getVarKey(c)); if (declared != null && !(declared.equals(Sorts.K()) && subsorts.lessThanEq(sort, Sorts.KList()))) { // if the declared/inferred sort is K, make sure it can fit in the context (ex. is not a KLabel) if ((!strictSortEquality && !subsorts.lessThanEq(declared, sort)) || (strictSortEquality && !declared.equals(sort))) { String msg = "Unexpected sort " + declared + " for term " + c.value() + ". Expected " + sort + "."; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, c.source().orElse(null), c.location().orElse(null)); return Left.apply(Sets.newHashSet(new VariableTypeClashException(kex))); } return wrapTermWithCast(c, declared); } } return Right.apply(c); }
private Optional<KLabel> klabelFromTerm(Term labelTerm) { if (labelTerm instanceof Constant) { Constant labelCon = (Constant) labelTerm; if (labelCon.production().sort().equals(Sorts.KLabel())) { String labelVal = labelCon.value(); if (labelVal.charAt(0) == '`') { return Optional.of(KLabel(labelVal.substring(1, labelVal.length() - 1))); } else { return Optional.of(KLabel(labelVal)); } } } return Optional.empty(); }
private Either<Set<ParseFailedException>, Term> wrapTermWithCast(Constant c, Sort declared) { Production cast; if (addCast) { cast = productions.apply(KLabel("#SemanticCastTo" + declared.toString())).head(); } else if (inferCasts && !hasCastAlready && productions.contains(KLabel("#SyntacticCast"))) { cast = stream(productions.apply(KLabel("#SyntacticCast"))).filter(p -> p.sort().equals(declared)).findAny().get(); } else { cast = null; } if (cast == null) { return Right.apply(c); } else { return Right.apply(TermCons.apply(ConsPStack.singleton(c), cast, c.location(), c.source())); } }
public Term apply(Constant c) { if (c.production().sort().equals(Sorts.KVariable()) && !declaredNames.contains(getVarKey(c))) { if (vars.isEmpty()) vars.add(HashMultimap.<VarKey, Sort>create()); for (Multimap<VarKey, Sort> vars2 : vars) vars2.put(getVarKey(c), sort); } return c; } }
public VarInfo(Constant varOcc, Sort sort, VarType varType) { this.varKey = getVarKey(varOcc); this.sort = sort; this.loc = varOcc.location().orElse(null); this.varType = varType; }
public boolean isAnyVar() { return var.value().equals(ResolveAnonVar.ANON_VAR.name()); } }
protected Term apply(KList klist, MetaData metaData) { Term term; Location loc = new Location(metaData.start.line, metaData.start.column, metaData.end.line, metaData.end.column); Source source = metaData.source; if (isToken) { String value = metaData.input.subSequence(metaData.start.position, metaData.end.position).toString(); term = Constant.apply(value, label, Optional.of(loc), Optional.of(source)); } else if (needsLabel) { term = TermCons.apply(klist.items(), label, loc, source); } else { return klist; } return term; } }
if (term instanceof Constant) { Constant c = (Constant) term; color(indenter, c.production(), 0, colorize); indenter.append(c.value()); resetColor(indenter, c.production(), colorize); } else if (term instanceof TermCons) { TermCons tc = (TermCons) term;
public Tuple2<Either<java.util.Set<ParseFailedException>, Term>, java.util.Set<VarInfo>> apply(Constant c) { if (c.production().sort().equals(Sorts.KVariable())) { return new Tuple2<>(Right.apply(c), Sets.newHashSet(new VarInfo(c, this.sort, varType))); } return simpleResult(c); } }