public class PatternMatcher extends IPatternMatcher implements java.io.Externalizable
Modifier and Type | Class and Description |
---|---|
class |
PatternMatcher.OrderlessMatcher
Matches an
IAST with header attribute Orderless
. |
protected class |
PatternMatcher.StackMatcher
Manage a stack of pairs of expressions, which have to match each other
|
Modifier and Type | Field and Description |
---|---|
protected IExpr |
fPatternCondition
Additional condition for pattern-matching maybe
null |
protected PatternMap |
fPatternMap
A map from a pattern to a possibly found value during pattern-matching.
|
protected int |
fPriority
priority of this matcher
|
fLhsPatternExpr
Constructor and Description |
---|
PatternMatcher()
Needed for serialization
|
PatternMatcher(IExpr patternExpr) |
Modifier and Type | Method and Description |
---|---|
boolean |
checkCondition()
Check if the condition for this pattern matcher evaluates to
true . |
boolean |
checkRHSCondition(EvalEngine engine)
Check if the condition for the right-hand-sides
Module[] or Condition[] expressions evaluates to
true . |
java.lang.Object |
clone() |
int |
compareTo(IPatternMatcher o) |
boolean |
equals(java.lang.Object obj) |
static boolean |
equivalent(IExpr patternExpr1,
IExpr patternExpr2,
PatternMap pm1,
PatternMap pm2)
Check if the two left-hand-side pattern expressions are equivalent.
|
int |
equivalent(IPatternMatcher obj) |
IExpr |
eval(IExpr leftHandSide)
Match the given left-hand-side and return an evaluated expression
|
protected IExpr |
evalAST(IAST lhsPatternAST,
IAST lhsEvalAST,
IExpr rhsExpr,
PatternMatcher.StackMatcher stackMatcher) |
static IExpr |
evalLeftHandSide(IAST leftHandSide) |
static IExpr |
evalLeftHandSide(IAST leftHandSide,
EvalEngine engine)
Transform the ast recursively, according to the attributes Flat, HoldAll,
HoldFirst, HoldRest, Orderless for the left-hand-side of a Set[] or
SetDelayed[] expression.
|
IExpr |
getCondition()
Get the additional condition for pattern-matching
|
void |
getPatterns(java.util.List<IExpr> resultList,
IExpr pExpr)
Returns the matched pattern in the order they appear in the pExpr
|
protected IExpr |
getPatternValue0()
Return the matched value for index 0 if possisble.
|
int |
getPriority()
Get the priority of this pattern-matcher.
|
int |
hashCode() |
protected void |
init(IExpr patternExpr) |
boolean |
isRuleWithoutPatterns()
Returns true if the given expression contains no patterns
|
protected void |
logConditionFalse(IExpr lhsEvalAST,
IExpr lhsPatternAST,
IExpr rhsAST) |
protected boolean |
matchAST(IAST lhsPatternAST,
IExpr lhsEvalExpr,
PatternMatcher.StackMatcher stackMatcher) |
protected boolean |
matchExpr(IExpr lhsPatternExpr,
IExpr lhsEvalExpr)
Checks if the two expressions match each other
|
protected boolean |
matchExpr(IExpr lhsPatternExpr,
IExpr lhsEvalExpr,
PatternMatcher.StackMatcher stackMatcher)
Checks if the two expressions match each other
|
void |
readExternal(java.io.ObjectInput objectInput) |
void |
setCondition(IExpr condition)
Sets an additional evaluation-condition for pattern-matching
|
boolean |
test(IExpr leftHandSide)
Start pattern matching.
|
void |
writeExternal(java.io.ObjectOutput objectOutput) |
getLHS, getRHS
protected transient int fPriority
protected IExpr fPatternCondition
null
protected transient PatternMap fPatternMap
null
if the left-hand-side pattern expression
contains no pattern.public PatternMatcher()
patternExpr
- public PatternMatcher(IExpr patternExpr)
protected final void init(IExpr patternExpr)
public boolean checkRHSCondition(EvalEngine engine)
Module[] or Condition[]
expressions evaluates to
true
. Override it in subclasses.true
PatternMatcherAndEvaluator.checkRHSCondition(EvalEngine)
public boolean checkCondition()
true
.public static boolean equivalent(IExpr patternExpr1, IExpr patternExpr2, PatternMap pm1, PatternMap pm2)
f[x_,y_]
is equivalent to f[a_,b_]
)patternExpr1
- patternExpr2
- pm1
- pm2
- public void getPatterns(java.util.List<IExpr> resultList, IExpr pExpr)
getPatterns
in class IPatternMatcher
resultList
- pExpr
- protected IExpr getPatternValue0()
null
if no matched expression existspublic int getPriority()
getPriority
in class IPatternMatcher
public final boolean isRuleWithoutPatterns()
isRuleWithoutPatterns
in class IPatternMatcher
public boolean test(IExpr leftHandSide)
IPatternMatcher
test
in interface java.util.function.Predicate<IExpr>
test
in class IPatternMatcher
true
if the expr
matches the
pattern-matchings left-hand-side expression.protected boolean matchExpr(IExpr lhsPatternExpr, IExpr lhsEvalExpr)
protected boolean matchExpr(IExpr lhsPatternExpr, IExpr lhsEvalExpr, PatternMatcher.StackMatcher stackMatcher)
protected boolean matchAST(IAST lhsPatternAST, IExpr lhsEvalExpr, PatternMatcher.StackMatcher stackMatcher)
protected IExpr evalAST(IAST lhsPatternAST, IAST lhsEvalAST, IExpr rhsExpr, PatternMatcher.StackMatcher stackMatcher)
lhsPatternAST
- lhsEvalAST
- rhsExpr
- stackMatcher
- F.NIL
if no match was found.protected void logConditionFalse(IExpr lhsEvalAST, IExpr lhsPatternAST, IExpr rhsAST)
public IExpr eval(IExpr leftHandSide)
eval
in class IPatternMatcher
leftHandSide
- left-hand-side expressionF.NIL
if the match wasn't successful, the evaluated
expression otherwise.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class IPatternMatcher
java.lang.CloneNotSupportedException
public IExpr getCondition()
public void setCondition(IExpr condition)
public static IExpr evalLeftHandSide(IAST leftHandSide, EvalEngine engine)
EvalEngine#evalSetAttributes()
methodast
- F.NIL
if evaluation is not possibleorg.matheclipse.core.eval.EvalEngine#evalSetAttributes()
public int compareTo(IPatternMatcher o)
compareTo
in interface java.lang.Comparable<IPatternMatcher>
public int equivalent(IPatternMatcher obj)
public void writeExternal(java.io.ObjectOutput objectOutput) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
public void readExternal(java.io.ObjectInput objectInput) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
java.lang.ClassNotFoundException