grapes-using-grapes: Applying a function to the result of a parser

%using%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


parcr documentation built on June 22, 2024, 10:31 a.m.