This namespaces provides a reader that combines our grammar and clojure's reader to turn a string of text into data clojure can then evaluate.
The reader starts by parsing the text using our grammar then returns a clojurized version of the parse tree.
The different syntactic elements are processed as follows:
The reader can wrap comment/embedded clojure in maps if indicated to. These maps have 2 keys:
type
: a marker explaining the kind of special value the map representsdata
: the actual value being wrapped, the content of a comment or the embedded clojure code.This model is consistent with the way https://github.com/cgrand/enlive treats dtd elements for instance. This may allow for uniform processing when generating html for instance.
This namespaces provides a reader that combines our grammar and clojure's reader to turn a string of text into data clojure can then evaluate. ## Reader results The reader starts by parsing the text using our grammar then returns a *clojurized* version of the parse tree. The different syntactic elements are processed as follows: - text -> string - tag -> clojure fn call - verbatim block -> string containing the verbatim block's content. - comments -> empty string or special map containing the comment depending on [[textp.reader.alpha.core/*keep-comments*]] - embedded clojure -> drop in clojure code or a map containing the code depending on [[textp.reader.alpha.core/*wrap-embedded*]] ## Special maps The reader can wrap comment/embedded clojure in maps if indicated to. These maps have 2 keys: - `type`: a marker explaining the kind of special value the map represents - `data`: the actual value being wrapped, the content of a comment or the embedded clojure code. This model is consistent with the way [https://github.com/cgrand/enlive](enlive) treats dtd elements for instance. This may allow for uniform processing when generating html for instance.
Stores the parse regions given by instaparse when clojurizing the parse tree.
Stores the parse regions given by instaparse when clojurizing the parse tree.
(clojurize form)
Function that turns a textp parse tree to data that clojure can eval. clojure form that are clojurized have parse info in their metadata.
Function that turns a textp parse tree to data that clojure can eval. clojure form that are clojurized have parse info in their metadata.
(clojurize-mixed content)
The basic content of an embedded code block is a sequence of strings and tags. These tags can't be read by the clojure reader.
To turn that block into clojure data, the trick is to replace the tags by place-holder strings that will be read as symbols. We can then use the clojure(script) reader on the result. Next we walk the code that's now data and replace those symbols with the clojurized tags.
The basic content of an embedded code block is a sequence of strings and tags. These tags can't be read by the clojure reader. To turn that block into clojure data, the trick is to replace the tags by place-holder strings that will be read as symbols. We can then use the clojure(script) reader on the result. Next we walk the code that's now data and replace those symbols with the clojurized tags.
Type of a special map for comments
Type of a special map for comments
Type of a special map for embedded clojure code
Type of a special map for embedded clojure code
Type of a special map for an embedded clojure symbol.
Type of a special map for an embedded clojure symbol.
(form->text form original)
Given a form and the original text, finds the part of the text that read as this form.
Given a form and the original text, finds the part of the text that read as this form.
(inject-clojurized-tags form env)
Walks the clojurized block and replaces placeholder symbols by the clojurized content.
Walks the clojurized block and replaces placeholder symbols by the clojurized content.
(parse text)
Wrapper around the parser from [[textp.reader.grammar]] adding error handling.
Wrapper around the parser from [[textp.reader.grammar]] adding error handling.
(read-from-string text)
(read-from-string text opts)
Args:
text
: string we want to readopts
: a :map specifying optionsOptions:
:keep-comments
: boolean defaulting to false. Indicates to the reader to keep the comments instead of
replacing them by an empty-string. (see [[textp.reader.alpha.core/keep-comments]]):wrap-embedded
: boolean defaulting to false. indicates to the reader to wrap the embeded clojure code/values
to be wrapped in a special map instead of being left as is in the result of the read.
(see [[textp.reader.alpha.core/wrap-embeded]])Args: - `text`: string we want to read - `opts`: a :map specifying options Options: - `:keep-comments`: boolean defaulting to false. Indicates to the reader to keep the comments instead of replacing them by an empty-string. (see [[textp.reader.alpha.core/*keep-comments*]]) - `:wrap-embedded`: boolean defaulting to false. indicates to the reader to wrap the embeded clojure code/values to be wrapped in a special map instead of being left as is in the result of the read. (see [[textp.reader.alpha.core/*wrap-embeded*]])
(read-string* s)
Wrapping of clojure(script)'s read-string function for use in our reader.
Wrapping of clojure(script)'s read-string function for use in our reader.
Set of the different special maps types.
Set of the different special maps types.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close