de.prob.prolog.match.PrologVariableMatch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of prologlib Show documentation
Show all versions of prologlib Show documentation
Part of the ProB Parser library
package de.prob.prolog.match;
import java.util.Map;
import de.prob.prolog.term.PrologTerm;
import de.prob.prolog.term.VariablePrologTerm;
/**
* Matches a Prolog variable.
*/
public class PrologVariableMatch extends PrologMatch {
private final String varName;
public static PrologVariableMatch anonVar(String varName) {
return namedVar(null, varName);
}
public static PrologVariableMatch anonVar() {
return namedVar(null, null);
}
public static PrologVariableMatch namedVar(String name, String varName) {
return new PrologVariableMatch(name, varName);
}
public static PrologVariableMatch namedVar(String name) {
return namedVar(name, null);
}
/**
* Matches on a Prolog variable with the given name
*
* @param name
* the name, if null
it will not be checked
*/
private PrologVariableMatch(final String name, final String varName) {
super(name);
this.varName = varName;
}
@Override
protected boolean isMatch(PrologTerm term, Map hits) {
boolean match = term instanceof VariablePrologTerm;
if (match && varName != null) {
match = varName.equals(((VariablePrologTerm) term).getName());
}
return match;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy