[][src]Trait libslide::grammar::transformer::Transformer

pub trait Transformer<T: Grammar, U: Grammar> {
    fn transform(&self, item: T) -> U;
}

A trait for transforming one grammar into another. This transformer takes ownership of the grammar it transforms.

Required methods

fn transform(&self, item: T) -> U

Loading content...

Implementors

impl Transformer<RcExprPat, RcExprPat> for Rule[src]

fn transform(&self, target: RcExprPat) -> RcExprPat[src]

Bootstraps a rule with another (or possibly the same) rule.

impl Transformer<RcExprPat, RcExprPat> for PatternMatch<RcExprPat>[src]

impl Transformer<RcExprPat, RcExpr> for PatternMatch<RcExpr>[src]

fn transform(&self, item: RcExprPat) -> RcExpr[src]

Transforms a pattern expression into an expression by replacing patterns with target expressions known by the PatternMatch.

This transformation can be used to apply a rule on an expression by transforming the RHS using patterns matched between the LHS of the rule and the target expression.

impl Transformer<RcExpr, RcExpr> for Rule[src]

fn transform(&self, target: RcExpr) -> RcExpr[src]

Attempts to apply a rule on a target expression by

  1. Applying the rule recursively on the target's subexpression to obtain a partially-transformed target expression.

  2. Pattern matching the lhs of the rule with the partially-transformed target expression.

  • If pattern matching is unsuccessful, no application is done and the original expression is returned.
  1. Expanding the rhs of the rule using the results of the pattern matching.

Examples:

This example is not tested
"$x + 0 -> $x".try_apply("x + 0")  // Some(x)
"$x + 0 -> $x".try_apply("x + 1")  // None
"$x + 0 -> $x".try_apply("x")      // None
Loading content...