about summary refs log tree commit diff stats
path: root/src/html/htmlparser.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-07-12 18:12:55 +0200
committerbptato <nincsnevem662@gmail.com>2022-07-12 18:12:55 +0200
commit2f0ea08df1e6884da51ea510cc352395e853cfc0 (patch)
tree214aef273f772a8ad657039097cb7c9134ba9f7d /src/html/htmlparser.nim
parent1abd3aadf0c999c6e26ba4e7910b5abe3510c6c2 (diff)
downloadchawan-2f0ea08df1e6884da51ea510cc352395e853cfc0.tar.gz
Fix a tokenizer bug, clean up some warnings
Diffstat (limited to 'src/html/htmlparser.nim')
-rw-r--r--src/html/htmlparser.nim13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim
index 0b2a99be..a9c9b1fd 100644
--- a/src/html/htmlparser.nim
+++ b/src/html/htmlparser.nim
@@ -54,7 +54,6 @@ proc resetInsertionMode(parser: var HTML5Parser) =
       node = parser.ctx
     if node.tagType == TAG_SELECT:
       if not last:
-        var ancestor = node
         for j in countdown(parser.openElements.high, 1):
           let ancestor = parser.openElements[j]
           case ancestor.tagType
@@ -525,6 +524,7 @@ macro match(token: Token, body: typed): untyped =
   type OfBranchStore = object
     ofBranches: seq[(seq[NimNode], NimNode)]
     defaultBranch: NimNode
+    painted: bool
 
   # Stores 'of' branches
   var ofBranches: array[TokenType, OfBranchStore]
@@ -552,12 +552,15 @@ macro match(token: Token, body: typed): untyped =
       case pattern.kind
       of nnkSym: # simple symbols; we assume these are the enums
         ofBranches[tokenTypes[pattern.strVal]].defaultBranch = action
+        ofBranches[tokenTypes[pattern.strVal]].painted = true
       of nnkCharLit:
         ofBranches[CHARACTER_ASCII].ofBranches.add((@[pattern], action))
+        ofBranches[CHARACTER_ASCII].painted = true
       of nnkCurly:
         case pattern[0].kind
         of nnkCharLit:
           ofBranches[CHARACTER_ASCII].ofBranches.add((@[pattern], action))
+          ofBranches[CHARACTER_ASCII].painted = true
         else: error fmt"Unsupported curly of kind {pattern[0].kind}"
       of nnkStrLit:
         var tempTokenizer = newTokenizer(newStringStream(pattern.strVal))
@@ -570,9 +573,11 @@ macro match(token: Token, body: typed): untyped =
               if ofBranches[token.t].ofBranches[i][1] == action:
                 found = true
                 ofBranches[token.t].ofBranches[i][0].add((quote do: TagType(`tt`)))
+                ofBranches[token.t].painted = true
                 break
             if not found:
               ofBranches[token.t].ofBranches.add((@[(quote do: TagType(`tt`))], action))
+              ofBranches[token.t].painted = true
           else: error fmt"{pattern.strVal}: Unsupported token {token} of kind {token.t}"
           break
       of nnkDiscardStmt:
@@ -628,7 +633,10 @@ macro match(token: Token, body: typed): untyped =
       else:
         discard
 
-  mainCase.add(newNimNode(nnkElse).add(quote do: discard))
+  for t in TokenType:
+    if not ofBranches[t].painted:
+      mainCase.add(newNimNode(nnkElse).add(quote do: discard))
+      break
 
   var stmts = newStmtList().add(mainCase)
   for stmt in defaultBranch:
@@ -1358,7 +1366,6 @@ proc processInHTMLContent(parser: var HTML5Parser, token: Token, insertionMode =
       )
       "</script>" => (block:
         #TODO microtask
-        let script = parser.currentNode
         pop_current_node
         parser.insertionMode = parser.oldInsertionMode
         #TODO document.write() ?