+ # http://www.w3.org/TR/html5/syntax.html#tag-open-state
+ tok_state_tag_open = ->
+ switch c = txt.charAt(cur++)
+ when '!'
+ tok_state = tok_state_markup_declaration_open
+ when '/'
+ tok_state = tok_state_end_tag_open
+ when '?'
+ # Parse error
+ tok_state = tok_state_bogus_comment
+ else
+ if lc_alpha.indexOf(c) > -1
+ tok_cur = [TYPE_OPEN_TAG, c, {}, []]
+ tok_state = tok_state_tag_name
+ else if uc_alpha.indexOf(c) > -1
+ tok_cur = [TYPE_OPEN_TAG, c.toLowerCase(), {}, []]
+ tok_state = tok_state_tag_name
+ else
+ # Parse error
+ tok_state = tok_state_data
+ cur -= 1 # we didn't parse/handle the char after <
+ return [TYPE_TEXT, '<']
+ return null
+
+ # http://www.w3.org/TR/html5/syntax.html#tag-name-state
+ tok_state_tag_name = ->
+ switch c = txt.charAt(cur++)
+ when "\t", "\n", ' '
+ tok_state = tok_state_before_attribute_name
+ when '/'
+ tok_state = tok_state_self_closing_start_tag
+ when '>'
+ tok_state = tok_state_data
+ tmp = tok_cur
+ tok_cur = null
+ return tmp
+ when "\u0000"
+ # Parse error
+ tok_cur[1] += "\ufffd"
+ else
+ if uc_alpha.indexOf(c) > -1
+ tok_cur[1] += c.toLowerCase()
+ else
+ tok_cur[1] += c
+ return null
+
+ # http://www.w3.org/TR/html5/syntax.html#character-reference-in-data-state