tokenize.bend checks
raw source on the hub · import element-html@0.1.0.0/tokenize.bend as Tokenize
3 imports
import Base import ./dom.bend as Dom import ./entities.bend as Ent
Types
type Tok source · line 15 · raw
Data
TStart@name:String -> @attrs:List<&2, 0x3f7d6a337c19dca90be0905f33ec406a/dom.Attr> -> @self_close:Bool -> Tok
TEnd@name:String -> Tok
TText@text:String -> Tok
TComment@text:String -> Tok
type Tag source · line 23 · raw
Data
A tag being read: name (reversed chars), attributes (newest first), and whether it is an end tag.
HTag@name:List<&2, Char> -> @attrs:List<&2, 0x3f7d6a337c19dca90be0905f33ec406a/dom.Attr> -> @end:Bool -> Tag
type Mode source · line 26 · raw
Data
HData@text:List<&2, Char> -> Mode
HTagOpenMode
HEndOpenMode
HTagName@tag:Tag -> Mode
HBeforeAttr@tag:Tag -> Mode
HAttrName@tag:Tag -> @name:List<&2, Char> -> Mode
HAfterAttrName@tag:Tag -> @name:List<&2, Char> -> Mode
HBeforeVal@tag:Tag -> @name:List<&2, Char> -> Mode
HValQ@tag:Tag -> @name:List<&2, Char> -> @quote:Char -> @val:List<&2, Char> -> Mode
HValUnq@tag:Tag -> @name:List<&2, Char> -> @val:List<&2, Char> -> Mode
HAfterVal@tag:Tag -> Mode
HSelfClose@tag:Tag -> Mode
HMarkup@dashes:U32 -> Mode
HComment@d1:Bool -> @d2:Bool -> @text:List<&2, Char> -> Mode
HBogus@text:List<&2, Char> -> Mode
HRaw@tag:String -> @text:List<&2, Char> -> Mode
Definitions
def str source · line 44 · raw
@cs:List<&2, Char> -> String
def lower source · line 47 · raw
@+c:Char -> Char
def is_ws source · line 50 · raw
@+c:Char -> Bool
def is_raw source · line 53 · raw
@+name:String -> Bool
def tag_name source · line 56 · raw
@t:Tag -> String
def tag_end source · line 61 · raw
@t:Tag -> Bool
def add_char source · line 66 · raw
@t:Tag -> @+c:Char -> Tag
def nul_go source · line 73 · raw
@s:String -> @+keep:Bool -> String
NUL (U+0000): dropped from text (the tree builder ignores it in a body), U+FFFD in raw text and attribute values (WHATWG 13.2.5).
def has_nul source · line 82 · raw
@s:String -> Bool
def nul_if source · line 89 · raw
@any:Bool -> @+s:String -> @+keep:Bool -> String
def nuls source · line 97 · raw
@+s:String -> @+keep:Bool -> String
Most text has no NUL: one scan, and it comes back unchanged.
def add_attr source · line 100 · raw
@t:Tag -> @+name:List<&2, Char> -> @+val:List<&2, Char> -> Tag
def token_of source · line 105 · raw
@t:Tag -> @+self:Bool -> Tok
def after_tag source · line 115 · raw
@+t:Tag -> Mode
After '>': back to text, or into raw text for <script>, <style>, ...
def text_tok source · line 118 · raw
@+cs:List<&2, Char> -> List<&2, Tok>
def raw_tok source · line 127 · raw
@+cs:List<&2, Char> -> @+tag:String -> List<&2, Tok>
Raw text: <title> and <textarea> decode character references (RCDATA), <script> and <style> do not (RAWTEXT, script data).
def ends_with_close source · line 136 · raw
@+rev:List<&2, Char> -> @+tag:String -> Bool
Does the reversed text end with "</" + tag (any case)? rev is newest first.
def one_char source · line 143 · raw
@xs:List<&2, Char> -> Bool
---- comments --------------------------------------------------------------------
A comment ends at "-->"; "<!-->" and "<!--->" are empty ones (WHATWG
13.2.5.43-44, abrupt closing). text holds what came after "<!--",
newest first, with the closing dashes in it.
def bang_end source · line 152 · raw
@xs:List<&2, Char> -> Bool
(checked at every character of a comment: no length, which would walk it) "--!>" also ends one (13.2.5.52, comment end bang)
def comment_ends source · line 167 · raw
@+c:Char -> @+d1:Bool -> @+d2:Bool -> @+text:List<&2, Char> -> Bool
def comment_data source · line 170 · raw
@+d1:Bool -> @+d2:Bool -> @+text:List<&2, Char> -> String
def pi_char source · line 179 · raw
@+c:Char -> Bool
<?target ...>: a processing instruction when the target is a name (an ASCII letter or "_", then letters, digits, "-" or "_") not starting with "xml"; any other <?...> is a bogus comment (as Chrome parses them).
def pi_rest source · line 183 · raw
@s:String -> Bool
def pi_target source · line 190 · raw
@s:String -> Bool
def is_pi source · line 198 · raw
@+s:String -> Bool
def bogus_emit source · line 204 · raw
@ends:Bool -> @+text:List<&2, Char> -> List<&2, Tok>
A bogus comment (<!...>, </ ...>) is a comment of its text. A DOCTYPE, and <?...> (Chrome makes it a processing instruction node), are nodes this DOM does not keep.
def comment_emit source · line 212 · raw
@ends:Bool -> @+d1:Bool -> @+d2:Bool -> @+text:List<&2, Char> -> List<&2, Tok>
def valq_next source · line 223 · raw
@close:Bool -> @+tag:Tag -> @+name:List<&2, Char> -> @+quote:Char -> @+val:List<&2, Char> -> @+c:Char -> Mode
An attribute value is decoded once, when it ends (a match, not a Bool.pick, which would decode the whole value again at every character).
def valunq_next source · line 230 · raw
@ws:Bool -> @gt:Bool -> @+tag:Tag -> @+name:List<&2, Char> -> @+val:List<&2, Char> -> @+c:Char -> Mode
def next_mode source · line 239 · raw
@m:Mode -> @+c:Char -> Mode
def tag_emit source · line 298 · raw
@gt:Bool -> @+tag:Tag -> @+self:Bool -> List<&2, Tok>
The text is decoded only when a token completes: these match on the decision, so the decode never runs per character (a Bool.pick would).
def data_emit source · line 305 · raw
@lt:Bool -> @+text:List<&2, Char> -> List<&2, Tok>
def raw_emit source · line 312 · raw
@done:Bool -> @+rev:List<&2, Char> -> @+tag:String -> List<&2, Tok>
def emits source · line 320 · raw
@m:Mode -> @+c:Char -> List<&2, Tok>
Tokens completed by reading c in mode m.
def at_eof source · line 355 · raw
@m:Mode -> List<&2, Tok>
def rev_append source · line 392 · raw
@xs:List<&2, Tok> -> @acc:List<&2, Tok> -> List<&2, Tok>
def go source · line 400 · raw
@s:String -> @+m:Mode -> @+acc:List<&2, Tok> -> List<&2, Tok>
Tokens newest first; tokenize returns them in order.
def tokenize source · line 407 · raw
@s:String -> List<&2, Tok>