Liking cljdoc? Tell your friends :D

fr.jeremyschoffen.textp.alpha.reader.core

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 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.
raw docstring

*keep-comments*clj/s

source

*parse-region*clj/s

Stores the parse regions given by instaparse when clojurizing the parse tree.

Stores the parse regions given by instaparse when clojurizing the parse tree.
sourceraw docstring

*wrap-embeded*clj/s

source

clojurizeclj/s

(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.
sourceraw docstring

clojurize*clj/smultimethod

source

clojurize-mixedclj/s

(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.
sourceraw docstring

commentclj/s

Type of a special map for comments

Type of a special map for comments
sourceraw docstring

embedded-codeclj/s

Type of a special map for embedded clojure code

Type of a special map for embedded clojure code
sourceraw docstring

embedded-valueclj/s

Type of a special map for an embedded clojure symbol.

Type of a special map for an embedded clojure symbol.
sourceraw docstring

extract-tagsclj/s

(extract-tags content)
source

form->textclj/s

(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.
sourceraw docstring

inject-clojurized-tagsclj/s

(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.
sourceraw docstring

parseclj/s

(parse text)

Wrapper around the parser from [[textp.reader.grammar]] adding error handling.

Wrapper around the parser from [[textp.reader.grammar]] adding error handling.
sourceraw docstring

read-from-stringclj/s

(read-from-string text)
(read-from-string text opts)

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]])
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*]])
sourceraw docstring

read-from-string*clj/s

(read-from-string* text)
source

read-string*clj/s

(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.
sourceraw docstring

special-tagsclj/s

Set of the different special maps types.

Set of the different special maps types.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close