alternation {qmrparser} | R Documentation |
Alternative phrases
Description
Applies parsers until one succeeds or all of them fail.
Usage
alternation(...,
action = function(s) list(type="alternation",value=s),
error = function(p,h) list(type="alternation",pos =p,h=h) )
Arguments
... |
list of alternative parsers to be executed |
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:
|
Details
In case of success, action
gets the node
from the first parse to succeed.
In case of failure, parameter h
from error
gets a list, with information about failure from all the parsers processed.
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
orerror
function output, depending on the casestream
With information about the input, after success or failure in recognition
Examples
# ok
stream <- streamParserFromString("123 Hello world")
( alternation(numberNatural(),symbolic())(stream) )[c("status","node")]
# fail
stream <- streamParserFromString("123 Hello world")
( alternation(string(),symbolic())(stream) )[c("status","node")]