match_expr: Produce an ast or parse graph of an expression

Description Usage Arguments Value Examples

View source: R/straw.R

Description

Produce an ast or parse graph of an expression

Usage

1
match_expr(g_parse, g_ast, parse_node, ast_node)

Arguments

g_parse

Parse graph generated by create_parse_graph

g_ast

AST graph generated by create_parse_graph

parse_node

node from g_parse to search from

ast_node

node from g_ast to search from

Value

A data.frame linking the graphs with columns parse_id, ast_id

Examples

1
2
3
4
5
6
7
8
exp <- parse(text = "if (x) 2 else a$'b'")
g <- create_parse_graph(parse(text = "if (x) 2 else a$'b'"))
plot(g, layout = layout.reingold.tilford)

g_ast <- create_parse_graph(exp, type = "ast")
plot(g_ast, layout = layout.reingold.tilford)

match_expr(g, g_ast, g[2,], g_ast[2,])

machow/straw documentation built on Sept. 9, 2020, 12:40 a.m.