xml.bend relies on unsafe/foreign
raw source on the hub · import gralha-xml-doc@0.1.0.1/xml.bend as Xml
XML: tokens, element tree, entities, attributes and serialization.
2 imports
import Base import gralha-text-scan@0.1.0.1/scan.bend as U
Types
type Step source · line 22 · raw
Data
One step of the decoding reversal: kind 0 a plain character, 1 an entity (its name collected backwards up to the '&'), 2 a ';' that began no entity (the collected text stays as it was), 3 the end.
Step@kind:U32 -> @ch:U32 -> @name:String -> @rest:String -> Step
type Attr source · line 121 · raw
Data
Attr@key:String -> @val:String -> Attr
type Tag source · line 124 · raw
Data
Tag@attrs:List<&2, Attr> -> @tail:String -> @closed:Bool -> Tag
type Next source · line 134 · raw
Data
Next@kind:U32 -> @ch:U32 -> @attrs:List<&2, Attr> -> @tail:String -> Next
type Token source · line 173 · raw
Data
Open@name:String -> @attrs:List<&2, Attr> -> @closed:Bool -> Token
Shut@name:String -> Token
Chars@content:String -> Token
type Lexeme source · line 178 · raw
Data
Lexeme@token:Token -> @tail:String -> Lexeme
type Element source · line 232 · raw
Data
Element@name:String -> @attrs:List<&2, Attr> -> @children:List<&2, Element> -> @text:String -> Element
type Taken source · line 391 · raw
Data
One attribute's value taken out of the list, so its text has a single owner; "" and the untouched list when absent.
Taken@value:String -> @rest:List<&2, Attr> -> Taken
Definitions
def entity.push source · line 8 · raw
@+e:String -> @+out:String -> String
Reverse a scan's accumulator while decoding XML entities: the reversed text shows an entity as its ';' first, then its name backwards, then '&'; a ';' without a short name and '&' behind it is plain text.
def entity.of source · line 13 · raw
@+name:String -> String
def rev.next.at source · line 36 · raw
@semi:Bool -> @+ch:U32 -> @t:String -> Step
def rev.next source · line 41 · raw
@s:String -> Step
def rev.decode source · line 58 · raw
@s:String -> @+out:String -> String
def until.decoded source · line 73 · raw
@s:String -> @+end:U32 -> @acc:String -> 0x2370002bb215388f2e71cae632c87c34/scan.Scan
def name.stop source · line 80 · raw
@+c:U32 -> Bool
def xml.name source · line 96 · raw
@s:String -> @acc:String -> 0x2370002bb215388f2e71cae632c87c34/scan.Scan
def value.go source · line 103 · raw
@quoted:Bool -> @+ch:U32 -> @rest:String -> 0x2370002bb215388f2e71cae632c87c34/scan.Scan
def value source · line 108 · raw
@s:String -> 0x2370002bb215388f2e71cae632c87c34/scan.Scan
def equals source · line 115 · raw
@s:String -> 0x2370002bb215388f2e71cae632c87c34/scan.Scan
def attr.kind source · line 131 · raw
@+c:U32 -> U32
The parse position after an attribute: the kind of the next character (see attr.kind; 4 at the end of the text) with the attributes so far. What a character starts inside a tag: 0 space, 1 the end of the tag, 2 a self-closing slash, 3 an attribute.
def next.of source · line 137 · raw
@attrs:List<&2, Attr> -> @tail:String -> Next
def attr.append source · line 144 · raw
@k:String -> @b:0x2370002bb215388f2e71cae632c87c34/scan.Scan -> @attrs:List<&2, Attr> -> Next
def attr.read.scan source · line 148 · raw
@a:0x2370002bb215388f2e71cae632c87c34/scan.Scan -> @attrs:List<&2, Attr> -> Next
def attr.read source · line 152 · raw
@s:String -> @attrs:List<&2, Attr> -> Next
def attributes.close source · line 155 · raw
@scan:0x2370002bb215388f2e71cae632c87c34/scan.Scan -> @attrs:List<&2, Attr> -> Tag
def attributes source · line 170 · raw
@s:String -> @attrs:List<&2, Attr> -> Tag
def lex.open source · line 181 · raw
@n:String -> @tag:Tag -> Lexeme
def lex.named source · line 185 · raw
@scan:0x2370002bb215388f2e71cae632c87c34/scan.Scan -> Lexeme
def lex.shut source · line 189 · raw
@scan:0x2370002bb215388f2e71cae632c87c34/scan.Scan -> Lexeme
def xml.raw source · line 193 · raw
@s:String -> String
def lex.cdata source · line 200 · raw
@scan:0x2370002bb215388f2e71cae632c87c34/scan.Scan -> Lexeme
def lex.tag source · line 204 · raw
@+s:String -> Lexeme
def lex.more source · line 212 · raw
@item:Lexeme -> @next:(@_:String -> List<&2, Token>) -> List<&2, Token>
def lex.after source · line 216 · raw
@s:String -> @next:(@_:String -> List<&2, Token>) -> List<&2, Token>
def lex.text source · line 221 · raw
@scan:0x2370002bb215388f2e71cae632c87c34/scan.Scan -> @next:(@_:String -> List<&2, Token>) -> List<&2, Token>
def elements.rev source · line 235 · raw
@xs:List<&2, Element> -> @acc:List<&2, Element> -> List<&2, Element>
def element.finish source · line 240 · raw
@e:Element -> Element
def stack.add source · line 244 · raw
@s:List<&2, Element> -> @node:Element -> List<&2, Element>
def stack.text source · line 250 · raw
@+s:List<&2, Element> -> @+text:String -> List<&2, Element>
def stack.close source · line 254 · raw
@s:List<&2, Element> -> List<&2, Element>
def tree.step source · line 259 · raw
@tok:Token -> @+s:List<&2, Element> -> List<&2, Element>
def tree source · line 267 · raw
@tokens:List<&2, Token> -> @s:List<&2, Element> -> List<&2, Element>
def tree.root source · line 272 · raw
@s:List<&2, Element> -> Element
def annotate source · line 277 · raw
@xs:List<&2, Token> -> @+i:U32 -> List<&2, Token>
def attr.pick source · line 284 · raw
@hit:Bool -> @+v:String -> @rest:Maybe<&2, String> -> Maybe<&2, String>
def attr.find source · line 302 · raw
@attrs:List<&2, Attr> -> @+key:String -> Maybe<&2, String>
def attr.or source · line 307 · raw
@found:Maybe<&2, String> -> @+fallback:String -> String
def attr.get source · line 312 · raw
@attrs:List<&2, Attr> -> @+key:String -> @+fallback:String -> String
def attrs.append source · line 315 · raw
@xs:List<&2, Attr> -> @ys:List<&2, Attr> -> List<&2, Attr>
def element.prefer source · line 320 · raw
@a:Maybe<&2, Element> -> @b:Maybe<&2, Element> -> Maybe<&2, Element>
def element.find source · line 325 · raw
@+xs:List<&2, Element> -> @+id:String -> Maybe<&2, Element>
def entity source · line 334 · raw
@+s:String -> String
Decode XML entities before interpreting attributes or exposing source editing.
def entities.more source · line 344 · raw
@scan:0x2370002bb215388f2e71cae632c87c34/scan.Scan -> @acc:String -> @next:(@_:String -> @_:String -> String) -> String
def entities source · line 359 · raw
@s:String -> String
def decode.attrs source · line 362 · raw
@as:List<&2, Attr> -> List<&2, Attr>
def decode.nodes source · line 368 · raw
@xs:List<&2, Element> -> List<&2, Element>
Attribute values were decoded as they were read; text still is here.
def parse source · line 374 · raw
@s:String -> Element
def attrs.remove source · line 378 · raw
@+as:List<&2, Attr> -> @+key:String -> List<&2, Attr>
Editor support: identifiers are private metadata and never serialized.
def attrs.set source · line 386 · raw
@as:List<&2, Attr> -> @+key:String -> @value:String -> List<&2, Attr>
def taken.push source · line 394 · raw
@t:Taken -> @a:Attr -> Taken
def attrs.take source · line 409 · raw
@as:List<&2, Attr> -> @+key:String -> Taken
def escape.rev source · line 417 · raw
@s:String -> @acc:String -> String
Build escaped XML in reverse, so large data URIs do not grow the host stack.
def escape source · line 427 · raw
@s:String -> String
def serialize.attrs.rev source · line 430 · raw
@as:List<&2, Attr> -> @+acc:String -> String
def serialize.attrs source · line 438 · raw
@as:List<&2, Attr> -> String
def serialize.element source · line 441 · raw
@+n:String -> @as:List<&2, Attr> -> @kids:List<&2, Element> -> @txt:String -> @+acc:String -> @children:(@_:List<&2, Element> -> @_:String -> String) -> String
def serialize.nodes source · line 457 · raw
@xs:List<&2, Element> -> String
def serialize source · line 460 · raw
@root:Element -> String
def elements.kinds source · line 465 · raw
@xs:List<&2, Element> -> @+acc:U32 -> U32
The number of elements in a forest, the roots included. Which of four element names the tree holds, as bits: 1 image, 2 use, 4 text, 8 style.
def elements.count source · line 473 · raw
@xs:List<&2, Element> -> U32
Unsafe
unsafe entity.take source · line 26 · raw
@s:String -> @+name:String -> @+n:U32 -> Step
unsafe rev.decode.go source · line 49 · raw
@st:Step -> @+out:String -> String
unsafe until.decoded.go source · line 63 · raw
@hit:Bool -> @+c:U32 -> @t:String -> @+end:U32 -> @acc:String -> 0x2370002bb215388f2e71cae632c87c34/scan.Scan
Like until, with entities decoded in the reversal.
unsafe name.go source · line 86 · raw
@stop:Bool -> @+c:U32 -> @t:String -> @acc:String -> 0x2370002bb215388f2e71cae632c87c34/scan.Scan
Each step is decided one character ahead (stop says whether c ends
the name) so the text after the name is held once, never shared.
unsafe attributes.go source · line 160 · raw
@step:Next -> Tag
unsafe tokenize source · line 226 · raw
@s:String -> List<&2, Token>
unsafe attr.find.go source · line 294 · raw
@hit:Bool -> @v:String -> @t:List<&2, Attr> -> @+key:String -> Maybe<&2, String>
The attribute's value when present. Attribute lists are short, so the whole list is walked without a lambda per entry. The first attribute with the key, decided one entry ahead so the walk stops at the hit instead of comparing every key.
unsafe entities.loop source · line 349 · raw
@s:String -> @+acc:String -> String
unsafe attrs.take.go source · line 399 · raw
@hit:Bool -> @kk:String -> @v:String -> @rest:List<&2, Attr> -> @+key:String -> Taken
unsafe serialize.nodes.rev source · line 451 · raw
@xs:List<&2, Element> -> @acc:String -> String