(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.
(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).
(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-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-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.
(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.
(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.
(trek grammar)
Return a trek of the grammar (map of paths to node values).
Return a trek of the grammar (map of paths to node values).
(trek->grammar trek)
Take a trek and convert it back into a grammar
Take a 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.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close