-
Notifications
You must be signed in to change notification settings - Fork 154
Rewriting Expressions
Dave DeLong edited this page Sep 19, 2015
·
3 revisions
Expression Rewriting is the ability for expressions like 3 * $a / $a
to be rewritten as 3
without ever knowing what the value of $a
is. (See more info about rewriting on Wikipedia)
ExpressionRewriter
has two methods related to expression rewriting:
rewriteExpression(expression: Expression, substitutions: Substitutions, evaluator: Evaluator) -> Expression
addRule(rule: RewriteRule)
The first method is the primary gateway. When handed an Expression
, it will analyze it and attempt to make as many changes to the expression as possible. It is conceivable that there may be rewriting rules that produce infinite loops, in which case ExpressionRewriter
will abort the writing after a finite number of attempts.
The second method allows you to define your own rewriting rules at runtime; it takes a [[RewriteRule
|Rewrite Rules]] value.