Create a parser based on a string grammar. The grammar is translated into combinators.
Create a parser based on a string grammar. The grammar is translated into combinators.
(create-parser text)
(create-parser text other-parsers)
Create a parser based on a string-based grammar definition. If the definition contains multiple rules, a map of parsers is returned. The following definition describes the string grammar syntax in itself:
space <- [\s]*
non-terminal= <- [a-zA-Z_-]+
literal <- '\'' > (:literal #'(\\\'|[^\'])*') '\''
character-class= <- '[' > #'(\\]|[^]])*' ']' [?*+]?
regex= <- '#' > literal
ref <- (non-terminal !'=' space !'<-')
end-of-file= <- '$'
group-name <- ':' > (:group-name [a-zA-Z_-]+)
group= <- '(' > group-name? space choice space ')'
expr <- ref / group / literal / character-class / end-of-file / regex
quantified <- (:quantified expr (:operand [?+*])) / expr
lookahead <- (:lookahead (:operand [&!]) > quantified) / quantified
cut= <- '>>' / '>'
chain <- (:chain lookahead (space (cut / lookahead))+) / lookahead
choice <- (:choice chain (space '/' space chain)+) / chain
rule= <- (:rule-name non-terminal '='?) space '<-' >> space choice
root= <- (:rules (space rule space)+) / (:no-rules space choice space) $
To capture nodes in the parse result, you need to use named groups.
If you postfix a rule name with =
, the expression is automatically
captured using the rule's name (without the postfix). Please read up
on this at crustimoney.combinators/grammar
.
A map of existing parsers can be supplied, which can be used by the string grammar. For example:
(create-parser "root <- 'Hello ' email"
{:email (regex "...")})
Create a parser based on a string-based grammar definition. If the definition contains multiple rules, a map of parsers is returned. The following definition describes the string grammar syntax in itself: space <- [\s]* non-terminal= <- [a-zA-Z_-]+ literal <- '\'' > (:literal #'(\\\'|[^\'])*') '\'' character-class= <- '[' > #'(\\]|[^]])*' ']' [?*+]? regex= <- '#' > literal ref <- (non-terminal !'=' space !'<-') end-of-file= <- '$' group-name <- ':' > (:group-name [a-zA-Z_-]+) group= <- '(' > group-name? space choice space ')' expr <- ref / group / literal / character-class / end-of-file / regex quantified <- (:quantified expr (:operand [?+*])) / expr lookahead <- (:lookahead (:operand [&!]) > quantified) / quantified cut= <- '>>' / '>' chain <- (:chain lookahead (space (cut / lookahead))+) / lookahead choice <- (:choice chain (space '/' space chain)+) / chain rule= <- (:rule-name non-terminal '='?) space '<-' >> space choice root= <- (:rules (space rule space)+) / (:no-rules space choice space) $ To capture nodes in the parse result, you need to use named groups. If you postfix a rule name with `=`, the expression is automatically captured using the rule's name (without the postfix). Please read up on this at `crustimoney.combinators/grammar`. A map of existing parsers can be supplied, which can be used by the string grammar. For example: (create-parser "root <- 'Hello ' email" {:email (regex "...")})
(vector-tree text)
Low-level function which translates the string grammar into an
intermediary vector-based representation. See
crustimoney.vector-grammar
for more on this format. This can be
useful for debugging.
Low-level function which translates the string grammar into an intermediary vector-based representation. See `crustimoney.vector-grammar` for more on this format. This can be useful for debugging.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close