Liking cljdoc? Tell your friends :D

Lilac parser

A toy combinator parser with better failure reasons.

Demo of (def a (add 1 2)) http://repo.mvc-works.org/lilac-parser/

Usage

Clojars Project

[mvc-works/lilac-parser "0.0.2-a1"]
(require '[lilac-parser.core :refer
            [parse-lilac defparser is+ many+ one-of+ some+ combine+ interleave+ other-than+]])

(parse-lilac "aaaa" (many+ (is+ "a")))

Demo of a stupid S-expression parser:

(def number-parser (many+ (one-of+ (set (string/split "1234567890" "")))))

(def space-parser (is+ " "))

(def word-parser (many+ (one-of+ (set (string/split "qwertyuiopasdfghjklzxcvbnm" "")))))

(defparser
 s-expr-parser+
 ()
 identity
 (combine+
  [(is+ "(")
   (some+ (or+ [number-parser word-parser space-parser (s-expr-parser+)]))
   (is+ ")")]))

(parse-lilac (string/split "(def a (add 1 2))" "") (s-expr-parser+))

defparser is a macro for defining parser that can be used recursively. Notice that s-expr-parser+ is different from a normal number-parser, it's a function so it need to be called before passing as a rule.

Workflow

Workflow https://github.com/mvc-works/calcit-workflow

License

MIT

Can you improve this documentation? These fine people already did:
jiyinyiyong & Jon
Edit on GitHub

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

× close