cl-parser-combinators

API Reference

parser-combinators

An implementation of parser combinators for Common Lisp

PARSER-COMBINATORS

  • Method POSITION-OF ((context-front context-front))
  • Macro COPY-CONTEXT (context class &rest additional-arguments)
  • Generic-Function MAKE-CONTEXT-AT-POSITION (base-context position)
  • Method MAKE-CONTEXT-AT-POSITION ((context context) position)
  • Generic-Function CONTEXT-EQUAL (context1 context2)
  • Method CONTEXT-EQUAL ((context1 context) (context2 context))
  • Method CONTEXT-EQUAL ((context1 context) (context2 context))
  • Method CONTEXT-EQUAL ((context1 context) (context2 context))
  • Generic-Function CONTEXT-INTERVAL (context1 context2 &optional result-type)
  • Method CONTEXT-INTERVAL ((context1 context) (context2 context) &optional (result-type 'string))
  • Method CONTEXT-INTERVAL ((context1 context) (context2 context) &optional (result-type 'string))
  • Method CONTEXT-INTERVAL ((context1 context) (context2 context) &optional (result-type 'string))
  • Method CONTEXT-INTERVAL ((context1 context) (context2 context) &optional result-type)
  • Method CONTEXT-INTERVAL ((context1 context) (context2 context) &optional result-type)
  • Method CONTEXT-INTERVAL ((context1 context) (context2 context) &optional result-type)
  • Class END-CONTEXT  (CONTEXT)
    No slots.
  • Generic-Function END-CONTEXT-P (context)
  • Method END-CONTEXT-P ((context t))
  • Method END-CONTEXT-P ((context t))
  • Method END-CONTEXT-P ((context t))
  • Method MAKE-CONTEXT-AT-POSITION ((base-context list-context) position)
  • Class VECTOR-CONTEXT  (CONTEXT)
    No slots.
  • Method STORAGE-OF ((context vector-context))
  • Method MAKE-CONTEXT-AT-POSITION ((base-context vector-context) position)
  • Method CONTEXT-INTERVAL ((context1 vector-context) (context2 vector-context) &optional (result-type 'string))
  • Method CONTEXT-INTERVAL ((context1 vector-context) (context2 end-context) &optional (result-type 'string))
  • Variable *DEFAULT-CONTEXT-CACHE*
    :vector
  • Generic-Function MAKE-CONTEXT (sequence &optional cache-type)
  • Method MAKE-CONTEXT ((list list) &optional (cache-type *default-context-cache*))
  • Method MAKE-CONTEXT ((vector vector) &optional (cache-type *default-context-cache*))
  • Function DROP-PARSER-CACHE
  • Macro CACHED? (parser label)
    Parser modifier macro: cache parser as label in global cache.
  • Macro DEF-CACHED-PARSER (name &body body)
    Define cached parser of no arguments.
  • Macro CACHED-ARGUMENTS? (parser label &rest arguments)
    Parser modifier macro: cache parser as label with argument list equal under equal in global cache.
  • Macro DEF-CACHED-ARG-PARSER (name arguments &body body)
    Define cached parser with arguments.
  • Class PARSER-POSSIBILITY
    TREE   Accessor: TREE-OF
    SUFFIX   Accessor: SUFFIX-OF
  • Function MAKE-PARSE-RESULT (continuation)
    Document all potential results of CONTINUATION as a PARSE-RESULT object.
  • Function CURRENT-RESULT (parse-result)
  • Function NEXT-RESULT (parse-result)
  • Function GATHER-RESULTS (parse-result)
    Obtain all of the results within PARSE-RESULT, starting with the current one, potentially realising the non-realised ones in the backing store.
  • Macro MDO (&body spec)
    Combinator: use do-like notation to sequentially link parsers. (<- name parser) allows capturing of return values.
  • Function PARSE-SEQUENCE (parser sequence)
    Parse a sequence (where a sequence is any object which implementes CONTEXT interface), return a PARSE-RESULT object. All returned values may share structure.
  • Function PARSE-STRING (parser string)
    Synonym for parse-sequence. Parse a string, return a PARSE-RESULT object. All returned values may share structure.
  • Function PARSE-SEQUENCE* (parser sequence &key (complete nil))
    Parse a sequence (where a sequence is any object which implementes CONTEXT interface) and return as multiple values the first result, whether the parse was incomplete, whether it was successful, the context front and the position frequency table. The context front is an object containing the context which most advances the input sequence and a list of lists of parser tags which were current at that point, which allows approximate error reporting. It will be NIL if the parse is successful and complete. The position frequency table serves profiling needs and maps sequence positions to the number of times a new context was created at that position -- which should provide a rough hint at how problematic that particular spot is. If COMPLETE is T, return the first parse to consume the input completely. If COMPLETE is :FIRST return the first result only when it the whole input was consumed, or immediately return nil.
  • Function PARSE-STRING* (parser string &key (complete nil))
    Synonym for parse-sequence*. Parse a string and return as multiple values the first result, whether the parse was incomplete, whether it was successful, the context front, and the position frequency table. The context front is an object containing the context which most advances the input sequence and a list of lists of parser tags which were current at that point, which allows approximate error reporting. It will be NIL if the parse is successful and complete. The position frequency table serves profiling needs and maps sequence positions to the number of times a new context was created at that position -- which should provide a rough hint at how problematic that particular spot is. If COMPLETE is T, return the first parse to consume the input completely. If COMPLETE is :FIRST return the first result only when it the whole input was consumed, or immediately return nil.
  • Macro DEFINE-ONESHOT-RESULT (inp is-unread &body body)
  • Function SAT (predicate)
    Parser: return a token satisfying a predicate.
  • Function CHAR? (character)
    Parser: accept token eql to argument
  • Generic-Function STRING?-USING-CONTEXT (input vector test)
    Implementation of string? specialized on context type. Returns as multiple values result and new context or nil on failure.
  • Method STRING?-USING-CONTEXT ((input vector-context) vector test)
  • Method STRING?-USING-CONTEXT ((input vector-context) vector test)
  • Method STRING?-USING-CONTEXT ((input vector-context) vector test)
  • Method STRING?-USING-CONTEXT ((input context) vector test)
  • Method STRING?-USING-CONTEXT ((input context) vector test)
  • Method STRING?-USING-CONTEXT ((input context) vector test)
  • Function STRING? (sequence &key (test #'eql) (result-type 'string))
    Non-backtracking parser: accept a sequence of elements with equality tested by TEST.
  • Function CHOICE (parser1 parser2)
    Combinator: all alternatives from two parsers
  • Function CHOICE1 (parser1 parser2)
    Combinator: one alternative from two parsers
  • Function CHOICES (&rest parser-list)
    Combinator: all alternatives from multiple parsers
  • Function CHOICES1 (&rest parser-list)
    Combinator: one alternative from multiple parsers
  • Function RESULT (v)
    Primitive parser: return v, leaves input unmodified.
  • Function ZERO
    Primitive parser: parsing failure
  • Function ITEM
    Primitive parser: consume item from input and return it.
  • Function FORCE? (parser)
    Parser modifier: fully realize result from parser
  • Macro DELAYED? (parser)
    Parser modifier macro: parser will be built when called. This is necessary for left-recursive parsers.
  • Function SEQ-LIST? (&rest parsers)
    Parser: Return a list of results of PARSERS.
  • Macro NAMED-SEQ? (&rest parser-descriptions)
    Parser: This is similar to MDO, except that constructed parsers cannot depend on the results of previous ones and the final form is not used as a parser, but is automatically used to construct the result. All names bound using the (<- name parser) construct are only available in that final form. This parser generator is useful when full generality of MDO is not necessary, as it is implemented non-recursively and has better memory performance.
  • Function TAG? (parser format-control &rest format-arguments)
    Parser modifier: add formatted string to tag stack for given parser.
  • Function CUT-TAG? (parser format-control &rest format-arguments)
    Parser modifier: add formatted string to tag stack for given parser, suppressing all lower level parsers.
  • Function CONTEXT?
    Parser: return current context without consuming any input
  • Function END?
    Parser: matches end of input, returns t
  • Function BETWEEN? (parser min max &optional (result-type 'list))
    Parser: accept between min and max expressions accepted by parser
  • Function MANY? (parser)
    Parser: accept zero or more repetitions of expression accepted by parser
  • Function MANY1? (parser)
    Parser: accept one or more of expression accepted by parser
  • Function TIMES? (parser count)
    Parser: accept exactly count expressions accepted by parser
  • Function ATLEAST? (parser count)
    Parser: accept at least count expressions accepted by parser
  • Function ATMOST? (parser count)
    Parser: accept at most count expressions accepted by parser
  • Function SEPBY1? (parser-item parser-separator)
    Parser: accept at least one of parser-item separated by parser-separator
  • Function BRACKET? (parser-open parser-center parser-close)
    Parser: accept parser-center bracketed by parser-open and parser-close
  • Function SEPBY? (parser-item parser-separator)
    Parser: accept zero or more of parser-item separated by parser-separator
  • Function SEPBY1-CONS? (p op)
    Parser: as sepby1, but returns a list of a result of p and pairs (op p). Mainly a component parser for chains
  • Function CHAINL1? (p op)
    Parser: accept one or more p reduced by result of op with left associativity
  • Function CHAINR1? (p op)
    Parser: accept one or more p reduced by result of op with right associativity
  • Function CHAINL? (p op v)
    Parser: like chainl1?, but will return v if no p can be parsed
  • Function CHAINR? (p op v)
    Parser: like chainr1?, but will return v if no p can be parsed
  • Function BREADTH? (parser min max &optional (result-type 'list))
    Parser: like between? but breadth first (shortest matches first)
  • Function FIND-AFTER? (p q)
    Parser: Find q after some sequence of p, earliest matches first.
  • Function FIND-BEFORE? (p q &optional (result-type 'list))
    Parser: Find a sequence of p terminated by q, doesn't consume q.
  • Function FIND-AFTER-COLLECT? (p q &optional (result-type 'list))
    Parser: Find q after some sequence of p, earliest match first. Return cons of list of p-results and q
  • Function FIND? (q)
    Parser: Find q, earliest match first.
  • Function HOOK? (function p)
    Parser: apply function to result of p
  • Function CHOOK? (result p)
    Parser: return result if p matches
  • Function CHOOKAHEAD? (result p)
    Parser: return result if p matches, but do no advance
  • Function OPT? (p)
    Parser: result of p or nil
  • Function VALIDATE? (p validation-function &optional (pre-hook #'identity))
    Parser: call validation-function on result of (funcall pre-hook p), fail if it returns nil, otherwhise return it as a result
  • Function EXCEPT? (p q)
    Parser: match p unless q matches.
  • Macro NAMED? (name &body body)
    Parser macro: give BODY a NAME, so it can refer to itself without causing generator recursion.
  • Function NESTED? (p &key (min nil) (max nil) (result-type 'list) (bracket-left #\() (bracket-right #\)))
    Parser: parse a sequence of p, like between?, but with p possibly nested in brackets.
  • Function EXPRESSION? (term operators &optional (bracket-left nil) (bracket-right nil))
    Parser: Reduce a sequence of terms with unary/binary operators with precedence. OPERATORS is a list of (op-parser :left/:right/:unary), where OP-PARSER is a parser consuming an operator and returning a reduction function. Highest precedence first.
  • Function MEMOIZE? (parser &optional (label (gensym)))
    Parser modifier: memoizes the parser, which if called again at a given position it will return a result immediately. LABEL is used for memoization key, use explicit one if the parser is used in multiple places.
  • Macro CURTAIL? (name &body body)
    Parser modifier: add recursion curtailing to PARSER, naming the curtailed parser NAME. Left recursive parser parser will only be nested once per remaining length of the input string. Note: this is only necessary for a limited class of left recursive parsers. Non-left recursive parsers should be implemented using just `named?`, and most left-recursive parsers using that in combination with `chainl1?`. Also see `expression?`.
  • Function SEQ-LIST* (&rest parsers)
    Non-backtracking parser: Return a list of result of PARSERS.
  • Macro NAMED-SEQ* (&rest parser-descriptions)
    Non-backtracking parser: This is similar to MDO, except that constructed parsers cannot depend on the results of previous ones and the final form is not used as a parser, but is automatically used to construct the result. All names bound using the (<- name parser) construct are only available in that final form. This parser generator is useful when full generality of MDO is not necessary, as it is implemented non-recursively and has better memory performance.
  • Macro MDO* (&body spec)
    Like NAMED-SEQ*, but with MDO syntax: the last element must be a parser.
  • Function BETWEEN* (parser min max &optional (result-type 'list))
    Non-backtracking parser: find the first, longest chain of expression accepted by parser of length between min and max
  • Function MANY* (parser)
    Non-backtracking parser: collect as many of first result of parser as possible
  • Function MANY1* (parser)
    Non-backtracking parser: accept as many as possible, and at least one, of parser
  • Function ATLEAST* (parser count)
    Non-backtracking parser: accept as many as possible and at least count of parser
  • Function ATMOST* (parser count)
    Non-backtracking parser: accept as many as possible but at most count of parser
  • Function SEPBY1* (parser-item parser-separator)
    Non-backtracking parser: accept as many as possible of parser-item separated by parser-separator, but at least one.
  • Function SEPBY* (parser-item parser-separator)
    Non-backtracking parser: accept as many as possible of parser-item separated by parser-separator.
  • Function CHAINL1* (p op)
    Non-backtracking parser: accept as many as possible, but at least one of p, reduced by result of op with left associativity
  • Function WHITESPACE* (&key (result-type nil) (accept-empty nil))
    Non-backtracking parser: accept a sequence of whitespace characters.
  • Function WORD*
    Parser: accept a string of alphanumeric characters
  • Function PURE-WORD*
    Parser: accept a string of alphabetic characters
  • Function NAT* (&optional (radix 10))
    Non-backtracking parser: accept natural number, consuming as many digits as possible
  • Function INT* (&optional (radix 10))
    Non-backtracking parser: accept integer, consuming as many digits as possible
  • Function CHAINR1* (p op)
    Non-backtracking parser: accept as many as possible, but at least one of p, reduced by result of op with right associativity
  • Function CHAINL* (p op v)
    Non-backtracking parser: like chainl1*, but will return v if no p can be parsed
  • Function CHAINR* (p op v)
    Non-backtracking parser: like chainr1*, but will return v if no p can be parsed
  • Function FIND-AFTER* (p q)
    Non-backtracking parser: Find first q after some sequence of p.
  • Generic-Function GATHER-IF-NOT*-USING-CONTEXT (input predicate accept-end accept-empty)
    Parser gather-if-not* specialized on context type
  • Method GATHER-IF-NOT*-USING-CONTEXT ((input vector-context) predicate accept-end accept-empty)
  • Method GATHER-IF-NOT*-USING-CONTEXT ((input vector-context) predicate accept-end accept-empty)
  • Method GATHER-IF-NOT*-USING-CONTEXT ((input vector-context) predicate accept-end accept-empty)
  • Method GATHER-IF-NOT*-USING-CONTEXT ((input context) predicate accept-end accept-empty)
  • Method GATHER-IF-NOT*-USING-CONTEXT ((input context) predicate accept-end accept-empty)
  • Method GATHER-IF-NOT*-USING-CONTEXT ((input context) predicate accept-end accept-empty)
  • Method GATHER-IF-NOT*-USING-CONTEXT ((input end-context) predicate accept-end accept-empty)
  • Method GATHER-IF-NOT*-USING-CONTEXT ((input end-context) predicate accept-end accept-empty)
  • Method GATHER-IF-NOT*-USING-CONTEXT ((input end-context) predicate accept-end accept-empty)
  • Function GATHER-IF-NOT* (predicate &key (result-type 'list) (accept-end nil) (accept-empty nil))
    Non-backtracking parser: Find a sequence of tokens terminated by one for which predicate returns true, which is not consumed.
  • Function GATHER-BEFORE-TOKEN* (token &key (result-type 'list) (test #'eql) (accept-end nil) (accept-empty nil))
    Non-backtracking parser: Find a sequence of tokens terminated by single token, which is not consumed.
  • Function FIND-BEFORE-TOKEN* (p token &key (result-type 'list) (test #'eql))
    Non-backtracking parser: Find a sequence of p terminated by single token q, which is not consumed.
  • Function FIND-BEFORE* (p q &optional (result-type 'list))
    Non-backtracking parser: Find a sequence of p terminated by q, doesn't consume q.
  • Function FIND-AFTER-COLLECT* (p q &optional (result-type 'list))
    Non-backtracking parser: Find first q after some sequence of p. Return cons of list of p-results and q
  • Function BEFORE* (p q)
    Non-backtracking parser: Find a p before q, doesn't consume q.
  • Function FIND* (q)
    Non-backtracking parser: Find first q
  • Function OPT* (p)
    Non-backtracking parser: result of p or nil
  • Function EXPRESSION* (term operators &optional (bracket-left nil) (bracket-right nil))
    Non-backtracking parser: Reduce a sequence of terms with unary/binary operators with precedence. OPERATORS is a list of (op-parser :left/:right/:unary), where OP-PARSER is a parser consuming an operator and returning a reduction function. Highest precedence first.
  • Function DIGIT?
    Parser: accept digit character
  • Function LOWER?
    Parser: accept lowercase character
  • Function UPPER?
    Parser: accept uppercase character
  • Function LETTER?
    Parser: accept alphabetic character
  • Function ALPHANUM?
    Parser: accept alphanumeric character
  • Function WHITESPACE? (&key (result-type nil) (accept-empty nil))
    Parser: accept a sequence of whitespace characters.
  • Function WORD?
    Parser: accept a string of alphanumeric characters
  • Function PURE-WORD?
    Parser: accept a string of alphabetic characters
  • Function NAT? (&optional (radix 10))
    Parser: accept natural numbers
  • Function INT? (&optional (radix 10))
    Parser: accept an integer, return as integer.
  • Function QUOTED? (&key (quote-char #\") (left-quote-char nil) (right-quote-char nil) (escape-char #\\) (include-quotes t))
    Parser: accept a string delimited with quote-char, possibly escaped by escape-char, possibly including quotation chars.

PARSER-COMBINATORS-DEBUG

No exported symbols.

parser-combinators-cl-ppcre

An implementation of parser combinators for Common Lisp

PARSER-COMBINATORS-CL-PPCRE

  • Generic-Function REGEX*-USING-CONTEXT (inp regex limit return-builder)
  • Method REGEX*-USING-CONTEXT ((inp vector-context) regex limit return-builder)
  • Method REGEX*-USING-CONTEXT ((inp vector-context) regex limit return-builder)
  • Method REGEX*-USING-CONTEXT ((inp vector-context) regex limit return-builder)
  • Method REGEX*-USING-CONTEXT ((inp t) regex limit return-builder)
  • Method REGEX*-USING-CONTEXT ((inp t) regex limit return-builder)
  • Method REGEX*-USING-CONTEXT ((inp t) regex limit return-builder)
  • Function REGEX* (regex &key (limit nil) (return-builder t))
    Non-backtracking parser: regular expression is applied to the input, and a result is constructed by return-builder (default will just return the match) from the result and submatches passed as strings. Passing regex-builder as nil will discard the result (use regex only to advance the input).

parser-combinators-debug

A debug extension for PARSER-COMBINATORS

No packages.