tabulog (version 0.1.1)

parser: 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 x is a list

name

An optional 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

Details

Parser objects contain 3 things:

  1. A regex expression that matches the given field

  2. A 'formatter'; a function that will in some way modify the captured text

    • By default, this the identity function

  3. (Optional) A name for the parser

Examples

Run this code
# NOT RUN {
# 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

# }

Run the code above in your browser using DataLab