Macaulay2 » Documentation
Packages » Parsing » Parser » andP
next | previous | forward | backward | up | index | toc

# andP -- parser conjunction

- Usage:
    `r = andP(p,q,...)`
- Inputs:
  - (p,q,...), a sequence of parsers (of type Parser)
- Outputs:
  - r, a parser, a parser that accepts as many tokens as p will accept, then as many as q will accept, and so on. The return value is the sequence of values returned by each of the input parsers.

## Description

An abbreviation for andP(p,q) is p@q.

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

    i1 : (constParser "abc" @ constParser "def" : charAnalyzer) "abcdef"

    o1 = (abc, def)

    o1 : Sequence

## Code

    ../Parsing.m2:120:19-128:12: --source code:
    Parser @ Parser := (p,q) -> new Parser from (
         c -> (
              if c =!= null then (
                   if (p' := p c) =!= null
                   then p' @ q
                   else if (val1 := p null) =!= null then if (q' := q c) =!= null then (val2 -> (val1,val2)) % q'
                   )
              else if (val1 = p null) =!= null and (val2 := q null) =!= null then (val1,val2)
              ))

## See also

- constParser -- produce a parser that accepts a fixed string, one character at a time
- Parser : Analyzer -- combine a parser with a lexical analyzer to make a complete system

## For the programmer

The object andP is a function closure.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Parsing.m2:377:0.