esprima | R Documentation |
Esprima is a high performance, standard-compliant ECMAScript parser. It has full support for ECMAScript 2017 and returns a sensible syntax tree format as standardized by ESTree project.
esprima_tokenize(text, range = FALSE, loc = FALSE, comment = FALSE)
esprima_parse(text, jsx = FALSE, range = FALSE, loc = FALSE,
tolerant = FALSE, tokens = FALSE, comment = FALSE)
text |
a character vector with JavaScript code |
range |
Annotate each token with its zero-based start and end location |
loc |
Annotate each token with its column and row-based location |
comment |
Include every line and block comment in the output |
jsx |
Support JSX syntax |
tolerant |
Tolerate a few cases of syntax errors |
tokens |
Collect every token |
The esprima_tokenize
function returns a data frame with JavaScript tokens. The
esprima_parse
function returns the Syntax Tree in JSON format. This can be parsed to R
using e.g. jsonlite::fromJSON
.
Esprima documentation: http://esprima.readthedocs.io/en/4.0/.
code <- "function test(x, y){ x = x || 1; y = y || 1; return x*y;}"
esprima_tokenize(code)
esprima_parse(code)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.