rewrite: Interface for AST rewriting

View source: R/core-rewrite.R

rewriteR Documentation

Interface for AST rewriting

Description

Interface for AST rewriting

Usage

rewrite(ast, rules)

Arguments

ast

A language object.

rules

A list of functions, each of which is the output from 'make_rule'.

Value

A language object.

Examples

library(sketch)

rewrite(
  ast = rlang::parse_expr("2 * (3 + pi)"),
  rules = list(make_rule("pi", "Math.PI"))
)

rewrite(
  ast = rlang::parse_expr("2 + pi"),
  rules = list(
    make_rule("pi", "Math.PI"),
    make_rule("+", "Math.add")
  )
)


sketch documentation built on May 29, 2024, 8:18 a.m.