Liking cljdoc? Tell your friends :D

parsesso

Parser combinators for Clojure(Script).

Clojars Project

cljdoc badge cljs compatible bb compatible tests

Motivation

  • Idiomatic and convenient API for parser combinators in Clojure and ClojureScript.

Inspiration

Cheat sheet

ParsessoParsec1,2,3Kern4Parsatron5
p/resultreturnreturnalways
p/failfailfailnever
p/fail-unexpectedunexpectedunexpected
p/expecting<?>, label<?>, expect
p/bind>>=>>=bind
p/fordobindlet->>
p/after>>>>>>, nxt
p/valuefmap<$>
p/maybetry<:>attempt
p/look-aheadlookAheadlook-aheadlookahead
p/not-followed-bynotFollowedBynot-followed-by
p/*manymanymanymany
p/+manymany1many1many1
p/*skipskipManyskip-many
p/+skipskipMany1skip-many1
p/tokentoken, satisfysatisfytoken
p/token-not
p/wordtokens, stringtoken*string
p/any-tokenanyToken,anyCharany-charany-char
p/eofeofeofeof
p/group<*><*>
p/alt<|>, choice<|>choice
p/optionoption, optionaloption, optional
p/betweenbetweenbetweenbetween
p/timescounttimestimes
p/*many-tillmanyTillmany-till
p/*sep-bysepBysep-by
p/+sep-bysepBy1sep-by1
p/*sep-end-byendByend-by
p/+sep-end-byendBy1end-by1
p/*sep-opt-bysepEndBysep-end-by
p/+sep-opt-bysepEndBy1sep-end-by1
p/get-stategetParserState...input, pos, user state
p/set-statesetParserState...input, pos, user state
p/update-stateupdateParserState...user state
p/traceparserTrace, parserTraced
expr/*chain-leftchainlchainl
expr/+chain-leftchainl1chainl1
expr/*chain-rightchainrchainr
expr/+chain-rightchainr1chainr1
char/ischar, oneOfsym*, one-of*char
char/is-notnoneOfnone-of*
char/regex
char/upper?upperupper (unicode)
char/lower?lowerlower (unicode)
char/letter?letterletter (unicode)letter (unicode)
char/number?digitdigit (unicode)digit (unicode)
char/letter-or-number?alphaNumalpha-num (unicode)
char/white?spacewhite-space (unicode)
char/newlineendOfLinenew-line*
char/str* <+>

Examples

Performance

See some benchmarks here.

FAQ

Q. What parser combinators are & are good for? How does it differ e.g. from Instaparse, which also parses text into data?

A parser combinator library is a library with functions that can be composed into a parser. Instaparse takes a grammar specification, but in a parser combinator library you build the specification from functions, rather than a DSL.

Q. When should I pick parser combinators over EBNF? Do they offer the same, and it is only question of which one I prefer to learn or is there some distinct advantage over a DSL such as EBNF? Perhaps it is easier to describe more complex grammars b/c I can make my own helper functions, or something?

In general, parser combinators such as parsesso are for creating top-down (i.e. LL) parsers, with the ability to reuse common code (this lib). Parser Generators typically generate a finite state automaton for a bottom-up (LR) parser. Though nowadays there are also combinators for LR grammars and generators for LL ones (e.g. ANTLR). Which one you should use, depends on how hard your grammar is, and how fast the parser needs to be. Especially if the grammar has lot of non-trivial ambiguities then it might be easier with the more flexible combinators approach.

Contributors

  • Michiel Borkent
    • Compatibility with babashka.
    • Github CI configuration.
    • Clj-kondo configuration tips.
  • Jakub Holý
    • Questions and answers in FAQ.

Can you improve this documentation? These fine people already did:
Sergey Trofimov, serioga & Lee Read
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close