Convert a R parsed expression to a GeneralTree.

Usage

# S3 method for expression
as.GeneralTree(x, ...)

Arguments

x
The expression that should be converted.
...
what = "token" fill the tree with tokens as the data field. what = "text" fill the tree with text as the data field.

Description

Convert a R parsed expression to a GeneralTree.

Examples

p <- parse(text = " tree <- GeneralTree$new(1, 'parent1') tree$addNode(1, 2, 'child.1.2') tree$addNode(2, 3, 'child.2.3')", keep.source = TRUE) as.GeneralTree(p, what = "token")
0 : BaseEnvironment --> 24 : expr --> 5 : expr --> 3 : SYMBOL | |-> 4 : LEFT_ASSIGN | \-> 22 : expr --> 10 : expr --> 8 : expr --> 6 : SYMBOL | | |-> 7 : '$' | | \-> 9 : SYMBOL_FUNCTION_CALL | |-> 11 : '(' | |-> 13 : expr --> 12 : NUM_CONST | |-> 14 : ',' | |-> 19 : expr --> 17 : STR_CONST | \-> 18 : ')' |-> 48 : expr --> 31 : expr --> 29 : expr --> 27 : SYMBOL | | |-> 28 : '$' | | \-> 30 : SYMBOL_FUNCTION_CALL | |-> 32 : '(' | |-> 34 : expr --> 33 : NUM_CONST | |-> 35 : ',' | |-> 39 : expr --> 38 : NUM_CONST | |-> 40 : ',' | |-> 45 : expr --> 43 : STR_CONST | \-> 44 : ')' \-> 73 : expr --> 56 : expr --> 54 : expr --> 52 : SYMBOL | |-> 53 : '$' | \-> 55 : SYMBOL_FUNCTION_CALL |-> 57 : '(' |-> 59 : expr --> 58 : NUM_CONST |-> 60 : ',' |-> 64 : expr --> 63 : NUM_CONST |-> 65 : ',' |-> 70 : expr --> 68 : STR_CONST \-> 69 : ')'
as.GeneralTree(p, what = "text")
0 : BaseEnvironment --> 24 : --> 5 : --> 3 : tree | |-> 4 : <- | \-> 22 : --> 10 : --> 8 : --> 6 : GeneralTree | | |-> 7 : $ | | \-> 9 : new | |-> 11 : ( | |-> 13 : --> 12 : 1 | |-> 14 : , | |-> 19 : --> 17 : 'parent1' | \-> 18 : ) |-> 48 : --> 31 : --> 29 : --> 27 : tree | | |-> 28 : $ | | \-> 30 : addNode | |-> 32 : ( | |-> 34 : --> 33 : 1 | |-> 35 : , | |-> 39 : --> 38 : 2 | |-> 40 : , | |-> 45 : --> 43 : 'child.1.2' | \-> 44 : ) \-> 73 : --> 56 : --> 54 : --> 52 : tree | |-> 53 : $ | \-> 55 : addNode |-> 57 : ( |-> 59 : --> 58 : 2 |-> 60 : , |-> 64 : --> 63 : 3 |-> 65 : , |-> 70 : --> 68 : 'child.2.3' \-> 69 : )
as.GeneralTree(p, what = c("text", "token"))
0 : BaseEnvironment --> 24 : expr: --> 5 : expr: --> 3 : SYMBOL: tree | |-> 4 : LEFT_ASSIGN: <- | \-> 22 : expr: --> 10 : expr: --> 8 : expr: --> 6 : SYMBOL: GeneralTree | | |-> 7 : '$': $ | | \-> 9 : SYMBOL_FUNCTION_CALL: new | |-> 11 : '(': ( | |-> 13 : expr: --> 12 : NUM_CONST: 1 | |-> 14 : ',': , | |-> 19 : expr: --> 17 : STR_CONST: 'parent1' | \-> 18 : ')': ) |-> 48 : expr: --> 31 : expr: --> 29 : expr: --> 27 : SYMBOL: tree | | |-> 28 : '$': $ | | \-> 30 : SYMBOL_FUNCTION_CALL: addNode | |-> 32 : '(': ( | |-> 34 : expr: --> 33 : NUM_CONST: 1 | |-> 35 : ',': , | |-> 39 : expr: --> 38 : NUM_CONST: 2 | |-> 40 : ',': , | |-> 45 : expr: --> 43 : STR_CONST: 'child.1.2' | \-> 44 : ')': ) \-> 73 : expr: --> 56 : expr: --> 54 : expr: --> 52 : SYMBOL: tree | |-> 53 : '$': $ | \-> 55 : SYMBOL_FUNCTION_CALL: addNode |-> 57 : '(': ( |-> 59 : expr: --> 58 : NUM_CONST: 2 |-> 60 : ',': , |-> 64 : expr: --> 63 : NUM_CONST: 3 |-> 65 : ',': , |-> 70 : expr: --> 68 : STR_CONST: 'child.2.3' \-> 69 : ')': )