new Rule(pattern, result, options, nameopt)
Simplification rule.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pattern |
JME | Expression pattern to match. Variables will match any sub-expression. |
|
result |
JME | Expression pattern to rewrite to. |
|
options |
string | Numbas.jme.rules.matchTree_options | ||
name |
string |
<optional> |
A human-readable name for the rule |
Properties:
Name | Type | Description |
---|---|---|
patternString |
JME | The JME string defining the pattern to match. |
resultString |
JME | The JME string defining the result of the rule. |
options |
Numbas.jme.rules.matchTree_options | Default options for the match algorithm. |
conditionStrings |
JME | JME strings defining the conditions. |
patternTree |
Numbas.jme.tree |
|
result |
Numbas.jme.tree | The parameter |
conditions |
Array.<Numbas.jme.tree> | The parameter |
Methods
get_options(options) → {Numbas.jme.rules.matchTree_options}
Extend this rule's default options with the given options.
Parameters:
Name | Type | Description |
---|---|---|
options |
Numbas.jme.rules.matchTree_options |
Returns:
Type | Description |
---|---|
Numbas.jme.rules.matchTree_options |
match(exprTree, scope) → {boolean|Numbas.jme.rules.jme_pattern_match}
Match a rule on given syntax tree.
Parameters:
Name | Type | Description |
---|---|---|
exprTree |
Numbas.jme.tree | The syntax tree to test. |
scope |
Numbas.jme.Scope | Used when checking conditions. |
Returns:
Type | Description |
---|---|
boolean | Numbas.jme.rules.jme_pattern_match |
|
matchAll(exprTree, scope) → {Array.<Numbas.jme.rules.jme_pattern_match>}
Find all matches for the rule, anywhere within the given expression.
Parameters:
Name | Type | Description |
---|---|---|
exprTree |
Numbas.jme.tree | The syntax tree to test. |
scope |
Numbas.jme.Scope | Used when checking conditions. |
Returns:
Type | Description |
---|---|
Array.<Numbas.jme.rules.jme_pattern_match> |
replace(exprTree, scope) → {Numbas.jme.rules.transform_result}
Transform the given expression if it matches this rule's pattern.
Parameters:
Name | Type | Description |
---|---|---|
exprTree |
Numbas.jme.tree | The syntax tree to transform. |
scope |
Numbas.jme.Scope | Used when checking conditions. |
Returns:
Type | Description |
---|---|
Numbas.jme.rules.transform_result |
replaceAll(exprTree, scope) → {Numbas.jme.rules.transform_result}
Transform all occurences of this rule's pattern in the given expression.
Parameters:
Name | Type | Description |
---|---|---|
exprTree |
Numbas.jme.tree | The syntax tree to transform. |
scope |
Numbas.jme.Scope | Used when checking conditions. |
Returns:
Type | Description |
---|---|
Numbas.jme.rules.transform_result |