Skip to main content

rewrite

rewriteR Documentation

Interface for AST rewriting#

Description#

Interface for AST rewriting

Usage#

rewrite(ast, rules)

Arguments#

astA language object.
rulesA 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")
)
)