Skip to content
Common Lisp packrat parser
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc remove references to now defunct sb-studio Apr 12, 2013
tools
web
Makefile
README
TODO.org
esrap.asd
esrap.lisp Merge branch 'wip-expression-case' of git://github.com/scymtym/esrap … Jun 22, 2013
example-sexp.lisp support for &BOUNDS syntax in :LAMBDA and :DESTRUCTURE transforms Apr 3, 2012
example-symbol-table.lisp
tests.lisp

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 (describing 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-2013 Nikodemus Siivola <nikodemus@random-state.net.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
 (not expression)          -- complement of expression
 (character-ranges ranges) -- character ranges
 (and &rest sequence)
 (or &rest ordered-choices)
 (* 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,
 and example-symbol-table.lisp for a grammar with lexical scope.

Trivial examples:

 ;; Parse takes a expression
 (parse '(or "foo" "bar") "foo")         => "foo", NIL

 ;; New rules can be added.
 ;;
 ;; Normally you'd use the declarative DEFRULE interface to define new
 ;; rules, but everything it does can be done directly by building
 ;; instances of the RULE class and using ADD-RULE to activate them.
 (add-rule 'foo+ (make-instance 'rule :expression '(+ "foo"))) => FOO+

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

 ;; Rules can transform their matches.
 (add-rule 'decimal
           (make-instance 'rule
            :expression '(+ (or "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))
            :transform (lambda (list start end)
                         (declare (ignore start end))
                         (parse-integer (format nil "~{~A~}" list)))))
  => DECIMAL

 ;; Any lisp function can be used as a semantic predicate.
 (parse '(oddp decimal) "123")                  => 123

 (parse '(evenp decimal) "123" :junk-allowed t) => NIL, 0
You can’t perform that action at this time.