(apply-grammar-update grammar utrek)
Takes a grammar and an map of grammar paths to grammar nodes (an update-trek). Replaces each update path in the grammar ith the new update node.
Takes a grammar and an map of grammar paths to grammar nodes (an update-trek). Replaces each update path in the grammar ith the new update node.
(assoc-in-grammar grammar path value)
Update a grammar node at the given path in grammar to a new value. Like assoc-in for grammars.
Update a grammar node at the given path in grammar to a new value. Like assoc-in for grammars.
(CHILD-EDGE e)
(children-of-node grammar path)
Given a grammar and path node within that grammar return the paths of the children (:alt, :ord, and :cat nodes).
Given a grammar and path node within that grammar return the paths of the children (:alt, :ord, and :cat nodes).
(combine-strings grammar)
Combine strings and spaces that immediately follow each other in a concatenation.
Combine strings and spaces that immediately follow each other in a concatenation.
(comment-trek grammar & [comment-tx])
Return a trek with comment values (map of grammar paths to parsed comments) by reading edn maps from comments in the grammar. Note that this will return different paths than a normal trek because a comments can occur on any :alt/:ord nodes and since comments can occur in internal :alt/:ord nodes a comment trek will have these internal nodes (a regular trek will not).
Multiple comments with edn maps in the same node will be merged into a single map. If the optional comment-tx function is provided it will be applied to the merge maps values.
This requires a patched version of instaparse to retain the comments in the grammar on :comments keys.
Return a trek with comment values (map of grammar paths to parsed comments) by reading edn maps from comments in the grammar. Note that this will return different paths than a normal trek because a comments can occur on any :alt/:ord nodes and since comments can occur in internal :alt/:ord nodes a comment trek will have these internal nodes (a regular trek will not). Multiple comments with edn maps in the same node will be merged into a single map. If the optional comment-tx function is provided it will be applied to the merge maps values. This requires a patched version of instaparse to retain the comments in the grammar on :comments keys.
(get-ancestors grammar path pred)
Returns a vector of paths for which each p in the vector is a parent edge of path in grammar for which (pred p) is true. For example, to find the nearest parent :cat nodes of my-path: (get-ancestors g my-path #(= :cat (last %)))
Returns a vector of paths for which each p in the vector is a parent edge of path in grammar for which (pred p) is true. For example, to find the nearest parent :cat nodes of my-path: (get-ancestors g my-path #(= :cat (last %)))
(get-ancestors* grammar path pred avoid)
(get-descendants grammar path pred)
Return a set of paths for which each p in the set is a descendent of path for which (pred p) is true.
Return a set of paths for which each p in the set is a descendent of path for which (pred p) is true.
(get-descendants* grammar path pred avoid)
(get-in-grammar grammar path)
Get the a grammar node for the given path in grammar. Nil is returned if the path does not exist in the grammar, the tag type along the path don't match, or the numeric parser index is out-of-bounds. Like get-in for grammars.
Get the a grammar node for the given path in grammar. Nil is returned if the path does not exist in the grammar, the tag type along the path don't match, or the numeric parser index is out-of-bounds. Like get-in for grammars.
(get-weighted-ancestors grammar path)
(grammar->ebnf grammar)
Takes a grammar and returns the EBNF string equivalent of that grammar.
Takes a grammar and returns the EBNF string equivalent of that grammar.
(grammar->parser grammar & [start])
Takes a grammar and returns a instaparse parser. The start production must either be set on the grammar metadata (by parser->grammar) or must be explicitly provided.
Takes a grammar and returns a instaparse parser. The start production must either be set on the grammar metadata (by parser->grammar) or must be explicitly provided.
(load-grammar ebnf)
Takes an EBNF grammar test string and returns an instacheck grammar (via parser->grammar).
Takes an EBNF grammar test string and returns an instacheck grammar (via parser->grammar).
(load-parser ebnf)
Takes an EBNF grammar test string and returns an instacheck parser.
Takes an EBNF grammar test string and returns an instacheck parser.
(ntrek grammar)
Return a ntrek (node trek) of the grammar (map of paths to leaf nodes).
Return a ntrek (node trek) of the grammar (map of paths to leaf nodes).
(ntrek->grammar ntrek)
Take an ntrek (node trek) and convert it back into a grammar
Take an ntrek (node trek) and convert it back into a grammar
(parser->grammar parser)
Takes a instaparse parser and returns an instacheck grammar: the :grammar value from the parser with a metadata map containing the start rule (:start).
Takes a instaparse parser and returns an instacheck grammar: the :grammar value from the parser with a metadata map containing the start rule (:start).
(paths-to-leaf grammar leaf-val)
Given a grammar and a non-terminal keyword nt, return all paths within the grammar that have nt as a leaf node.
Given a grammar and a non-terminal keyword nt, return all paths within the grammar that have nt as a leaf node.
(TERMINAL v)
(trek grammar)
Return a trek (value trek) of the grammar (map of paths to node values).
Return a trek (value trek) of the grammar (map of paths to node values).
(trek->grammar trek)
Take a trek (value trek) and convert it back into a grammar
Take a trek (value trek) and convert it back into a grammar
(trek-grammar grammar tx)
Walk a grammar graph applying tx at each path/node
Walk a grammar graph applying tx at each path/node
(update-in-grammar grammar [rule-kw & rest-path :as path] f & args)
Update a grammar node at the given path in the grammar by running (apply f node args) on the node and returning the update grammar. Like update-in for grammars.
Update a grammar node at the given path in the grammar by running (apply f node args) on the node and returning the update grammar. Like update-in for grammars.
(walk-grammar grammar f)
Breadth-first walk a grammar transforming it by applying f at each path/node
Breadth-first walk a grammar transforming it by applying f at each path/node
(walk-grammar* node path f)
Internal: Breadth-first walk a grammar tree transforming it by applying f at each path/node
Internal: Breadth-first walk a grammar tree transforming it by applying f at each path/node
(walk-grammar-rule tree rule f)
Breadth-first walk a grammar rule transforming it by applying f at each path/node
Breadth-first walk a grammar rule transforming it by applying f at each path/node
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close