next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Parsing > Parser > orP

orP -- parsing alternatives



An abbreviation for orP(p,q) is p|q.

In case of ambiguity, the value returned by the left-most accepting parser is provided.

If one of the arguments is a string then constParser is used to convert it into a parser.

In an efficient grammar, the first token presented to r will be acceptable to at most one of the input parsers, and then the parser returned by r will be the parser returned by the single accepting input parser.

i1 : (constParser "abc" | constParser "def" : charAnalyzer) "abc"

o1 = abc
i2 : (constParser "abc" | constParser "def" : charAnalyzer) "def"

o2 = def
i3 : (constParser "abc" | "def" : charAnalyzer) "def"

o3 = def


../../../../../../../Macaulay2/packages/Parsing.m2:84:26-89:46: --source code:
Parser | Parser := (p,q) -> new Parser from ( c -> (
          p' := p c;
          q' := q c;
          if p' === null then q'
          else if q' === null then p'
          else if c === null then p' else p'|q'))

See also

For the programmer

The object orP is a function closure.