From af3dbce840d0d0956663ffb20012329a4c22d5dd Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 1 Aug 2023 19:05:45 +0200 Subject: Fixes & workarounds to compile on Nim 2.0.0 * Import punycode, as it has been removed from stdlib. * Fix some syntax errors * Apparently you can no longer compare distinct pointers with nil. Add explicit comparisons with typeof(nil) instead. * htmlparser: rename _ to other, as semantics of _ have changed. (Quite a shame, it looked better with _. Oh well.) * Explicitly specify mm:refc, as the browser OOMs with orc for some reason. Confirmed to compile & run on 2.0.0, 1.6.14, 1.6.12, 1.6.10 and 1.6.8. (<1.6.8 it's broken & wontfix.) --- src/html/dom.nim | 12 ++++++------ src/html/htmlparser.nim | 42 +++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 27 deletions(-) (limited to 'src/html') diff --git a/src/html/dom.nim b/src/html/dom.nim index 4318c517..11254c56 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -2872,9 +2872,9 @@ proc querySelector*(node: Node, q: string): Element {.jsfunc.} = const (ReflectTable, TagReflectMap, ReflectAllStartIndex) = (func(): ( seq[ReflectEntry], - Table[TagType, seq[uint16]], - uint16) = - var i: uint16 = 0 + Table[TagType, seq[int16]], + int16) = + var i: int16 = 0 while i < ReflectTable0.len: let x = ReflectTable0[i] result[0].add(x) @@ -2882,7 +2882,7 @@ const (ReflectTable, TagReflectMap, ReflectAllStartIndex) = (func(): ( break for tag in result[0][i].tags: if tag notin result[1]: - result[1][tag] = newSeq[uint16]() + result[1][tag] = newSeq[int16]() result[1][tag].add(i) assert result[0][i].tags.len != 0 inc i @@ -2967,8 +2967,8 @@ func getReflectFunctions(tags: set[TagType]): seq[TabGetSet] = return result func getElementReflectFunctions(): seq[TabGetSet] = - var i: uint16 = ReflectAllStartIndex - while i < uint16(ReflectTable.len): + var i: int16 = ReflectAllStartIndex + while i < int16(ReflectTable.len): let entry = ReflectTable[i] assert entry.tags == AllTagTypes result.add(TabGetSet(name: ReflectTable[i].funcname, get: jsReflectGet, set: jsReflectSet, magic: i)) diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim index 05e830fb..2192ccf8 100644 --- a/src/html/htmlparser.nim +++ b/src/html/htmlparser.nim @@ -1152,7 +1152,7 @@ proc closeP(parser: var HTML5Parser) = # ("

", "", "") => (block: echo "p, a or closing div") # ("

", "

") => (block: anything_else) # (TokenType.START_TAG, TokenType.END_TAG) => (block: assert false, "invalid") -# _ => (block: echo "anything else") +# other => (block: echo "anything else") # # (effectively) generates this: # @@ -1322,7 +1322,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], quote do: discard (`v`, proc() = `body`) - template _ = discard + template other = discard template reprocess(tok: Token) = parser.processInHTMLContent(tok, parser.insertionMode) @@ -1362,7 +1362,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], parser.setQuirksMode(LIMITED_QUIRKS) parser.insertionMode = BEFORE_HTML ) - _ => (block: + other => (block: if not parser.opts.isIframeSrcdoc: parse_error UNEXPECTED_INITIAL_TOKEN parser.setQuirksMode(QUIRKS) @@ -1386,7 +1386,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], ) ("", "", "", "
") => (block: anything_else) TokenType.END_TAG => (block: parse_error UNEXPECTED_END_TAG) - _ => (block: + other => (block: let element = parser.createElement(TAG_HTML, Namespace.HTML) parser.append(parser.document, element) parser.pushElement(element) @@ -1406,7 +1406,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], ) ("", "", "", "
") => (block: anything_else) TokenType.END_TAG => (block: parse_error UNEXPECTED_END_TAG) - _ => (block: + other => (block: let head = Token(t: START_TAG, tagtype: TAG_HEAD) parser.head = some(parser.insertHTMLElement(head)) parser.insertionMode = IN_HEAD @@ -1481,7 +1481,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], parser.resetInsertionMode() ) ("", TokenType.END_TAG) => (block: parse_error UNEXPECTED_END_TAG) - _ => (block: + other => (block: pop_current_node parser.insertionMode = AFTER_HEAD reprocess token @@ -1503,7 +1503,7 @@ proc processInHTMLContent[Handle](parser: var HTML5Parser[Handle], "
" => (block: anything_else) ("", "