%ret% {parcr}R Documentation

Return a fixed value instead of the result of a parser

Description

Sometimes we are not interested in the result from a parser, only that the parser succeeds. It may be convenient to return some short representation or nothing even rather than the string itself. The ⁠%ret%⁠ combinator is useful in such cases. The parser (p %ret% c) has the same behavior as p, except that it returns the value c if successful.

Usage

p %ret% c

Arguments

p

a parser.

c

string, i.e. a single-element character vector. NULL is coerced to character(0).

Value

A parser.

Pseudocode

(p %xret% c)(x):
  if p(x)==[] then fail()(x)
  else succeed(c)(x[-1])

See Also

%using%

Examples

(literal("A") %ret% "We have an A!") (LETTERS[1:5])
(literal("A") %ret% NULL) (LETTERS[1:5])

[Package parcr version 0.5.1 Index]