Jump to navigation

Class: Rule

Numbas.jme.rules.Rule

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

patternString compiled to a syntax tree

result Numbas.jme.tree

result compiled to a syntax tree

conditions Array.<Numbas.jme.tree>

conditions compiled to syntax trees

Source:

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
Source:

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
  • false if no match, or a dictionary of matched subtrees
Source:
See:

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>
Source:
See:

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
Source:
See:

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
Source:
See: