%using% {parcr}R Documentation

Applying a function to the result of a parser

Description

The ⁠%using%⁠ combinator allows us to manipulate results from a parser. The parser (p %using% f) has the same behavior as the parser p, except that the function f is applied to its result value.

Usage

p %using% f

Arguments

p

a parser.

f

a function to be applied to the result of a successful p.

Value

A parser.

Pseudocode

(p %using% f)(x):
  if p1(x)==[] then fail()(x)
  else succeed(f(p1(x)$L))(x[-1])

Examples

(literal('ab') %using% toupper) (c("ab","cdef")) # success
(literal('ab') %using% toupper) (c("bb","cdef")) # failure


[Package parcr version 0.5.2 Index]