parser: Detailed R code parser

Description Usage Arguments Value Note Author(s) References See Also Examples

View source: R/parser.R

Description

This is a parser for R code using the same grammar as the usual parser (parse) but structuring the information differently.

Usage

1
parser(file, encoding = "unknown", text)

Arguments

file

Source file to parse

encoding

Encoding for the file

text

If text is given, then its content is sent to a temporary file, which is then used as the file argument.

Value

The output is a list of expressions similar to the output of parse except that expressions are not associated with an inline srcref information. Instead, each expression has an id attribute that refers to the data.

The data attribute is a data frame with the following columns:

line1,col1,byte1

First line, column, and byte of the symbol (token or expression)

line2,col2,byte2

Last line, column, and byte of the symbol (token or expression)

token

Token type.

id

Unique identifier given to this token or expression

parent

identifier for the expression that contains this token or expression

token.desc

A description of this token type. This is read from the output generated by bison

Note

The location information is different to that of R's parse function, parse structures columns and bytes information to comply with the substring function whereas this function returns the information as an offset to the start of the line.

Author(s)

Romain Francois <romain@r-enthusiasts.com>

References

This function is largely inspired from the R core parse function. The C code uses the same grammar as the one used by parse.

The Gnu bison parser generator (http://www.gnu.org/software/bison/) is used to create the C code from the grammar.

See Also

The usual R parser parse

Examples

1
2
3
4
	

f <- system.file( "example", "f.R", package = "parser" )
out <- parser( f )

parser documentation built on May 2, 2019, 6:49 p.m.