repetition1N: Repeats a parser, at least once.

View source: R/repetition1N.R

repetition1NR Documentation

Repeats a parser, at least once.

Description

Repeats a parser application indefinitely while it is successful. It must succeed at least once.

Usage

  
  repetition1N(rpa, 
               action = function(s)   list(type="repetition1N",value=s  ),
               error  = function(p,h) list(type="repetition1N",pos=p,h=h))

Arguments

rpa

parse to be applied iteratively

action

Function to be executed if recognition succeeds. It takes as input parameters information derived from parsers involved as parameters

error

Function to be executed if recognition does not succeed. I takes two parameters:

  • p

    with position where parser, streamParser, starts its recognition, obtained with streamParserPosition

  • h

    with information obtained from parsers involved as parameters, normally related with failure(s) position in component parsers.

    Its information depends on how parser involved as parameters are combined and on the error definition in these parsers.

Details

In case of success, action gets a list with information about the node returned by the applied parser. List length equals the number of successful repetitions.

In case of failure, parameter h from error gets error information returned by the first attempt of parser application.

Value

Anonymous functions, returning a list.

function(stream) –> list(status,node,stream)

From these input parameters, an anonymous function is constructed. This function admits just one parameter, stream, with streamParser class, and returns a three-field list:

  • status

    "ok" or "fail"

  • node

    With action or error function output, depending on the case

  • stream

    With information about the input, after success or failure in recognition

Examples


# ok
stream  <- streamParserFromString("Hello world")
( repetition1N(symbolic())(stream) )[c("status","node")]


# fail
stream  <- streamParserFromString("123 Hello world")
( repetition1N(symbolic())(stream) )[c("status","node")]


qmrparser documentation built on April 24, 2022, 1:05 a.m.