Liking cljdoc? Tell your friends :D

squarepeg.core


alphaclj

(alpha input)
(alpha input context)
(alpha input bindings context memo)

alpha is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

alpha is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

alphanumclj

(alphanum input)
(alphanum input context)
(alphanum input bindings context memo)

alphanum is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

alphanum is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

alwaysclj

(always input)
(always input context)
(always input bindings context memo)

always is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

always is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

anythingclj

(anything input)
(anything input context)
(anything input bindings context memo)

anything is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

anything is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

defrulecljmacro

(defrule name & body)
source

digitclj

(digit input)
(digit input context)
(digit input bindings context memo)

digit is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

digit is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

endclj

(end input)
(end input context)
(end input bindings context memo)

end is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

end is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

failclj

(fail msg memo)

Fail a rule call with the given msg

Fail a rule call with the given msg
sourceraw docstring

failure?clj

(failure? x)

Is x a failure?

Is x a failure?
sourceraw docstring

match-charclj

(match-char input)
(match-char input context)
(match-char input bindings context memo)

match-char is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-char is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

match-floatclj

(match-float input)
(match-float input context)
(match-float input bindings context memo)

match-float is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-float is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

match-hashclj

(match-hash input)
(match-hash input context)
(match-hash input bindings context memo)

match-hash is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-hash is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

match-integerclj

(match-integer input)
(match-integer input context)
(match-integer input bindings context memo)

match-integer is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-integer is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

match-keywordclj

(match-keyword input)
(match-keyword input context)
(match-keyword input bindings context memo)

match-keyword is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-keyword is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

match-listclj

(match-list input)
(match-list input context)
(match-list input bindings context memo)

match-list is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-list is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

match-numberclj

(match-number input)
(match-number input context)
(match-number input bindings context memo)

match-number is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-number is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

match-stringclj

(match-string input)
(match-string input context)
(match-string input bindings context memo)

match-string is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-string is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

match-symbolclj

(match-symbol input)
(match-symbol input context)
(match-symbol input bindings context memo)

match-symbol is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-symbol is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

match-vectorclj

(match-vector input)
(match-vector input context)
(match-vector input bindings context memo)

match-vector is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

match-vector is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

mk1omclj

(mk1om rule)

Create a rule which matches rule as many times as possible but at least once.

mk1om creates a rule that matches the given rule at least once. Returns all matches.

Example:

;; match one or more digits
(def digits (mk1om digit))
(digits "1234" {} {} {}) 
    => {:r [\1 \2 \3 \4] :s [\1 \2 \3 \4] :i nil :b {} :m {}}
(digits "123 4" {} {} {}) 
    => {:r [\1 \2 \3] :s [\1 \2 \3] :i (\4) :b {} :m {}}
Create a rule which matches rule as many times as possible but at
least once.

`mk1om` creates a rule that matches the given rule at least
once. Returns all matches.

Example:

    ;; match one or more digits
    (def digits (mk1om digit))
    (digits "1234" {} {} {}) 
        => {:r [\1 \2 \3 \4] :s [\1 \2 \3 \4] :i nil :b {} :m {}}
    (digits "123 4" {} {} {}) 
        => {:r [\1 \2 \3] :s [\1 \2 \3] :i (\4) :b {} :m {}}
sourceraw docstring

mkaltclj

(mkalt)
(mkalt rule)
(mkalt rule1 rule2)
(mkalt rule1 rule2 & rules)

Create a rule which succeeds if one of rules succeeds.

mkalt takes any number of rules and tries each one in order. The first rule that matches is returned.

Example:

;; match 'a' or 'b' or 'c' (in that order)
(def aorborc (mkalt (mklit \a) (mklit \b) (mklit \c)))
Create a rule which succeeds if one of rules succeeds.

`mkalt` takes any number of rules and tries each one in order. The
first rule that matches is returned.

Example:

    ;; match 'a' or 'b' or 'c' (in that order)
    (def aorborc (mkalt (mklit \a) (mklit \b) (mklit \c)))
sourceraw docstring

mkbindclj

(mkbind rule var)

Create a rule that binds the return value of rule to var.

mkbind creates a rule that will bind the return value of its first argument (a rule) to its second argument (typically a keyword). Binding is useful if you want to refer to the return value of a rule later.

Example:

;; bind the matched digits to :digits
(def digits (mkbind 
    (mk1om (mkpr #(Character/isDigit %))) :digits))
(digits "123" {} {} {}) 
    => {:r [\1 \2 \3] :s [\1 \2 \3] :i nil :b {:digits [\1 \2 \3]}
        :m {}}
Create a rule that binds the return value of rule to var.

`mkbind` creates a rule that will bind the return value of its first
argument (a rule) to its second argument (typically a
keyword). Binding is useful if you want to refer to the return value
of a rule later.

Example:

    ;; bind the matched digits to :digits
    (def digits (mkbind 
        (mk1om (mkpr #(Character/isDigit %))) :digits))
    (digits "123" {} {} {}) 
        => {:r [\1 \2 \3] :s [\1 \2 \3] :i nil :b {:digits [\1 \2 \3]}
            :m {}}
sourceraw docstring

mkfnclj

(mkfn f)

Create a function useful for calling a rule at the REPL.

Create a function useful for calling a rule at the REPL.
sourceraw docstring

mklitclj

(mklit l)

Create a rule which consumes one item of input. If it is equal to l, succeed.

mklit creates a rule that matches a value if it is equal.

Example:

;; match the number 12
(def twelve (mklit 12))
(twelve [12] {} {} {}) => {:r 12 :s [12] :i nil :b {} :m {}}
Create a rule which consumes one item of input. If it is equal to
l, succeed.

`mklit` creates a rule that matches a value if it is equal.

Example:

    ;; match the number 12
    (def twelve (mklit 12))
    (twelve [12] {} {} {}) => {:r 12 :s [12] :i nil :b {} :m {}}
sourceraw docstring

mklowerclj

(mklower rule)

Make a rule that transforms the input to lowercase. This is helpful for creating a rule that is case insensitive. Rules executed after this rule will see the original input.

Make a rule that transforms the input to lowercase. This is helpful
for creating a rule that is case insensitive. Rules executed after
this rule will see the original input.
sourceraw docstring

mkmatchclj

(mkmatch rule)

Create a rule that binds the input sequence that is matched to :match.

mkmatch create a new rule which returns the matched portion of the input. It binds that portion of the input matched by the given rule to :match. It also coerces Strings if possible.

Example:

;; match a "SELECT" statement in a contrived query language.
;; perform a "lookup" of everything after the SELECT followed
;; by whitespace
(def selectstmt (mkscope (mkmemo (mkret (mkseq [(mkstr "SELECT") w+
   (mkmatch (mk1om anything))]) (fn [b c] (lookup (:match b))))))
Create a rule that binds the input sequence that is matched to
  `:match`.

`mkmatch` create a new rule which returns the matched portion of the
input. It binds that portion of the input matched by the given rule
to `:match`. It also coerces Strings if possible.

Example:

    ;; match a "SELECT" statement in a contrived query language.
    ;; perform a "lookup" of everything after the SELECT followed
    ;; by whitespace
    (def selectstmt (mkscope (mkmemo (mkret (mkseq [(mkstr "SELECT") w+
       (mkmatch (mk1om anything))]) (fn [b c] (lookup (:match b))))))
sourceraw docstring

mkmemoclj

(mkmemo rule)

Create a rule that memoizes the given rule.

mkmemo creates a new rule which memoizes the given rule. The best way to use this is directly inside of a mkscope when defining a top-level rule for most efficient results. Memoizing is done to trade space efficiency for time efficiency. Effectively using mkmemo will make a parse use linear space and linear time with respect to input size.

Create a rule that memoizes the given rule.

`mkmemo` creates a new rule which memoizes the given rule. The best
way to use this is directly inside of a `mkscope` when defining a
top-level rule for most efficient results. Memoizing is done to trade
space efficiency for time efficiency. Effectively using mkmemo will
make a parse use linear space and linear time with respect to input
size.
sourceraw docstring

mknotclj

(mknot rule)

Create a rule that fails if the next input matches rule and succeeds otherwise.

mknot inverts a rule. Given a rule, mknot returns a new rule that fails when the given rule succeeds, and vice versa. It never returns a value and never consumes input. It is most useful for making a rule that says "and is not followed by . . .".

Example:

(def not-followed-by-whitespace (mknot whitespace))
(not-followed-by-whitespace "abc" {} {} {}) 
    => {:r nil :s [] :i (\a \b \c) :b {} :m {})
(not-followed-by-whitespace " abc" {}) => {:fail "NOT failed"}
Create a rule that fails if the next input matches rule and
succeeds otherwise.

`mknot` inverts a rule. Given a rule, `mknot` returns a new
rule that fails when the given rule succeeds, and vice versa. It never
returns a value and never consumes input. It is most useful for making
a rule that says "and is not followed by . . .".

Example:

    (def not-followed-by-whitespace (mknot whitespace))
    (not-followed-by-whitespace "abc" {} {} {}) 
        => {:r nil :s [] :i (\a \b \c) :b {} :m {})
    (not-followed-by-whitespace " abc" {}) => {:fail "NOT failed"}
sourceraw docstring

mknothingclj

(mknothing rule)

Create a rule that succeeds, fails, and consumes just like rule but returns nothing.

mknothing makes a rule return nothing.

Example:

;; ignore whitespace
(def ignorewhitespace (mknothing (mk1om #(Character/isSpace %))))
Create a rule that succeeds, fails, and consumes just like rule but
returns nothing.

`mknothing` makes a rule return nothing.

Example:

    ;; ignore whitespace
    (def ignorewhitespace (mknothing (mk1om #(Character/isSpace %))))
sourceraw docstring

mkoptclj

(mkopt rule)

Create a rule which matches rule or not, but never fails.

mkopt creates a rule that always succeeds. If the rule it is given matches, it returns its value. Otherwise, it succeeds with no return.

Example:

;; optionally match 'xyz'
(def xyz? (mkopt (mkstr "xyz")))
Create a rule which matches rule or not, but never fails.

`mkopt` creates a rule that always succeeds. If the rule it is given
matches, it returns its value. Otherwise, it succeeds with no return.

Example:

    ;; optionally match 'xyz'
    (def xyz? (mkopt (mkstr "xyz")))
sourceraw docstring

mkprclj

(mkpr pr)

Create a rule that consumes one item from the input. If pr applied to that item returns true, the rule succeeds. Otherwise, fail.

mkpr creates a rule that consumes one item from the input. It then calls the given predicate on it. If the predicate returns nil, the rule fails. Otherwise, the rule passes. The return value is the item consumed. (It does not consume input if the predicate fails.)

Example:

;; match only even numbers
(def even (mkpr evenp))
Create a rule that consumes one item from the input. If pr applied
to that item returns true, the rule succeeds. Otherwise, fail.

`mkpr` creates a rule that consumes one item from the input. It then
calls the given predicate on it. If the predicate returns nil, the
rule fails. Otherwise, the rule passes. The return value is the item
consumed. (It does not consume input if the predicate fails.)

Example:

    ;; match only even numbers
    (def even (mkpr evenp))
sourceraw docstring

mkpredclj

(mkpred f)

Create a rule which never returns a value or consumes input. It succeeds if f returns non-nil and fails otherwise. f is a function of bindings and context.

mkpred takes a predicate and returns a rule that succeeds when the predicate applied to the first input element succeeds. It never returns a value and never consumes input. The predicate operates on the bindings map.

Example:

;; match two numbers if their sum > 100
(def sum>100 (mkseq (mkbind integer :a) (mkbind integer :b)
                    (mkpred #(> (+ (:a %) (:b %)) 100))))
Create a rule which never returns a value or consumes input. It
succeeds if `f` returns non-nil and fails otherwise. `f` is a function
of `bindings` and `context`.

`mkpred` takes a predicate and returns a rule that succeeds when the
predicate applied to the first input element succeeds. It never
returns a value and never consumes input. The predicate operates on
the bindings map.

Example:

    ;; match two numbers if their sum > 100
    (def sum>100 (mkseq (mkbind integer :a) (mkbind integer :b)
                        (mkpred #(> (+ (:a %) (:b %)) 100))))
sourceraw docstring

mkretclj

(mkret rule ret)

Create a rule that returns a value. The value is computed by ret, which is a function of a bindings map. The rule also binds the return value of rule to :ret.

mkret changes the current return value. It takes a function which takes the bindings map.

Example:

;; parse digit characters as an int
(def integer (mkret (mkbind (mk1om (mkpr #(Character/isDigit %))) 
                            :digits) 
                    #(Integer/parseInt (:digits %))))
Create a rule that returns a value. The value is computed by ret,
which is a function of a bindings map. The rule also binds the return
value of rule to `:ret`.

`mkret` changes the current return value. It takes a function which
takes the bindings map.

Example:

    ;; parse digit characters as an int
    (def integer (mkret (mkbind (mk1om (mkpr #(Character/isDigit %))) 
                                :digits) 
                        #(Integer/parseInt (:digits %))))
sourceraw docstring

mkscopeclj

(mkscope rule)

Create a rule which contains the scope of the given rule. Bindings made in the rule do not escape this rule's scope.

mkscope creates a scope protector around a rule so that bindings that the given rule creates do not leak into the current scope. This function should be used around your own rules.

Example:

;; a rule that binds but does not protect
(def as (mkbind (mk1om (mklit \a)) :as))
;; a rule that calls as
(def xab (mkseq (mkbind (mk1om (mklit \x)) :as) ;; bind to :as
                (mkscope as)                    ;; make sure as
                                                ;; does not bind
                (mk1om (mklit \b))))
Create a rule which contains the scope of the given rule. Bindings
made in the rule do not escape this rule's scope.

`mkscope` creates a scope protector around a rule so that bindings
that the given rule creates do not leak into the current scope. This
function should be used around your own rules.

Example:

    ;; a rule that binds but does not protect
    (def as (mkbind (mk1om (mklit \a)) :as))
    ;; a rule that calls as
    (def xab (mkseq (mkbind (mk1om (mklit \x)) :as) ;; bind to :as
                    (mkscope as)                    ;; make sure as
                                                    ;; does not bind
                    (mk1om (mklit \b))))
sourceraw docstring

mkseqclj

(mkseq)
(mkseq rule)
(mkseq rule1 rule2)
(mkseq rule1 rule2 & rules)

Create a rule that matches all of rules in order. Returns a vec of the return values of each.

mkseq takes any number of rules and creates a rule that must match all of them in sequence.

Example:

;; match three even numbers then two odds
(def even3odd2 (mkseq even even even odd odd))
Create a rule that matches all of rules in order. Returns a vec of
the return values of each.

`mkseq` takes any number of rules and creates a rule that must
match all of them in sequence.

Example:

    ;; match three even numbers then two odds
    (def even3odd2 (mkseq even even even odd odd))
sourceraw docstring

mkstrclj

(mkstr s)

Create a rule which matches all of the characters of a String s in sequence.

mkstr create a sequential rule that matches all of the characters of a string.

Example:

;; match the string "hello" followed by whitespace
(def hellow+ (mkseq [(mkstr "hello") (mk1om whitespace)]))
Create a rule which matches all of the characters of a String s in
sequence.

`mkstr` create a sequential rule that matches all of the characters of
a string.

Example:

    ;; match the string "hello" followed by whitespace
    (def hellow+ (mkseq [(mkstr "hello") (mk1om whitespace)]))
sourceraw docstring

mksubclj

(mksub rule)

Create a rule which applies a rule to a nested seq within the input.

mksub creates a rule that matches a nested seq within the seq.

Example:

;; match a seq of ones
(def ones (mk0om (mklit 1)))
;; match a seq of ones followed by 2s
(def onesthentwos (mkseq (mksub ones) (mk0om (mklit 2))))
(onesthentwos [[1 1 1] 2 2] {}) => SUCCESS
(onesthentwos [1 1 1 2 2] {}) => FAILURE
Create a rule which applies a rule to a nested seq within the
input.

`mksub` creates a rule that matches a nested seq within the seq.

Example:

    ;; match a seq of ones
    (def ones (mk0om (mklit 1)))
    ;; match a seq of ones followed by 2s
    (def onesthentwos (mkseq (mksub ones) (mk0om (mklit 2))))
    (onesthentwos [[1 1 1] 2 2] {}) => SUCCESS
    (onesthentwos [1 1 1 2 2] {}) => FAILURE
sourceraw docstring

mkzomclj

(mkzom rule)

Create a rule which matches rule consecutively as many times as possible. The rule never fails. Returns a seq of all matched values.

mkzom creates a rule which matches zero or more times. It will match the most possible times. It never fails.

Example:

;; match zero or more whitespace
(def w* (mkzom (mkpr #(Character/isSpace %))))
Create a rule which matches rule consecutively as many times as
possible. The rule never fails. Returns a seq of all matched values.

`mkzom` creates a rule which matches zero or more times. It will match
the most possible times. It never fails.

Example:

    ;; match zero or more whitespace
    (def w* (mkzom (mkpr #(Character/isSpace %))))
sourceraw docstring

neverclj

(never input)
(never input context)
(never input bindings context memo)

never is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

never is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

succeedclj

(succeed return sreturn input bindings memo)

Succeed a rule call.

Succeed a rule call.
sourceraw docstring

success?clj

(success? x)

Is x a success?

Is x a success?
sourceraw docstring

whitespaceclj

(whitespace input)
(whitespace input context)
(whitespace input bindings context memo)

whitespace is a squarepeg parser rule. Call with a seq of input or use it as a rule (4 arguments).

whitespace is a squarepeg parser rule. Call with a
seq of input or use it as a rule (4 arguments).
sourceraw docstring

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

× close