No matching definitions.

dom/core

src/dom/core.tur

the shared Document / Node vocabulary for tur-xml and tur-html.

Since: 0.1.0

defopaque

Document

(Document)

an owned parsed tree. Owns every Node and every borrowed cstr

defopaque

Node

(Node)

a borrowed handle to one node of a Document. Dangles once its

defstruct

SourcePos

(defstruct SourcePos :copy [line : int col : int])

a 1-based line and byte column in the parser's input.

defn

syntax-kind

(syntax-kind :)

the shared Syntax node.

ParseErrorKind -- the shared Syntax node.

(ParseError (syntax-kind) (from-cstr "mismatched tag") 3 7)

Since: 0.1.0

defn

limit-kind

(limit-kind :)

the shared Limit node (see syntax-kind).

defn

refused-kind

(refused-kind :)

the shared Refused node (see syntax-kind).

defn

io-kind

(io-kind :)

the shared Io node (see syntax-kind).

defstruct

ParseError

(defstruct ParseError :copy [kind : ParseErrorKind msg : String line : int col : int])

why a parse failed and where.

defn

parse-error-pos

(parse-error-pos [e : ParseError] :)

where a ParseError happened.

ethe error

SourcePos -- 1-based line and byte column; (SourcePos 0 0) when the error has no position (an Io error).

(.line (parse-error-pos e))   ; => 3

Since: 0.1.0

defn

parse-error-message

(parse-error-message [e : ParseError] :)

borrow the message of a ParseError.

ethe error

cstr -- valid until `parse-error-release`.

(println (parse-error-message e))   ; e.g. "mismatched tag"

Since: 0.1.0

defn

parse-error-release

(parse-error-release [e : ParseError] :)

release the String a ParseError owns.

ethe error, not used afterwards
(parse-error-release e)

Since: 0.1.0

defn

dom-root

(dom-root [d : Document] :)

the document element (the outermost element).

dthe document

(Option Node) -- none only for a document with no element at all (an empty HTML fragment, say).

(match (dom-root d)
    (Some r) (node-name r)   ; => (Some "feed")
    (None)   (None))

Since: 0.1.0

defn

dom-node

(dom-node [d : Document] :)

the document node itself (kind DocumentNode).

dthe document

Node -- the invisible root.

(node-children (dom-node d))   ; => doctype, comments, root element

Since: 0.1.0

defn

dom-free

(dom-free [d : Document] :)

release a document and everything it owns.

dthe document, not used afterwards
(dom-free d)

Since: 0.1.0

defn

dom-node-count

(dom-node-count [d : Document] :)

how many nodes the document holds (the document node

dthe document

int -- elements, text, comments, CDATA, PIs and doctypes together.

(dom-node-count d)   ; => 3 for <a>x<b/></a>

Since: 0.1.0

defn

dom-live-bytes

(dom-live-bytes :)

arena bytes held by every live Document in the process.

int -- bytes, including each arena chunk's header.

(let [before (dom-live-bytes)]
    (dom-free (ok-val (dom-parse-string "<a/>")))
    (= before (dom-live-bytes)))   ; => true

Since: 0.1.0

defn

node-kind

(node-kind [n : Node] :)

what kind of node this is.

nthe node

NodeKind

(match (node-kind n) (ElementNode) "element" (TextNode) "text" ...)

Since: 0.1.0

defn

node-element?

(node-element? [n : Node] :)

is this node an element?

nthe node

bool

(node-element? (dom-node d))   ; => false (the document node)

Since: 0.1.0

defn

node-name

(node-name [n : Node] :)

the name of an element, PI target, or doctype.

nthe node

(Option cstr) -- borrowed from the document; none for text, comment, CDATA and document nodes.

(node-name root)   ; => (Some "rss")

Since: 0.1.0

defn

node-local-name

(node-local-name [n : Node] :)

an element's name without its namespace prefix.

nthe node

(Option cstr) -- `link` for `<atom:link>`; none for non-elements.

(node-local-name n)   ; => (Some "link")

Since: 0.1.0

defn

node-ns-uri

(node-ns-uri [n : Node] :)

an element's namespace URI.

nthe node

(Option cstr) -- none for an element in no namespace, and for non-elements.

(node-ns-uri feed)   ; => (Some "http://www.w3.org/2005/Atom")

Since: 0.1.0

defn

node-value

(node-value [n : Node] :)

the character data of a text, comment, CDATA or PI node.

nthe node

(Option cstr) -- borrowed from the document; none for elements, the doctype and the document node.

(match (node-first-child p)          ; <p>hello</p>
    (Some t) (node-value t)            ; => (Some "hello")
    (None)   (None))

Since: 0.1.0

defn

node-text

(node-text [n : Node] :)

the text of a node and all its descendants, concatenated.

nthe node

String -- owned; release it when done.

(node-text p)   ; => "abc" for <p>a<b>b</b>c</p>

Since: 0.1.0

defn

node-attr

(node-attr [n : Node name : cstr] :)

look up an element's attribute by name.

nthe element
namethe attribute name

(Option cstr) -- borrowed from the document; none when absent or when `n` is not an element.

(node-attr link "href")   ; => (Some "https://example.com/")

Since: 0.1.0

defn

node-attr-count

(node-attr-count [n : Node] :)

how many attributes an element has.

nthe node

int -- 0 for non-elements.

(node-attr-count (dom-root d))   ; => 2 for <a x="1" y="2"/>

Since: 0.1.0

defn

node-attr-name-at

(node-attr-name-at [n : Node i : int] :)

the name of an element's i-th attribute (document

nthe element
i0 <= i < (node-attr-count n)

(Option cstr) -- borrowed; none when out of range.

(node-attr-name-at el 0)   ; => (Some "x")

Since: 0.1.0

defn

node-attr-value-at

(node-attr-value-at [n : Node i : int] :)

the value of an element's i-th attribute.

nthe element
i0 <= i < (node-attr-count n)

(Option cstr) -- borrowed; none when out of range.

(node-attr-value-at el 0)   ; => (Some "1")

Since: 0.1.0

defn

node-parent

(node-parent [n : Node] :)

the node's parent.

nthe node

(Option Node) -- the root element's parent is the document node; the document node has none.

(node-parent title)   ; => (Some head)

Since: 0.1.0

defn

node-first-child

(node-first-child [n : Node] :)

the node's first child.

nthe node

(Option Node) -- none for a leaf.

(node-first-child (dom-node d))

Since: 0.1.0

defn

node-last-child

(node-last-child [n : Node] :)

the node's last child.

nthe node

(Option Node) -- none for a leaf.

(node-last-child body)

Since: 0.1.0

defn

node-next-sibling

(node-next-sibling [n : Node] :)

the next node under the same parent.

nthe node

(Option Node) -- none for the last child.

(node-next-sibling item)

Since: 0.1.0

defn

node-prev-sibling

(node-prev-sibling [n : Node] :)

the previous node under the same parent.

nthe node

(Option Node) -- none for the first child.

(node-prev-sibling item)

Since: 0.1.0

defn

node-child-count

(node-child-count [n : Node] :)

how many children the node has.

nthe node

int

(node-child-count (dom-node d))

Since: 0.1.0

defn

node-children

(node-children [n : Node] :)

the node's children, in document order.

nthe node

(Cons Node) -- `(tnil)` for a leaf.

(tlength (node-children root))   ; => 3

Since: 0.1.0

defn

node-document

(node-document [n : Node] :)

the Document that owns this node.

nthe node

Document -- the same handle `dom-free` takes.

(dom-free (node-document root))

Since: 0.1.0

defn

node-pos

(node-pos [n : Node] :)

where the node started in the source.

nthe node

(Option SourcePos) -- XML nodes carry their start position; HTML nodes and the document node do not (lexbor's tree does not record them).

(node-pos item)   ; => (Some (SourcePos 4 3))

Since: 0.1.0

defn

node-depth

(node-depth [n : Node] :)

how many ancestors the node has.

nthe node

int -- 0 for the document node, 1 for the root element.

(node-depth (dom-node d))   ; => 0

Since: 0.1.0

defn

node-matches?

(node-matches? [n : Node name : cstr] :)

is `n` an element that answers to `name`?

nthe node
namethe name to test

bool -- false for every non-element.

(node-matches? n "{http://www.w3.org/2005/Atom}entry")

Since: 0.1.0

defn

find-all

(find-all [n : Node tag : cstr] :)

every descendant element named `tag`, in document order.

nwhere to search (often `(dom-node d)` for the whole document)
tagthe element name

(Cons Node) -- `(tnil)` when nothing matches.

(tlength (find-all (dom-node d) "item"))   ; => number of <item>s

Since: 0.1.0

defn

find-first

(find-first [n : Node tag : cstr] :)

the first descendant element named `tag`, in document order.

nwhere to search
tagthe element name (as in `find-all`)

(Option Node) -- none when nothing matches.

(find-first (dom-node d) "title")

Since: 0.1.0

defn

dom-serialize

(dom-serialize [n : Node] :)

markup for a node and its subtree.

nthe node (an element, the document node, or any leaf)

String -- owned; release it when done.

(to-cstr (dom-serialize root))   ; => "<a x=\"1\"><b/></a>"

Since: 0.1.0

defn

dom-equal?

(dom-equal? [a : Node b : Node] :)

are two subtrees structurally equal?

aa node
banother node, possibly from another document

bool

(dom-equal? (dom-node d1) (dom-node d2))

Since: 0.1.0

Internal definitions
__null?-- internal: is this a null pointer?
__null-ptr-- internal: the null pointer.
__null-cstr?-- internal: is this a null cstr?
__opt-node-- internal: a nullable node pointer as an (Option Node).
__opt-cstr-- internal: a nullable borrowed cstr as an (Option cstr).
__doc-node-raw-- internal: the document's invisible root node.
__root-raw-- internal: the root element, or NULL.
__kind-raw-- internal: the C kind code.
__name-raw-- internal: the C name, or NULL.
__local-raw-- internal: the C local name, or NULL.
__ns-raw-- internal: the C namespace URI, or NULL.
__value-raw-- internal: the C character data, or NULL.
__text-raw-- internal: malloc'd concatenated text.
__attr-raw-- internal: the attribute value, or NULL.
__attr-name-at-raw-- internal: i-th attribute name, or NULL.
__attr-value-at-raw-- internal: i-th attribute value, or NULL.
__parent-raw-- internal.
__first-child-raw-- internal.
__last-child-raw-- internal.
__next-raw-- internal.
__prev-raw-- internal.
__children-acc-- internal: build the child list back to front.
__doc-of-raw-- internal.
__line-raw-- internal.
__col-raw-- internal.
__find-prev-raw-- internal: previous match in reverse document order.
__find-next-raw-- internal: next match in document order.
__find-all-acc-- internal: collect matches back to front.
__serialize-raw-- internal: malloc'd markup.