symbolic {qmrparser} | R Documentation |
Alphanumeric token.
Description
Recognises an alphanumeric symbol. By default, a sequence of alphanumeric, numeric and dash symbols, beginning with an alphabetical character.
Usage
symbolic (charFirst=isLetter,
charRest=function(ch) isLetter(ch) || isDigit(ch) || ch == "-",
action = function(s) list(type="symbolic",value=s),
error = function(p) list(type="symbolic",pos =p))
Arguments
charFirst |
Predicate of valid characters as first symbol character |
charRest |
Predicate of valid characters as the rest of symbol characters |
action |
Function to be executed if recognition succeeds. Character stream making up the token is passed as parameter to this function |
error |
Function to be executed if recognition does not succeed. Position of |
Value
Anonymous function, returning a list.
function(stream)
–> list(status,node,stream)
From input parameters, an anonymous function is defined. This function admits just one parameter, stream, with type streamParser
, 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
# fail
stream <- streamParserFromString("123")
( symbolic()(stream) )[c("status","node")]
# ok
stream <- streamParserFromString("abc123_2")
( symbolic()(stream) )[c("status","node")]