SMUG
is a library for parsing text, based on monadic parser
combinators [fn:1]. Using a simple technique from the functional
programming camp, SMUG
makes it simple to create quick extensible
recursive descent parsers without funky syntax or impenetrable
macrology.
- parsers are first class values written in basic lisp
- non-deterministic infinite look-ahead
- easy to learn, easy to use
- extensible input protocol : parse strings, streams, lists etc
- in-depth tutorial : no previous experience required.
(asdf:load-system :smug)
There is an extensive Tutorial available that starts from
scratch and literately implements smug
itself.
If that is not enough, the paper that smug
is based on, Monadic
Parser Combinators, has been updated with Common Lisp code. This is a
Work In Progress and does not yet reflect the source code of smug
itself.
(require 'org-id)
(org-babel-lob-ingest "tutorial.org")
(defpackage :smug/smug
(:nicknames :smug)
(:use :cl)
(:export
#:.identity
#:.fail
#:.item
#:.bind
#:input-empty-p
#:input-first
#:input-rest
#:run
#:parse
#:.plus
#:.or
#:.not
#:.let*
#:.map
#:.concatenate
#:.is
#:.is-not
#:.char=
#:.char-equal
#:.string-equal
#:.string=
#:.progn
#:.prog1
#:.prog2
#:.and
#:.or
#:.not
#:.first
#:.optional
#:.read-line))
(in-package :smug/smug)
<<tutorial_.letstar>>
<<tutorial_run>>
<<tutorial_parse>>
<<tutorial_.fail>>
<<tutorial_.plus>>
<<tutorial_.identity>>
<<tutorial_.bind>>
<<tutorial_.or>>
<<tutorial_.not>>
<<tutorial_reading-input>>
<<tutorial_.item>>
<<tutorial-source>>
<<tutorial_.list-of>>
<<tutorial_.satisfies>>
<<tutorial_.optional>>
<<tutorial_.and>>
<<tutorial_.progn>>
<<tutorial_.is-not>>
<<tutorial_.is>>
<<tutorial-.mapcar>>
<<tutorial-.mapc>>
<<tutorial-.make-list>>
<<tutorial-.concatenate>>
<<tutorial_.map>>
<<tutorial_char=digit-char|lower-case-p>>
<<tutorial-line>>
<<tutorial_.coerce>>
<<tutorial_.string=>>
<<tutorial_.char-equal>>
<<tutorial_.string-equal>>
<<tutorial_.first>>
[fn:1] Monadic parser combinators (pdf, ps, bibtex) Graham Hutton and Erik Meijer. Technical Report NOTTCS-TR-96-4, Department of Computer Science, University of Nottingham, 1996.
– http://www.cs.nott.ac.uk/~gmh/bib.html#monparsing
[fn:2] http://www.willamette.edu/~fruehr/haskell/seuss.html
[fn:3] like, say, scheme