Liking cljdoc? Tell your friends :D

blancas.kern.core

The core Kern library.

Kern is a library of parser combinators for Clojure. It is useful for implementing recursive-descent parsers based on predictive LL(1) grammars with on-demand, unlimited look-ahead LL(*).

The main inspiration for Kern comes from Parsec, a Haskell library written by Daan Leijen, as well as work by Graham Hutton, Erik Meijer, and William Burge. The name Kern is a token of appreciation to Brian Kernighan (now at Princeton) for his work on programming languages.

Daan Leijen Parsec, a fast combinator parser, 2001 http://legacy.cs.uu.nl/daan/download/parsec/parsec.pdf

Graham Hutton and Erik Meijer Monadic Parser Combinators, 1996 http://eprints.nottingham.ac.uk/237/1/monparsing.pdf

William H. Burge Recursive Programming Techniques Addison-Wesley, 1975

The core Kern library.

Kern is a library of parser combinators for Clojure. It is useful for
implementing recursive-descent parsers based on predictive LL(1) grammars
with on-demand, unlimited look-ahead LL(*).

The main inspiration for Kern comes from Parsec, a Haskell library written
by Daan Leijen, as well as work by Graham Hutton, Erik Meijer, and William Burge.
The name Kern is a token of appreciation to Brian Kernighan (now at Princeton)
for his work on programming languages.

Daan Leijen
Parsec, a fast combinator parser, 2001
http://legacy.cs.uu.nl/daan/download/parsec/parsec.pdf

Graham Hutton and Erik Meijer
Monadic Parser Combinators, 1996
http://eprints.nottingham.ac.uk/237/1/monparsing.pdf

William H. Burge
Recursive Programming Techniques
Addison-Wesley, 1975
raw docstring

*tab-width*clj

The number of columns to advance for a tab character. By default, a tab takes four columns.

The number of columns to advance for a tab character.
By default, a tab takes four columns.
sourceraw docstring

<$>clj

(<$> f p)

Parses p; if successful, it applies f to the value parsed by p.

Parses p; if successful, it applies f to the value parsed by p.
sourceraw docstring

<*>clj

(<*> p & more)

Applies one or more parsers; collects the results in a vector, including nil values. If any parser fails, it stops immediately and fails.

Applies one or more parsers; collects the results in a
vector, including nil values. If any parser fails, it
stops immediately and fails.
sourceraw docstring

<+>clj

(<+> p & more)

Applies one or more parsers stopping at the first failure. Flattens the result and converts it to a string.

Applies one or more parsers stopping at the first failure.
Flattens the result and converts it to a string.
sourceraw docstring

<:>clj

(<:> p)

Parses p; on failure it pretends it did not consume any input.

Parses p; on failure it pretends it did not consume any input.
sourceraw docstring

<<clj

(<< p q)
(<< p q & more)

Parses p followed by q; keeps p, skips q. If more parsers are given, it keeps the first result and skips the rest.

Parses p followed by q; keeps p, skips q. If more parsers are
given, it keeps the first result and skips the rest.
sourceraw docstring

<?>clj

(<?> p msg)

If parser p fails consuming no input, it replaces any Expecting errors with a single Expecting with message msg. This helps to produce more abstract and accurate error messages.

If parser p fails consuming no input, it replaces any Expecting
errors with a single Expecting with message msg. This helps to
produce more abstract and accurate error messages.
sourceraw docstring

<|>clj

(<|> p q)
(<|> p q & more)

Tries p; if it fails without consuming any input, it tries q. With more parsers, it will stop and succeed if a parser succeeds; it will stop and fail if a parser fails consuming input; or it will try the next one if a parser fails without consuming input.

Tries p; if it fails without consuming any input, it tries q.
With more parsers, it will stop and succeed if a parser succeeds;
it will stop and fail if a parser fails consuming input; or it
will try the next one if a parser fails without consuming input.
sourceraw docstring

>>clj

(>> p q)
(>> p q & more)

Parses p followed by q; skips p, keeps q. If more parsers are given, it skips all but last and keeps the result of the last.

Parses p followed by q; skips p, keeps q. If more parsers are
given, it skips all but last and keeps the result of the last.
sourceraw docstring

>>=clj

(>>= p f)

Binds parser p to function f which gets p's value and returns a new parser. Function p must define a single parameter. The argument it receives is the value parsed by p, not ps' return value, which is a parser state record.

Binds parser p to function f which gets p's value and returns
a new parser. Function p must define a single parameter. The
argument it receives is the value parsed by p, not ps' return
value, which is a parser state record.
sourceraw docstring

alpha-numclj

Parses a letter or digit.

Parses a letter or digit.
sourceraw docstring

any-charclj

Succeeds with any character.

Succeeds with any character.
sourceraw docstring

betweenclj

(between delim p)
(between open close p)

Applies open, p, close; returns the value of p.

Applies open, p, close; returns the value of p.
sourceraw docstring

bindcljmacro

(bind [& bindings] & body)

Expands into nested >>= forms and a function body. The pattern:

(>>= p1 (fn [v1] (>>= p2 (fn [v2] ... (return (f v1 v2 ...))))))

can be more conveniently be written as:

(bind [v1 p1 v2 p2 ...] (return (f v1 v2 ...)))

Expands into nested >>= forms and a function body. The pattern:

(>>= p1 (fn [v1]
(>>= p2 (fn [v2]
...
  (return (f v1 v2 ...))))))

can be more conveniently be written as:

(bind [v1 p1 v2 p2 ...] (return (f v1 v2 ...)))
sourceraw docstring

char-seqclj

(char-seq rdr)

Returns characters from rdr as a lazy sequence. rdr must implement java.io.Reader

Returns characters from rdr as a lazy sequence.
rdr must implement java.io.Reader
sourceraw docstring

clear-emptyclj

(clear-empty s)

Sets the parser state as not empty. Needed in compound parsers where optional parsers at the end may leave an incorrect :empty state for the parser as a whole.

Sets the parser state as not empty. Needed in compound parsers
where optional parsers at the end may leave an incorrect :empty
state for the parser as a whole.
sourceraw docstring

dec-numclj

Parses a decimal integer delimited by any character that is not a decimal digit.

Parses a decimal integer delimited by any character that
is not a decimal digit.
sourceraw docstring

def-cljmacro

(def- name & more)

Same as def, yielding a private def.

Same as def, yielding a private def.
sourceraw docstring

defn*cljmacro

(defn* name & more)

Same as def, yielding a dynamic def.

Same as def, yielding a dynamic def.
sourceraw docstring

digitclj

Parses a digit.

Parses a digit.
sourceraw docstring

end-byclj

(end-by sep p)

Parses p zero or more times, separated and ended by applications of sep; returns the results of p in a vector.

Parses p zero or more times, separated and ended by applications
of sep; returns the results of p in a vector.
sourceraw docstring

end-by1clj

(end-by1 sep p)

Parses p one or more times, separated and ended by applications of sep; returns the results of p in a vector.

Parses p one or more times, separated and ended by applications
of sep; returns the results of p in a vector.
sourceraw docstring

eofclj

Succeeds on end of input.

Succeeds on end of input.
sourceraw docstring

expectclj

(expect p msg)

Applies parser p; if it fails (regardless of input consumed) it replaces any expecting errors with expecting msg. This is similar to <?> but works even if some input was consumed.

Applies parser p; if it fails (regardless of input consumed)
it replaces any expecting errors with expecting msg. This is
similar to <?> but works even if some input was consumed.
sourceraw docstring

expectingclj

(expecting msg s)

Sets s as expecting msg.

Sets s as expecting msg.
sourceraw docstring

f->sclj

(f->s f)
(f->s f e)

Gets a character sequence from a file-like object.

Gets a character sequence from a file-like object.
sourceraw docstring

failclj

(fail msg)

Fails without consuming any input, having a single error record with the passed messge msg.

Fails without consuming any input, having a single error
record with the passed messge msg.
sourceraw docstring

failed-empty?clj

(failed-empty? s)

Tests if s failed without consuming any input.

Tests if s failed without consuming any input.
sourceraw docstring

field*clj

(field* cs)

Parses an unquoted text field terminated by any character in cs.

Parses an unquoted text field terminated by any character in cs.
sourceraw docstring

float-numclj

Parses a simple fractional number without an exponent. It is delimited by any character that is not a decimal digit. It cannot start with a period; the first period found must be followed by at least one digit.

Parses a simple fractional number without an exponent.
It is delimited by any character that is not a decimal
digit. It cannot start with a period; the first period
found must be followed by at least one digit.
sourceraw docstring

fwdcljmacro

(fwd p)

Delays the evaluation of a parser that was forward (declare)d and it has not been defined yet. For use in (def)s of no-arg parsers, since the parser expression evaluates immediately.

Delays the evaluation of a parser that was forward (declare)d and
it has not been defined yet. For use in (def)s of no-arg parsers,
since the parser expression evaluates immediately.
sourceraw docstring

get-inputclj

(get-input s)

Gets the input stream from a parser state.

Gets the input stream from a parser state.
sourceraw docstring

get-positionclj

(get-position s)

Gets the position in the input stream of a parser state.

Gets the position in the input stream of a parser state.
sourceraw docstring

get-stateclj

(get-state s)

Get the user state from the parser state record.

Get the user state from the parser state record.
sourceraw docstring

hex-digitclj

Parses a hexadecimal digit.

Parses a hexadecimal digit.
sourceraw docstring

hex-numclj

Parses a hex integer delimited by any character that is not a hex digit.

Parses a hex integer delimited by any character that
is not a hex digit.
sourceraw docstring

letterclj

Parses a letter.

Parses a letter.
sourceraw docstring

look-aheadclj

(look-ahead p)

Applies p and returns the result; it consumes no input.

Applies p and returns the result; it consumes no input.
sourceraw docstring

lowerclj

Parses a lower-case letter.

Parses a lower-case letter.
sourceraw docstring

manyclj

(many p)

Parses p zero or more times; returns the result(s) in a vector. It stops when p fails, but this parser succeeds.

Parses p zero or more times; returns the result(s) in a
vector. It stops when p fails, but this parser succeeds.
sourceraw docstring

many-tillclj

(many-till p end)

Parses zero or more p while trying end, until end succeeds. Returns the results in a vector.

Parses zero or more p while trying end, until end succeeds.
Returns the results in a vector.
sourceraw docstring

many0clj

(many0 p)

Like (many) but it won't set the state to :empty. Use instead of (many) if it comes last to avoid overriding non-empty parsing.

Like (many) but it won't set the state to :empty. Use instead of
(many) if it comes last to avoid overriding non-empty parsing.
sourceraw docstring

many1clj

(many1 p)

Parses p one or more times and returns the result(s) in a vector. It stops when p fails, but this parser succeeds.

Parses p one or more times and returns the result(s) in a
vector. It stops when p fails, but this parser succeeds.
sourceraw docstring

markclj

Succeeds with a punctuation mark.

Succeeds with a punctuation mark.
sourceraw docstring

member?clj

(member? x coll)

Tests if x is a member of coll.

Tests if x is a member of coll.
sourceraw docstring

modify-stateclj

(modify-state f & more)

Modify the user state with the result of f, which takes the old user state plus any additional arguments.

Modify the user state with the result of f, which takes the old
user state plus any additional arguments.
sourceraw docstring

new-line*clj

Succeeds on a new line.

Succeeds on a new line.
sourceraw docstring

none-of*clj

(none-of* cs)

Succeeds if the next character is not in the supplied string.

Succeeds if the next character is not in the supplied string.
sourceraw docstring

not-followed-byclj

(not-followed-by p)

Succeeds only if p fails; consumes no input.

Succeeds only if p fails; consumes no input.
sourceraw docstring

oct-digitclj

Parses an octal digit.

Parses an octal digit.
sourceraw docstring

oct-numclj

Parses an octal integer delimited by any character that is not an octal digit.

Parses an octal integer delimited by any character that
is not an octal digit.
sourceraw docstring

one-of*clj

(one-of* cs)

Succeeds if the next character is in the supplied string.

Succeeds if the next character is in the supplied string.
sourceraw docstring

optionclj

(option x p)

Applies p; if it fails without consuming input, it returns a parser state record with the :value x as default.

Applies p; if it fails without consuming input, it returns a
parser state record with the :value x as default.
sourceraw docstring

optionalclj

(optional p)

Succeeds if p succeeds or if p fails without consuming input.

Succeeds if p succeeds or if p fails without consuming input.
sourceraw docstring

parseclj

(parse p cs)
(parse p cs src)
(parse p cs src us)

Parses a character sequence; takes an optional label and a user state initial value, which default to nil. Returns a PState record.

cs A seqable object; parse calls (seq) on this value. src Identifies the source of the text, e.g. a filename. us Initializes a field that is maintained by client code.

Parses a character sequence; takes an optional label and a user
state initial value, which default to nil. Returns a PState record.

cs    A seqable object; parse calls (seq) on this value.
src   Identifies the source of the text, e.g. a filename.
us    Initializes a field that is maintained by client code.
sourceraw docstring

parse-dataclj

(parse-data p cs)
(parse-data p cs src)
(parse-data p cs src us)

Works like (parse) but with error diagnostics disabled for better performance. It's intended for data that can be assumed to be correct or its diagnosis postponed.

Works like (parse) but with error diagnostics disabled for
better performance. It's intended for data that can be
assumed to be correct or its diagnosis postponed.
sourceraw docstring

parse-data-fileclj

(parse-data-file p f)
(parse-data-file p f en)
(parse-data-file p f en us)

Works like (parse-file) but with error diagnostics disabled for better performance. It's intended for data files that can be assumed to be correct or its diagnosis postponed.

Works like (parse-file) but with error diagnostics disabled for
better performance. It's intended for data files that can be
assumed to be correct or its diagnosis postponed.
sourceraw docstring

parse-fileclj

(parse-file p f)
(parse-file p f en)
(parse-file p f en us)

Parses a file; takes an optional encoding and user state, which default to utf-8 and nil. Returns a PState record.

Parses a file; takes an optional encoding and user state,
which default to utf-8 and nil. Returns a PState record.
sourceraw docstring

predictclj

(predict p)

Applies p; if it succeeds it consumes no input.

Applies p; if it succeeds it consumes no input.
sourceraw docstring

(print-error s)

Prints error messages in a PState record.

Prints error messages in a PState record.
sourceraw docstring

put-stateclj

(put-state u)

Put u as the new value for user state in the parser state record.

Put u as the new value for user state in the parser state record.
sourceraw docstring

replyclj

(reply v s)

Makes s succeed with value v.

Makes s succeed with value v.
sourceraw docstring

returnclj

(return v)

Succeeds without consuming any input. Any carried errors are removed.

Succeeds without consuming any input. Any carried errors
are removed.
sourceraw docstring

runclj

(run p cs)
(run p cs src)
(run p cs src us)

For testing parsers, e.g. at the REPL. Calls (parse) on the arguments and prints the result. If p succeeds it prints the parsed value; if it fails it prints any error messages.

For testing parsers, e.g. at the REPL. Calls (parse) on the
arguments and prints the result. If p succeeds it prints the
parsed value; if it fails it prints any error messages.
sourceraw docstring

run*clj

(run* p cs)
(run* p cs src)
(run* p cs src us)

For testing parsers, e.g. at the REPL. Works like (run) but on success it pretty-prints the resulting parser state.

For testing parsers, e.g. at the REPL. Works like (run) but
on success it pretty-prints the resulting parser state.
sourceraw docstring

runfclj

(runf p f)
(runf p f en)
(runf p f en us)

For testing, e.g. at the REPL, with input from files. Prints the results.

For testing, e.g. at the REPL, with input from files.
Prints the results.
sourceraw docstring

runf*clj

(runf* p f)
(runf* p f en)
(runf* p f en us)

For testing, e.g. at the REPL, with input from files. Pretty-prints the results.

For testing, e.g. at the REPL, with input from files.
Pretty-prints the results.
sourceraw docstring

satisfyclj

(satisfy pred)

Succeeds if the next character satisfies the predicate pred, in which case advances the position of the input stream. It may fail on an unexpected end of input.

Succeeds if the next character satisfies the predicate pred,
in which case advances the position of the input stream. It
may fail on an unexpected end of input.
sourceraw docstring

(search p)

Applies a parser p, traversing the input as necessary, until it succeeds or it reaches the end of input.

Applies a parser p, traversing the input as necessary,
until it succeeds or it reaches the end of input.
sourceraw docstring

sep-byclj

(sep-by sep p)

Parses p zero or more times while parsing sep in between; collects the results of p in a vector.

Parses p zero or more times while parsing sep in between;
collects the results of p in a vector.
sourceraw docstring

sep-by1clj

(sep-by1 sep p)

Parses p one or more times while parsing sep in between; collects the results of p in a vector.

Parses p one or more times while parsing sep in between;
collects the results of p in a vector.
sourceraw docstring

sep-end-byclj

(sep-end-by sep p)

Parses p zero or more times separated, and optionally ended by sep; collects the results in a vector.

Parses p zero or more times separated, and optionally ended by sep;
collects the results in a vector.
sourceraw docstring

sep-end-by1clj

(sep-end-by1 sep p)

Parses p one or more times separated, and optionally ended by sep; collects the results in a vector.

Parses p one or more times separated, and optionally ended by sep;
collects the results in a vector.
sourceraw docstring

set-inputclj

(set-input in)

Sets the input stream in a parser state.

Sets the input stream in a parser state.
sourceraw docstring

set-positionclj

(set-position pos)

Sets the position in the input stream of a parser state.

Sets the position in the input stream of a parser state.
sourceraw docstring

skipclj

(skip p)
(skip p q)
(skip p q & more)

Applies one or more parsers and skips the result. That is, it returns a parser state record with a :value nil.

Applies one or more parsers and skips the result. That is, it
returns a parser state record with a :value nil.
sourceraw docstring

skip-manyclj

(skip-many p)

Parses p zero or more times and skips the results. This is like skip but it can apply p zero, one, or many times.

Parses p zero or more times and skips the results. This is
like skip but it can apply p zero, one, or many times.
sourceraw docstring

skip-many1clj

(skip-many1 p)

Parses p one or more times and skips the results.

Parses p one or more times and skips the results.
sourceraw docstring

skip-wsclj

(skip-ws p)

Skips whitespaces before parsing p.

Skips whitespaces before parsing p.
sourceraw docstring

spaceclj

Parses the space character.

Parses the space character.
sourceraw docstring

splitclj

Splits a string on whitespace.

Splits a string on whitespace.
sourceraw docstring

split-onclj

(split-on cs)

Splits a string on one of the given characters and whitespace. Removes empty strings from the result.

Splits a string on one of the given characters and whitespace.
Removes empty strings from the result.
sourceraw docstring

sym*clj

(sym* x)

Parses a single symbol x (a character).

Parses a single symbol x (a character).
sourceraw docstring

sym-clj

(sym- x)

Parses a single symbol x (a character); not case-sensitive.

Parses a single symbol x (a character); not case-sensitive.
sourceraw docstring

tabclj

Parses the tab character.

Parses the tab character.
sourceraw docstring

timesclj

(times n p)

Applies p n times; collects the results in a vector.

Applies p n times; collects the results in a vector.
sourceraw docstring

token*clj

(token* xs)
(token* xs & more)

Parses a specific string, not necessarily delimited. If more than one are given it will try each choice in turn.

Parses a specific string, not necessarily delimited. If more
than one are given it will try each choice in turn.
sourceraw docstring

token-clj

(token- xs)
(token- xs & more)

Parses a specific string, not necessarily delimited; not case-sensitive. If more than one are given it will try each choice in turn.

Parses a specific string, not necessarily delimited; not
case-sensitive. If more than one are given it will try
each choice in turn.
sourceraw docstring

unexpectedclj

(unexpected msg s)

Sets s as failed because an unexpected reason.

Sets s as failed because an unexpected reason.
sourceraw docstring

unexpected-inputclj

(unexpected-input in s)

Sets s as failed because of an unexpected input.

Sets s as failed because of an unexpected input.
sourceraw docstring

upperclj

Parses an upper-case letter.

Parses an upper-case letter.
sourceraw docstring

valueclj

(value p cs)
(value p cs src)
(value p cs src us)

Calls (parse) on the arguments and returns the actual parsed value, not the PState record.

Calls (parse) on the arguments and returns the actual parsed
value, not the PState record.
sourceraw docstring

white-spaceclj

Parses a whitespace character.

Parses a whitespace character.
sourceraw docstring

word*clj

(word* letter cs)
(word* letter cs & more)

Parses a specific string, delimited by letter. If more than one are given it will try each choice in turn.

Parses a specific string, delimited by letter. If more than
one are given it will try each choice in turn.
sourceraw docstring

word-clj

(word- letter cs)
(word- letter cs & more)

Parses a specific string, delimited by letter; not case-sensitive. If more than one are given it will try each choice in turn.

Parses a specific string, delimited by letter; not case-sensitive.
If more than one are given it will try each choice in turn.
sourceraw docstring

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

× close