repetition0N: Repeats one parser

Description Usage Arguments Details Value Examples

View source: R/repetition0N.R

Description

Repeats a parser indefinitely, while it succeeds. It will return an empty token if the parser never succeeds,

Number of repetitions may be zero.

Usage

1
2
3
4
  
  repetition0N(rpa0, 
               action = function(s)            list(type="repetition0N",value=s   ), 
               error  = function(p,h) list(type="repetition0N",pos=p,h=h)) 

Arguments

rpa0

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 at least one success, action gets the node returned by the parser repetition1N after applying the parser to be repeated. Otherwise, it gets the node corresponding to token empty: list(type="empty" ,value="")

Functionerror is never called. It is defined as parameter for the sake of homogeneity with the rest of functions.

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:

Examples

1
2
3
4
5
6
7
8
# ok
stream  <- streamParserFromString("Hello world")
( repetition0N(symbolic())(stream) )[c("status","node")]


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

qmrparser documentation built on May 19, 2017, 4:37 p.m.

Search within the qmrparser package
Search all R packages, documentation and source code