std.block.parse

*dispatch-options*

dynamic

*end-delimiter*

dynamic

*hash-dispatch*

dynamic

*hash-options*

dynamic

*symbol-allowed*

dynamic

-parse

multimethod

added in 3.0

extendable parsing function

(base/block-info (-parse (reader/create “:a”))) => {:type :token, :tag :keyword, :string “:a”, :height 0, :width 2}

(base/block-info (-parse (reader/create “"
"”))) => {:type :token, :tag :string, :string “"
"”, :height 0, :width 4}

(base/block-info (-parse (reader/create “"\n"”))) => {:type :token, :tag :string, :string “"\n"”, :height 1, :width 1}

delimiter-block?

added in 3.0

(delimiter-block? block)

checks if block is of tag :delimiter

(delimiter-block? (binding end-delimiter (first “}”) (-parse (reader/create “}”)))) => true

eof-block?

added in 3.0

(eof-block? block)

checks if block is of tag :eof

(eof-block? (-parse (reader/create ""))) => true

parse-collection

added in 3.0

(parse-collection reader tag)

parses a collection

(-> (parse-collection (reader/create “#(+ 1 2 3 4)”) :fn) (base/block-value)) => ’(fn* [](+ 1 2 3 4))

(-> (parse-collection (reader/create “(1 2 3 4)”) :list) (base/block-value)) => ’(1 2 3 4)

(-> (parse-collection (reader/create “1 2 3 4”) :vector) (base/block-value)) => 1 2 3 4

(-> (parse-collection (reader/create “{1 2 3 4}”) :map) (base/block-value)) => {1 2, 3 4}

(-> (parse-collection (reader/create “#{1 2 3 4}”) :set) (base/block-value)) => #{1 4 3 2}

parse-comment

added in 3.0

(parse-comment reader)

creates a comment

(-> (reader/create “;this is a comment”) parse-comment (base/block-info)) => {:type :comment, :tag :comment, :string “;this is a comment”, :height 0, :width 18}

parse-cons

added in 3.0

(parse-cons reader tag)

parses a cons

(-> (parse-cons (reader/create “~hello”) :unquote) (base/block-value)) => ’(unquote hello)

(-> (parse-cons (reader/create “~@hello”) :unquote-splice) (base/block-value)) => ’(unquote-splicing hello)

(-> (parse-cons (reader/create “^tag {:a 1}”) :meta) (base/block-value) ((juxt meta identity))) => {:tag ’tag} {:a 1}

(-> (parse-cons (reader/create “@hello”) :deref) (base/block-value)) => ’(deref hello)

(-> (parse-cons (reader/create “`hello”) :syntax) (base/block-value)) => ’(quote std.block.parse-test/hello)

parse-first

added in 4.0

(parse-first string)

gets the first element in root

(str (parse-first “a b c”)) => “a”

parse-hash

added in 3.0

(parse-hash reader)

parses a block starting with # from the reader

(-> (parse-hash (reader/create “#{1 2 3}”)) (base/block-value)) => #{1 2 3}

(-> (parse-hash (reader/create “#(+ 1 2)”)) (base/block-value)) => ’(fn* [](+ 1 2))

parse-hash-cursor

added in 3.0

(parse-hash-cursor reader)

parses the hash-cursor string

(str (parse-hash-cursor (reader/create “#|”))) => “|”

parse-hash-uneval

added in 3.0

(parse-hash-uneval reader)

parses the hash-uneval string

(str (parse-hash-uneval (reader/create “#_”))) => “#_”

parse-keyword

added in 3.0

(parse-keyword reader)

reads a keyword block from the reader

(-> (reader/create “:a/b”) (parse-keyword) (base/block-value)) => :a/b

(-> (reader/create “::hello”) (parse-keyword) (base/block-value)) => (keyword “:hello”)

parse-non-expressions

added in 3.0

(parse-non-expressions reader)

parses whitespace until next token

(str (parse-non-expressions (reader/create " \na"))) => “(␣
) a

parse-reader

added in 3.0

(parse-reader reader)

reads a :char block from the reader

parse-root

added in 3.0

(parse-root s)

parses a root

(str (parse-root “a b c”)) => “a b c”

parse-select

added in 3.0

(parse-select reader)

parses a block starting with #? from the reader

(-> (parse-select (reader/create “#?(:cljs a)”)) (base/block-value)) => ’(? {:cljs a})

(-> (parse-select (reader/create “#?@(:cljs a)”)) (base/block-value)) => ’(?-splicing {:cljs a})

parse-string

added in 3.0

(parse-string s)

parses a block from a string input

(-> (parse-string “#(:b {:b 1})”) (base/block-value)) => ’(fn* {(keyword “b”) 1}))

parse-token

added in 3.0

(parse-token reader)

reads token block from the reader

(-> (reader/create “abc”) (parse-token) (base/block-value)) => ’abc

(-> (reader/create “3/5”) (parse-token) (base/block-value)) => 3/5

parse-unquote

added in 3.0

(parse-unquote reader)

parses a block starting with ~ from the reader

(-> (parse-unquote (reader/create “~hello”)) (base/block-value)) => ’(unquote hello)

(-> (parse-unquote (reader/create “~@hello”)) (base/block-value)) => ’(unquote-splicing hello)

parse-void

added in 3.0

(parse-void reader)

reads a void block from reader

(->> (reader/read-repeatedly (reader/create " \t\n\f") parse-void eof-block?) (take 5) (map str)) => “␣” "\ " "
" "\ "

read-collection

added in 3.0

(read-collection reader start end-delimiter)

reads all children, taking a delimiter as option

(->> (read-collection (reader/create “(1 2 3 4 5)”) “(” (first “)”)) (apply str)) => “1␣2␣3␣4␣5”

read-cons

added in 3.0

(read-cons reader start)(read-cons reader start n)

helper method for reading (->> (read-cons (reader/create “@hello”) “@”) (map base/block-string)) => ’(“hello”)

(->> (read-cons (reader/create “^hello {}”) “^” 2) (map base/block-string)) => ’(“hello” " " “{}”)

read-dispatch

added in 3.0

(read-dispatch ch)

dispatches on first symbol

(read-dispatch \tab) => :void

(read-dispatch (first “#”)) => :hash

read-start

added in 3.0

(read-start reader start)

helper to verify that the beginning has been read

(read-start (reader/create “~@”) “~#”) => (throws)

read-string-data

added in 3.0

(read-string-data reader)

reads string data from the reader

(read-string-data (reader/create “"hello"”)) => “hello”

read-whitespace

added in 3.0

(read-whitespace reader)

reads whitespace blocks as vector

(count (read-whitespace (reader/create " "))) => 3