kevinushey / sourcetools

Tools for reading, tokenizing, and parsing R code.
MIT License
77 stars 3 forks source link

consider 'ParseNode' structure #4

Closed kevinushey closed 8 years ago

kevinushey commented 8 years ago

Currently, a parse tree is effectively just a tree arrangement of tokens -- however, this is a bit unwieldy for e.g. function definitions, since 'named' values are not expressed well.

E.g.

function(x, y = 1) {}

gives an R LANGSXP with structure:

[`function`, (x =, y = 1), {}]

whereas, for our parse tree, it would probably look like:

     function
    /        \
 (arglist)   expr
 /       \
x         y
|         |
<>        1

Is this sensible?

kevinushey commented 8 years ago

We're doing this now in the parse tree and it seems to work well.