diff options
author | bptato <nincsnevem662@gmail.com> | 2023-08-28 22:50:50 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-08-28 22:50:50 +0200 |
commit | 2b704de41587af20441106fab264c06868559ab9 (patch) | |
tree | 4efc43f9ca611caf5da49a5cb8f42e365dde24ce /src | |
parent | 9026c578f637fffee792b4397251f0ca4562caa5 (diff) | |
download | chawan-2b704de41587af20441106fab264c06868559ab9.tar.gz |
refactor: Result[T, DOMException] -> DOMResult[T]
Diffstat (limited to 'src')
-rw-r--r-- | src/css/cssparser.nim | 15 | ||||
-rw-r--r-- | src/html/dom.nim | 30 |
2 files changed, 21 insertions, 24 deletions
diff --git a/src/css/cssparser.nim b/src/css/cssparser.nim index 07abd67a..52aa0d8c 100644 --- a/src/css/cssparser.nim +++ b/src/css/cssparser.nim @@ -715,7 +715,7 @@ proc parseListOfRules*(cvals: seq[CSSComponentValue]): seq[CSSRule] = state.tokens = cast[seq[CSSParsedItem]](cvals) return state.parseListOfRules() -proc parseRule(state: var CSSParseState): Result[CSSRule, DOMException] = +proc parseRule(state: var CSSParseState): DOMResult[CSSRule] = while state.has() and state.peek() == CSS_WHITESPACE_TOKEN: discard state.consume() if not state.has(): @@ -737,13 +737,12 @@ proc parseRule(state: var CSSParseState): Result[CSSRule, DOMException] = return err(newDOMException("EOF not reached", "SyntaxError")) return ok(res) -proc parseRule*(inputStream: Stream): Result[CSSRule, DOMException] = +proc parseRule*(inputStream: Stream): DOMResult[CSSRule] = var state = CSSParseState() state.tokens = tokenizeCSS(inputStream) return state.parseRule() -proc parseDeclaration(state: var CSSParseState): - Result[CSSDeclaration, DOMException] = +proc parseDeclaration(state: var CSSParseState): DOMResult[CSSDeclaration] = while state.has() and state.peek() == CSS_WHITESPACE_TOKEN: discard state.consume() @@ -756,8 +755,7 @@ proc parseDeclaration(state: var CSSParseState): return err(newDOMException("No declaration found", "SyntaxError")) -proc parseDeclaration*(inputStream: Stream): - Result[CSSDeclaration, DOMException] = +proc parseDeclaration*(inputStream: Stream): DOMResult[CSSDeclaration] = var state = CSSParseState() state.tokens = tokenizeCSS(inputStream) return state.parseDeclaration() @@ -789,7 +787,7 @@ proc parseListOfDeclarations2*(inputStream: Stream): seq[CSSDeclaration] = return state.parseListOfDeclarations2() proc parseComponentValue(state: var CSSParseState): - Result[CSSComponentValue, DOMException] = + DOMResult[CSSComponentValue] = while state.has() and state.peek() == CSS_WHITESPACE_TOKEN: discard state.consume() if not state.has(): @@ -803,8 +801,7 @@ proc parseComponentValue(state: var CSSParseState): return err(newDOMException("EOF not reached", "SyntaxError")) return ok(res) -proc parseComponentValue*(inputStream: Stream): - Result[CSSComponentValue, DOMException] = +proc parseComponentValue*(inputStream: Stream): DOMResult[CSSComponentValue] = var state: CSSParseState state.tokens = tokenizeCSS(inputStream) return state.parseComponentValue() diff --git a/src/html/dom.nim b/src/html/dom.nim index 6d4b285e..c0b60728 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -1073,7 +1073,7 @@ proc remove(tokenList: DOMTokenList, tokens: varargs[string]): return ok() proc toggle(tokenList: DOMTokenList, token: string, force = none(bool)): - Result[bool, DOMException] {.jsfunc.} = + DOMResult[bool] {.jsfunc.} = ?validateDOMToken(token) let i = tokenList.toks.find(token) if i != -1: @@ -1089,7 +1089,7 @@ proc toggle(tokenList: DOMTokenList, token: string, force = none(bool)): return ok(false) proc replace(tokenList: DOMTokenList, token, newToken: string): - Result[bool, DOMException] {.jsfunc.} = + DOMResult[bool] {.jsfunc.} = ?validateDOMToken(token) ?validateDOMToken(newToken) let i = tokenList.toks.find(token) @@ -2224,7 +2224,7 @@ proc removeAttributeNS(element: Element, namespace, localName: string) {.jsfunc. element.delAttr(i) proc toggleAttribute(element: Element, qualifiedName: string, - force = none(bool)): Result[bool, DOMException] {.jsfunc.} = + force = none(bool)): DOMResult[bool] {.jsfunc.} = ?validateAttributeName(qualifiedName) let qualifiedName = if element.namespace == Namespace.HTML and not element.document.isxml: qualifiedName.toLowerAscii2() @@ -2245,7 +2245,7 @@ proc value(attr: Attr, s: string) {.jsfset.} = if attr.ownerElement != nil: attr.ownerElement.attr0(attr.name, s) -proc setNamedItem(map: NamedNodeMap, attr: Attr): Result[Attr, DOMException] +proc setNamedItem(map: NamedNodeMap, attr: Attr): DOMResult[Attr] {.jsfunc.} = if attr.ownerElement != nil and attr.ownerElement != map.element: return err(newDOMException("Attribute is currently in use", @@ -2261,12 +2261,12 @@ proc setNamedItem(map: NamedNodeMap, attr: Attr): Result[Attr, DOMException] map.element.attrs[attr.name] = attr.value map.attrlist.add(attr) -proc setNamedItemNS(map: NamedNodeMap, attr: Attr): Result[Attr, DOMException] +proc setNamedItemNS(map: NamedNodeMap, attr: Attr): DOMResult[Attr] {.jsfunc.} = return map.setNamedItem(attr) proc removeNamedItem(map: NamedNodeMap, qualifiedName: string): - Result[Attr, DOMException] {.jsfunc.} = + DOMResult[Attr] {.jsfunc.} = let i = map.findAttr(qualifiedName) if i != -1: let attr = map.attrlist[i] @@ -2275,7 +2275,7 @@ proc removeNamedItem(map: NamedNodeMap, qualifiedName: string): return err(newDOMException("Item not found", "NotFoundError")) proc removeNamedItemNS(map: NamedNodeMap, namespace, localName: string): - Result[Attr, DOMException] {.jsfunc.} = + DOMResult[Attr] {.jsfunc.} = let i = map.findAttrNS(namespace, localName) if i != -1: let attr = map.attrlist[i] @@ -2518,8 +2518,7 @@ proc insert*(parent, node, before: Node) = for node in nodes: insertNode(parent, node, before) -proc insertBefore*(parent, node, before: Node): Result[Node, DOMException] - {.jsfunc.} = +proc insertBefore*(parent, node, before: Node): DOMResult[Node] {.jsfunc.} = ?parent.preInsertionValidity(node, before) let referenceChild = if before == node: node.nextSibling @@ -2528,7 +2527,7 @@ proc insertBefore*(parent, node, before: Node): Result[Node, DOMException] parent.insert(node, referenceChild) return ok(node) -proc appendChild(parent, node: Node): Result[Node, DOMException] {.jsfunc.} = +proc appendChild(parent, node: Node): DOMResult[Node] {.jsfunc.} = return parent.insertBefore(node, nil) proc append*(parent, node: Node) = @@ -2536,7 +2535,7 @@ proc append*(parent, node: Node) = #TODO replaceChild -proc removeChild(parent, node: Node): Result[Node, DOMException] {.jsfunc.} = +proc removeChild(parent, node: Node): DOMResult[Node] {.jsfunc.} = if node.parentNode != parent: return err(newDOMException("Node is not a child of parent", "NotFoundError")) @@ -2811,7 +2810,7 @@ proc prepare*(element: HTMLScriptElement) = #TODO options/custom elements proc createElement(document: Document, localName: string): - Result[Element, DOMException] {.jsfunc.} = + DOMResult[Element] {.jsfunc.} = if not localName.matchNameProduction(): return err(newDOMException("Invalid character in element name", "InvalidCharacterError")) @@ -2831,7 +2830,7 @@ proc createDocumentFragment(document: Document): DocumentFragment {.jsfunc.} = return newDocumentFragment(document) proc createDocumentType(implementation: ptr DOMImplementation, qualifiedName, - publicId, systemId: string): Result[DocumentType, DOMException] {.jsfunc.} = + publicId, systemId: string): DOMResult[DocumentType] {.jsfunc.} = if not qualifiedName.matchQNameProduction(): return err(newDOMException("Invalid character in document type name", "InvalidCharacterError")) @@ -2858,7 +2857,8 @@ proc createHTMLDocument(implementation: ptr DOMImplementation, title = proc hasFeature(implementation: ptr DOMImplementation): bool {.jsfunc.} = return true -proc createCDATASection(document: Document, data: string): Result[CDATASection, DOMException] {.jsfunc.} = +proc createCDATASection(document: Document, data: string): + DOMResult[CDATASection] {.jsfunc.} = if not document.isxml: return err(newDOMException("CDATA sections are not supported in HTML", "NotSupportedError")) @@ -2871,7 +2871,7 @@ proc createComment*(document: Document, data: string): Comment {.jsfunc.} = return newComment(document, data) proc createProcessingInstruction(document: Document, target, data: string): - Result[ProcessingInstruction, DOMException] {.jsfunc.} = + DOMResult[ProcessingInstruction] {.jsfunc.} = if not target.matchNameProduction() or "?>" in data: return err(newDOMException("Invalid data for processing instruction", "InvalidCharacterError")) |