aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
parent1abd3aadf0c999c6e26ba4e7910b5abe3510c6c2 (diff)
downloadchawan-2f0ea08df1e6884da51ea510cc352395e853cfc0.tar.gz
Fix a tokenizer bug, clean up some warnings
Diffstat (limited to 'src')
-rw-r--r--src/html/dom.nim25
-rw-r--r--src/html/htmlparser.nim13
-rw-r--r--src/html/htmltokenizer.nim2
-rw-r--r--src/io/buffer.nim34
-rw-r--r--src/io/loader.nim1
-rw-r--r--src/layout/engine.nim12
-rw-r--r--src/utils/radixtree.nim28
7 files changed, 50 insertions, 65 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 921c8702..e412a366 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -1,7 +1,6 @@
import tables
import options
import streams
-import strformat
import strutils
import css/values
@@ -317,7 +316,7 @@ func branch*(node: Node): seq[Node] =
for node in node.branch:
result.add(node)
-func firstChild(node: Node): Node =
+func firstChild*(node: Node): Node =
if node.childNodes.len == 0:
return nil
return node.childNodes[0]
@@ -727,9 +726,9 @@ proc remove*(node: Node) =
#TODO not surpress observers => queue tree mutation record
proc adopt(document: Document, node: Node) =
- let oldDocument = node.document
if node.parentNode != nil:
remove(node)
+ #TODO shadow root
proc applyChildInsert(parent, child: Node, index: int) =
if parent.rootNode != nil:
@@ -760,8 +759,8 @@ proc insert*(parent, node, before: Node) =
if before != nil:
#TODO live ranges
discard
- let previousSibling = if before == nil: parent.lastChild
- else: before.previousSibling
+ #let previousSibling = if before == nil: parent.lastChild
+ #else: before.previousSibling
for node in nodes:
parent.document.adopt(node)
if before == nil:
@@ -835,7 +834,21 @@ proc appendAttribute*(element: Element, k, v: string) =
for class in classes:
if class != "" and class notin element.classList:
element.classList.add(class)
- else: discard
+ if element.tagType == TAG_INPUT:
+ case k
+ of "value": HTMLInputElement(element).value = v
+ of "type": HTMLInputElement(element).inputType = inputType(v)
+ of "size":
+ var i = 20
+ var fail = v.len > 0
+ for c in v:
+ if not c.isDigit:
+ fail = true
+ break
+ if not fail:
+ i = parseInt(v)
+ HTMLInputElement(element).size = i
+ of "checked": HTMLInputElement(element).checked = true
element.attributes[k] = v
proc setForm*(element: Element, form: HTMLFormElement) =
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() ?
diff --git a/src/html/htmltokenizer.nim b/src/html/htmltokenizer.nim
index 29680d19..8738323f 100644
--- a/src/html/htmltokenizer.nim
+++ b/src/html/htmltokenizer.nim
@@ -801,7 +801,7 @@ iterator tokenize*(tokenizer: var Tokenizer): Token =
of '=': switch_state BEFORE_ATTRIBUTE_VALUE
of '>':
switch_state DATA
- emit '>'
+ emit_tok
of eof:
parse_error eof_in_tag
emit_eof
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index 7dc59777..44e5855c 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -329,26 +329,6 @@ proc refreshDisplay(buffer: Buffer) =
inc y
-proc setCursorXB(buffer: Buffer, byte: int) =
- var w = 0
- var b = 0
- while b < byte:
- var r: Rune
- fastRuneAt(buffer.currentLine, b, r)
- w += r.width()
-
- let x = w
- if x - buffer.fromx >= 0 and x - buffer.width < buffer.fromx:
- buffer.cursorx = x
- else:
- if x > buffer.cursorx:
- buffer.fromx = max(x - buffer.width + 1, 0)
- elif x < buffer.cursorx:
- buffer.fromx = min(x, buffer.maxfromx)
- buffer.cursorx = x
- buffer.redraw = true
- buffer.xend = buffer.cursorx
-
proc setCursorX(buffer: Buffer, x: int, refresh = true, save = true) =
if (not refresh) or (buffer.fromx <= x and x < buffer.fromx + buffer.width):
buffer.cursorx = x
@@ -391,10 +371,6 @@ proc setFromXY*(buffer: Buffer, x, y: int) =
buffer.fromy = max(min(y, buffer.maxfromy), 0)
buffer.fromx = max(min(x, buffer.maxfromx), 0)
-proc setCursorXBY(buffer: Buffer, x, y: int) =
- buffer.setCursorY(y)
- buffer.setCursorXB(x)
-
proc cursorDown*(buffer: Buffer) =
if buffer.cursory < buffer.numLines - 1:
buffer.setCursorY(buffer.cursory + 1)
@@ -955,11 +931,11 @@ proc submitForm(form: HTMLFormElement, submitter: Element): Option[ClickAction]
assert formmethod == FORM_METHOD_POST
HttpPost
- let target = if submitter.isSubmitButton() and submitter.attrb("formtarget"):
- submitter.attr("formtarget")
- else:
- submitter.target()
- let noopener = true #TODO
+ #let target = if submitter.isSubmitButton() and submitter.attrb("formtarget"):
+ # submitter.attr("formtarget")
+ #else:
+ # submitter.target()
+ #let noopener = true #TODO
template mutateActionUrl() =
let query = serializeApplicationXWWFormUrlEncoded(entrylist)
diff --git a/src/io/loader.nim b/src/io/loader.nim
index 30ee07e6..8d942ae2 100644
--- a/src/io/loader.nim
+++ b/src/io/loader.nim
@@ -3,7 +3,6 @@ import options
import os
import osproc
import streams
-import streamwrapper
import strutils
import config/config
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 3fe7af96..bf40f4b4 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -110,7 +110,6 @@ proc horizontalAlignRow(ictx: InlineContext, row: InlineRow, computed: CSSComput
dec spaces
if spaces > 0:
let spacingwidth = (ictx.maxwidth - sumwidth) div spaces
- let oldwidth = row.width
row.width = 0
for atom in row.atoms:
atom.offset.x = row.width
@@ -474,7 +473,7 @@ proc buildInlineBlock(builder: InlineBlockBoxBuilder, parent: InlineContext, par
assert builder.content != nil
result = parentblock.newInlineBlock(builder)
- let blockbuilder = BlockBoxBuilder(builder.content)
+ let blockbuilder = builder.content
if blockbuilder.inlinelayout:
# Builder only contains inline boxes.
result.bctx.inline = result.bctx.buildInlines(blockbuilder.children)
@@ -520,9 +519,6 @@ proc buildInline(bctx: BlockContext, box: InlineBoxBuilder) =
if padding_left > 0:
box.ictx.thisrow.addSpacing(padding_left, box.ictx.cellheight, paddingformat)
- let originalRow = box.ictx.thisrow
- let originalWidth = box.ictx.thisrow.width
-
for text in box.text:
assert box.children.len == 0
box.ictx.renderText(text, bctx.compwidth, box.computed, box.node)
@@ -674,12 +670,6 @@ func getInputBox(parent: BoxBuilder, input: HTMLInputElement, viewport: Viewport
textbox.text.add(input.inputString())
return textbox
-func getInputBox(computed: CSSComputedValues, input: HTMLInputElement, viewport: Viewport): InlineBoxBuilder =
- let textbox = computed.getTextBox()
- textbox.node = input
- textbox.text.add(input.inputString())
- return textbox
-
# Don't generate empty anonymous inline blocks between block boxes
func canGenerateAnonymousInline(blockgroup: seq[BoxBuilder], computed: CSSComputedValues, text: Text): bool =
return blockgroup.len > 0 and blockgroup[^1].computed{"display"} == DISPLAY_INLINE or
diff --git a/src/utils/radixtree.nim b/src/utils/radixtree.nim
index f4ef5fb0..1ea32997 100644
--- a/src/utils/radixtree.nim
+++ b/src/utils/radixtree.nim
@@ -43,20 +43,20 @@ iterator keys*[T](node: RadixNode[T]): string =
yield node.children[i].k
inc i
-func contains[T](node: RadixNode[T], k: string): bool =
- var i = 0
- while i < node.children.len:
- if node.children[i].k[0] == k[0]:
- if k.len != node.children[i].k.len:
- return false
- var j = 1
- while j < k.len:
- if node.children[i].k[j] != k[j]:
- return false
- inc j
- return true
- inc i
- return false
+#func contains[T](node: RadixNode[T], k: string): bool =
+# var i = 0
+# while i < node.children.len:
+# if node.children[i].k[0] == k[0]:
+# if k.len != node.children[i].k.len:
+# return false
+# var j = 1
+# while j < k.len:
+# if node.children[i].k[j] != k[j]:
+# return false
+# inc j
+# return true
+# inc i
+# return false
# O(1) add procedures for insert
proc add[T](node: RadixNode[T], k: string, v: T) =