/** * Creates a {@link Selector} using the given parameters and sets type of * selector to {@link SelectorType#PARAMETERLIST} or * {@link SelectorType#VARIABLE} * * @param parameters * List of {@link Term}s. */ public Selector(List<Term> parameters, SourceInfo info) { super(info); this.parameters = parameters; if (parameters == null || parameters.isEmpty()) { throw new IllegalArgumentException("cannot have parameterlist selector with empty content"); } if (parameters.size() == 1 && parameters.get(0).isVar()) { this.type = SelectorType.VARIABLE; } else { this.type = SelectorType.PARAMETERLIST; } // cache this.free = new LinkedHashSet<>(); for (Term term : parameters) { this.free.addAll(term.getFreeVar()); } }
/** * Creates a new macro definition. * * @param name * The name/label of the macro * @param parameters * The parameters of the macro (can be the empty list but not null). * @param definition * The {@link MentalStateCondition} the macro is a shorthand for. If * null, this macro reference still needs to be resolved. Should only * be null for macro instances. * @param info * Source info about this object. */ public Macro(String name, List<Term> parameters, MentalStateCondition definition, SourceInfo info) { super(info); this.name = name; this.parameters = parameters; this.definition = definition; for (Term t : this.parameters) { this.free.addAll(t.getFreeVar()); if (t.isVar() && !t.isClosed()) { this.free.add((Var) t); } } }
if (term.isVar()) { boundedVars.add((Var) term);
/** * Delegate parsing of PARLIST terminal node to KR parser and checks whether * terms are variables. Reports an error if this is not the case. * * @param pars * String text from PARLIST terminal. * @param ctx * Parser context where PARLIST was found. * @return List of terms. */ public List<Var> visitVARLIST(TerminalNode parlist, ParserRuleContext ctx) { List<Term> parameters = visitPARLIST(parlist, getSourceInfo(ctx)); List<Var> vars = new LinkedList<>(); for (Term term : parameters) { if (!term.isVar()) { reportError(SyntaxError.PARAMETER_NOT_A_VARIABLE, getSourceInfo(ctx), getTheErrorStrategy().prettyPrintRuleContext(ctx.getRuleIndex()), term.toString()); } else { vars.add((Var) term); } } return vars; }