Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Common Lisp packrat parser
Common Lisp
branch: master

This branch is 3 commits ahead, 25 commits behind nikodemus:master

README

ESRAP -- a packrat parser for Common Lisp

In addition to regular Packrat / Parsing Grammar / TDPL features ESRAP
supports:

 - dynamic redefinition of nonterminals
 - inline grammars
 - semantic predicates
 - introspective facilities (decribing grammars, tracing, setting breaks)

Homepage & Documentation:

  http://nikodemus.github.com/esrap/

References:

  * Bryan Ford, 2002, "Packrat Parsing: a Practical Linear Time
    Algorithm with Backtracking".

    http://pdos.csail.mit.edu/~baford/packrat/thesis/

Licence:

 Copyright (c) 2007-2011 Nikodemus Siivola <nikodemus@sb-studio.net>

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation files
 (the "Software"), to deal in the Software without restriction,
 including without limitation the rights to use, copy, modify, merge,
 publish, distribute, sublicense, and/or sell copies of the Software,
 and to permit persons to whom the Software is furnished to do so,
 subject to the following conditions:

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Syntax overview:

 <literal>                 -- case-sensitive terminal
 (~ <literal>)             -- case-insensitive terminal
 character                 -- any single character
 (string length)           -- any string of length
 (and &rest sequence)
 (or &rest ordered-choises)
 (* greedy-repetition)
 (+ greedy-positive-repetition)
 (? optional)
 (& followed-by)           -- does not consume
 (! not-followed-by)       -- does not consume
 (<predicate> expr)        -- semantic parsing

 See file example-sexp.lisp for a complete sample grammar and usage.

Trivial examples:

 (parse '(or "foo" "bar") "foo")         => "foo", NIL

 (add-rule 'foo+ (make-instance 'rule :expression '(+ "foo"))) => FOO+

 (parse 'foo+ "foofoofoo")               => ("foo" "foo" "foo"), NIL

 (add-rule 'decimal
           (make-instance 'rule
            :expression '(+ (or "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))
            :transform (lambda (list)
                         (parse-integer (format nil "~{~A~}" list)))))
  => DECIMAL

 (parse '(oddp decimal) "123")                  => 123

 (parse '(evenp decimal) "123" :junk-allowed t) => NIL, 0
Something went wrong with that request. Please try again.