(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 node-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-wtrek grammar & [comment-tx])
Return a wtrek 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 wtrek 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 wtrek 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 wtrek 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.
(filter-trek-weighted trek)
Given trek, only keep paths that refer to weighted nodes (:alt, :ord, :opt, :star). In a generator context, these are the nodes that use (igen/freq).
Given trek, only keep paths that refer to weighted nodes (:alt, :ord, :opt, :star). In a generator context, these are the nodes that use (igen/freq).
(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).
(path-log-trek grammar parse-result)
Takes a grammar and parse-result parsed using that grammar and returns a path-log trek based on the :path-log in parse-result. Note that this will return a different set of paths than a normal trek or wtrek because it contains "weights" for all nodes of the grammar and not just for leaf or weighted nodes.
Takes a grammar and parse-result parsed using that grammar and returns a path-log trek based on the :path-log in parse-result. Note that this will return a different set of paths than a normal trek or wtrek because it contains "weights" for all nodes of the grammar and not just for leaf or weighted nodes.
(path-log-wtrek grammar parse-result)
Takes a grammar and parse-result parsed using that grammar and returns a wtrek with weights set based on the :path-log in parse-result. Note that this will return different paths than a normal trek because a wtrek contains all weighted nodes (:alt, :ord, :opt, :star) from the grammar not just leaf nodes.
Takes a grammar and parse-result parsed using that grammar and returns a wtrek with weights set based on the :path-log in parse-result. Note that this will return different paths than a normal trek because a wtrek contains all weighted nodes (:alt, :ord, :opt, :star) from the grammar not just leaf nodes.
(paths-to-nt grammar nt)
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.
(removed-node? grammar weights path)
Takes path to a grammar node and returns true if all the child weights of this node are 0. Only paths ending in :alt, :ord, :opt, and :star can have child weights).
Takes path to a grammar node and returns true if all the child weights of this node are 0. Only paths ending in :alt, :ord, :opt, and :star can have child weights).
(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
(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.
(wtrek grammar & [default-weight])
Takes a grammar and returns a wtrek/weight trek (map of grammar paths to weight values). If the node at a path has a comment with a :weight specification then this will be used for the weight otherwise the default-weight parameter will be used (with a default of 100). Note that this will return different paths than a normal trek because a wtrek contains all weighted nodes (:alt, :ord, :opt, :star) from the grammar not just leaf nodes.
Takes a grammar and returns a wtrek/weight trek (map of grammar paths to weight values). If the node at a path has a comment with a :weight specification then this will be used for the weight otherwise the default-weight parameter will be used (with a default of 100). Note that this will return different paths than a normal trek because a wtrek contains all weighted nodes (:alt, :ord, :opt, :star) from the grammar not just leaf nodes.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close