1. Prcc(Parser/Regex Combinator library for Chicken scheme)
    1. Introduction
    2. Combinators
      1. Helpers
    3. Example
  2. More information
  3. Author
  4. License
  5. Version History

Prcc(Parser/Regex Combinator library for Chicken scheme)

Introduction

Prcc is a PEG-like combinator parser library and inspired by Ruby gem rsec.

Combinators

[syntax] (char CHAR)

Generate a parser that read a char.

[syntax] (<c> CHAR)

Alias of char.

[syntax] (seq PARSER ...)

Sequence parser.

[syntax] (<and> PARSER ...)

Alias of sequence parser.

[syntax] (sel PARSER ...)

Branch parser and ordered selected.

[syntax] (<or> PARSER ...)

Alias of branch parser.

[syntax] (one? PARSER)

Appear 0 or 1 time.

[syntax] (<?> PARSER)

Alias of one?.

[syntax] (rep PARSER)

Repeat 0 to infinite times.

[syntax] (<*> PARSER)

Alias of rep.

[syntax] (rep+ PARSER)

Repeat 1 to infinite times.

[syntax] (<+> PARSER)

Alias of rep+.

[syntax] (pred PARSER0 PARSER1)

Lookahead predicate PARSER1.

[syntax] (<&> PARSER0 PARSER1)

Alias of pred

[syntax] (pred! PARSER0 PARSER1)

Negative lookahead.

[syntax] (<&!> PARSER0 PARSER1)

Alias of pred!.

[syntax] (eof)

End of file.

[syntax] (act PARSER [SUCC-PROC] [FAIL-PREC])

Mutate parser and be used to process the output of a parser.

[syntax] (<@> PARSER [SUCC-PROC] [FAIL-PREC])

Alias of act.

[syntax] (neg PARSER)

Take parser failure as pass.

[syntax] (<^> PARSER)

Alias of neg.

[syntax] (regexp-parser STRING [CHUNK-SIZE])

Generate a regexp parser.

[syntax] (<r> STRING [CHUNK-SIZE])

Alias of regexp-parser.

[syntax] (lazy PARSER)

Defer the binding of parser. This is useful for recursive parser.

[syntax] (cached PARSER)

Cache parser result(packrat parsing).

Helpers

[syntax] (str STRING)

A string parser.

[syntax] (<s> STRING)

Alias of str.

[syntax] (one-of STRING)

Parse one of chars in STRING.

[syntax] (join+ PARSER0 PARSER1)

Repeat PARSER0 with PARSER1 inserted.

[syntax] (join+_ PARSER0 PARSER1 [skip: PARSER2])

Repeat PARSER0 with PARSER1 inserted but skip PARSER2. By default, PARSER2 is spaces parser (<s*>).

[syntax] (ind SEQ-PARSER INDEX)

Return the value of SEQ_PARSER output that is indicated by INDEX.

[syntax] (<#> SEQ-PARSER INDEX)

Alias of ind.

[syntax] (<w>)

A word letter.

[syntax] (<w*>)
[syntax] (<w+>)
[syntax] (<space>)
[syntax] (<s*>)
[syntax] (<s+>)
[syntax] (rep_ PARSER0 [skip: PARSER1])

Repeat PARSER0 from 0 to infinite times, but skip PARSER1. By default, PARSER1 is spaces parser (<s*>).

[syntax] (<*_> PARSER0 [skip: PARSER1])

Alias of rep_.

[syntax] (rep+_ PARSER0 [skip: PARSER1])

Repeat PARSER0 from 1 to infinite times, but skip PARSER1. By default, PARSER1 is spaces parser (<s*>).

[syntax] (<+_> PARSER0 [skip: PARSER1])

Alias of rep+_.

[syntax] (seq_ PARSER ... [skip: PARSER1])

Sequence parser but skip PARSER1. By default, PARSER1 is spaces parser (<s*>).

[syntax] (and_ PARSER ... [skip: PARSER1])

Alias of seq_.

[syntax] (even SEQ-PARSER)

Generate a parser which return even elements of sequence parser output.

[syntax] (odd SEQ-PARSER)

Generate a parser which return odd elements of sequence parser output.

[syntax] (parse-file FILENAME PARSER [CACHE])

Parse a file with PARSER. By default, no cache(CACHE=#f).

[syntax] (parse-string STRING PARSER [CACHE])
[syntax] (parse-port PORT PARSER [CACHE])

Example

        (use prcc)

        (define parser
          (<and>
            (<@> (<s> "hello")
              (lambda (o) "hello "))
            (<s> "world")
            (eof)))

        (display (parse-string "helloworld" parser))
        (newline)

More information

PEG wiki page

Packrat Parsing and Parsing Expression Grammars

Author

Wei Hu

License

 Copyright (C) 2012, Wei Hu
 All rights reserved.
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 Redistributions of source code must retain the above copyright notice, this
 list of conditions and the following disclaimer.
 Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution.
 Neither the name of the author nor the names of its contributors may be
 used to endorse or promote products derived from this software without
 specific prior written permission.
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.

Version History

0.1
initial release