package org.matheclipse.core.patternmatching;
import java.util.List;
import org.matheclipse.core.interfaces.IExpr;
import com.google.common.base.Predicate;
/**
* Interface for the pattern matcher
*/
public abstract class IPatternMatcher implements Predicate, Cloneable {
/**
* Contains the "pattern-matching" expression
*
*/
protected IExpr fLhsPatternExpr;
protected IPatternMatcher() {
fLhsPatternExpr = null;
}
public IPatternMatcher(IExpr lhsPatternExpr) {
fLhsPatternExpr = lhsPatternExpr;
}
/**
* Get the "left-hand-side" of a pattern-matching rule.
*
* @return
*/
public IExpr getLHS() {
return fLhsPatternExpr;
}
/**
* Get the "right-hand-side" of a pattern-matching rule.
*
* @return null if no right-hand-side is defined for the pattern matcher
*/
public IExpr getRHS() {
return null;
}
/**
* Returns the matched pattern in the order they appear in the pattern expression.
*
*
* @param resultList
* a list instance
* @param patternExpr
* the expression which contains the pattern objects
*/
public abstract void getPatterns(List resultList, IExpr patternExpr);
/**
* Check if the pattern-matchings left-hand-side expression contains no patterns.
*
* @return true, if the given expression contains no patterns
*/
public abstract boolean isRuleWithoutPatterns();
/**
* Start pattern matching.
*
* @param expr
* @return true if the expr matches the pattern-matchings left-hand-side expression.
*/
public abstract boolean apply(IExpr expr);
/**
* Match the given left-hand-side and return an evaluated expression
*
* @param expr
* @return null if the match wasn't successful, the evaluated expression otherwise.
*/
public abstract IExpr eval(final IExpr expr);
@Override
public Object clone() throws CloneNotSupportedException {
IPatternMatcher v = (IPatternMatcher) super.clone();
v.fLhsPatternExpr = fLhsPatternExpr;
return v;
}
}
Ads help maintain this website.