parser {tabulog} | R Documentation |
Parser Objects
Description
Create or test for parser objects. These objects will be used by templates to identify a field within a log file.
Usage
parser(x, f, name = NULL)
is.parser(x)
Arguments
x |
A regex string, a parser, or a list of either; Or object to be tested |
f |
A function to format the captured output, or a named list of such
functions if |
name |
An optional name for the parser |
Details
Parser objects contain 3 things:
A regex expression that matches the given field
A 'formatter'; a function that will in some way modify the captured text
By default, this the identity function
(Optional) A name for the parser
Value
parser
and its S3 methods coerce x
to a parser
object,
returning said parser object. is.parser
returns TRUE or FALSE
Examples
# Captures integers
parser('[0-9]+')
# Captures integers, cast to integers
parser('[0-9]+', as.integer)
# List of parsers, all named (inferred from list names), some with parsers
parser(
list(
ip = '[0-9]{1,3}(\\.[0-9]{1,3}){3}',
int = '[0-9]+',
date = '[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}'
),
list(int = as.integer, date = as.Date)
)
is.parser(parser('[0-9]+')) #TRUE
is.parser(100) #FALSE
[Package tabulog version 0.1.1 Index]