### Example: Setting and Getting Attributes Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Demonstrates setting attributes using a dictionary converted to XmlAttributes and then retrieving them using the 'attr' procedure. ```nim var j = newElement("myTag") let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes j.attrs = att assert j.attr("key1") == "first value" assert j.attr("key2") == "second value" ``` -------------------------------- ### Example: Get Comment Text Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Demonstrates creating a comment node and retrieving its text content using the `text` procedure. ```nim var c = newComment("my comment") assert $c == "" assert c.text == "my comment" ``` -------------------------------- ### Example: Get Element Tag Name Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Demonstrates how to create an XML element and assert its tag name using the `tag` procedure. ```nim var a = newElement("firstTag") a.add newElement("childTag") assert $a == "\n \n \n" assert a.tag == "firstTag" ``` -------------------------------- ### XMLHttpRequest Example Source: https://nim-lang.github.io/fusion/src/fusion/js/jsxmlhttprequest.html Demonstrates the creation, configuration, and usage of XMLHttpRequest for making HTTP requests. Includes setting headers, sending data, and retrieving response details. This example requires the fusionJsXmlhttprequestTests to be defined. ```nim import src/fusion/js/jsxmlhttprequest from std/dom import Node if defined(fusionJsXmlhttprequestTests): let request: XMLHttpRequest = newXMLHttpRequest() request.open("GET".cstring, "http://localhost:8000/".cstring, false) request.setRequestHeader("mode".cstring, "no-cors".cstring) request.setRequestHeader([(key: "mode".cstring, val: "no-cors".cstring)]) request.overrideMimeType("text/plain".cstring) request.send() echo request.getAllResponseHeaders() echo "responseText\t", request.responseText echo "responseURL\t", request.responseURL echo "statusText\t", request.statusText echo "responseXML\t", request.responseXML is Node echo "status\t", request.status echo "timeout\t", request.timeout echo "withCredentials\t", request.withCredentials echo "readyState\t", request.readyState request.abort() ``` -------------------------------- ### Example: Accessing Attributes Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Shows how to check if attributes are initialized (nil) and how to assign and then access them. ```nim var j = newElement("myTag") assert j.attrs == nil let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes j.attrs = att assert j.attrs == att ``` -------------------------------- ### Example: Create and Assert Table Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Demonstrates the creation of a Table from a sequence of pairs and asserts its equality with a literal. ```nim let a = [('a', 5), ('b', 9)] let b = toTable(a) assert b == {'a': 5, 'b': 9}.toTable ``` -------------------------------- ### Example: XML Constructor Macro Usage Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Illustrates the usage of the `<>` macro for creating an XML element with an attribute and text content. ```nim <>a(href="http://nim-lang.org", newText("Nim rules.")) ``` -------------------------------- ### Example: Counting Attributes Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Shows how to check the initial attribute count (0) and then verify the count after setting attributes. ```nim var j = newElement("myTag") assert j.attrsLen == 0 let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes j.attrs = att assert j.attrsLen == 2 ``` -------------------------------- ### Example: Building a String with Nodes Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Demonstrates building a string by adding comments, elements with text, and verifying the final concatenated string. ```nim var a = newElement("firstTag") b = newText("my text") c = newComment("my comment") s = "" s.add(c) a.add(b) s.add(a) assert s == "my text" ``` -------------------------------- ### Get or Put (`mgetOrPut`) Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Procedures for getting a value by key, or putting a default value if the key doesn't exist, returning a mutable reference to the value. ```APIDOC ## mgetOrPut[A, B](t: OrderedTableRef[A, B]; key: A; val: B): var B ### Description Retrieves a mutable reference to the value associated with a key in an OrderedTableRef. If the key does not exist, it is inserted with the provided value, and a mutable reference to the new value is returned. ### Method mgetOrPut ### Endpoint N/A (Procedure Call) ### Parameters - **t** (OrderedTableRef[A, B]) - The OrderedTableRef. - **key** (A) - The key to look up or insert. - **val** (B) - The value to insert if the key does not exist. ### Response - **var B** - A mutable reference to the value associated with the key. ``` ```APIDOC ## mgetOrPut[A, B](t: TableRef[A, B]; key: A; val: B): var B ### Description Retrieves a mutable reference to the value associated with a key in a TableRef. If the key does not exist, it is inserted with the provided value, and a mutable reference to the new value is returned. ### Method mgetOrPut ### Endpoint N/A (Procedure Call) ### Parameters - **t** (TableRef[A, B]) - The TableRef. - **key** (A) - The key to look up or insert. - **val** (B) - The value to insert if the key does not exist. ### Response - **var B** - A mutable reference to the value associated with the key. ``` -------------------------------- ### Example: Create and Assert OrderedTable Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Demonstrates the creation of an OrderedTable from a sequence of pairs and asserts its equality with a literal. ```nim let a = [('a', 5), ('b', 9)] let b = toOrderedTable(a) assert b == {'a': 5, 'b': 9}.toOrderedTable ``` -------------------------------- ### Example: Create and Assign Attributes Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Shows how to convert key-value pairs into XmlAttributes and assign them to an element's `attrs` field. ```nim let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes var j = newElement("myTag") j.attrs = att echo j ## ``` -------------------------------- ### Tuple Matching Examples Source: https://nim-lang.github.io/fusion/src/fusion/matching.html Demonstrates various tuple matching patterns, including matching all elements, failed bindings, and conditional matches. ```nim Input tuple: `(1, 2, "fa")` Pattern| Result| Comment ---|---|--- `(_, _, _)`| **Ok**| Match all `(@a, @a, _)`| **Fail**| `(@a is (1 | 2), @a, _)`| **Fail**| 1 `(1, 1 | 2, _)`| **Ok**| * 1 Pattern backtracking is not performed, `@a` is first bound to `1`, and in subsequent match attempts pattern fails. ``` -------------------------------- ### JsSet Example Usage Source: https://nim-lang.github.io/fusion/src/fusion/js/jssets.html Demonstrates the creation, manipulation, and assertion of JsSet properties. Requires fusionJsSetTests to be defined. ```nim import src/fusion/js/jssets import std/jsffi if defined(fusionJsSetTests): let a: JsSet = newJsSet([1.toJs, 2.toJs, 3.toJs, 4.toJs]) let b: JsSet = newJsSet([1.0.toJs, 2.0.toJs, 3.0.toJs]) doAssert a.len == 4 doAssert b.len == 3 doAssert a.toString() == @["1".cstring, "2", "3", "4"] doAssert b.toString() == @["1".cstring, "2", "3"] a.clear() b.clear() let d: JsSet = newJsSet([1.toJs, 2.toJs, 3.toJs]) doAssert d.len == 3 d.add(4.toJs) d.delete(2.toJs) doAssert 3.toJs in d doAssert "3".cstring.toJs notin d doAssert d.contains 1.toJs doAssert $d == """@[\"1\", \"3\", \"4\"]""" ``` -------------------------------- ### keysFrom Source: https://nim-lang.github.io/fusion/theindex.html Iterates over keys starting from a specified key in a Table. ```APIDOC ## iterator keysFrom[A, B](b: Table[A, B]; fromKey: A): A ### Description An iterator that yields keys from a specified starting key (inclusive) to the end of the table. ### Parameters * **b** (Table[A, B]) - The table to iterate over. * **fromKey** (A) - The key from which to start iteration. ### Yields (A) Each key from 'fromKey' onwards. ``` -------------------------------- ### Basic Pool Usage Example Source: https://nim-lang.github.io/fusion/src/fusion/pools.html Demonstrates how to initialize a pool and allocate new nodes of a specific object type. Pools are designed for efficient memory management. ```nim var p: Pool[MyObjectType] var n0 = newNode(p) var n1 = newNode(p) ``` -------------------------------- ### Sequence Matching Examples Source: https://nim-lang.github.io/fusion/src/fusion/matching.html Demonstrates various sequence matching patterns, including size checks, capturing elements, and conditional matching. ```nim input sequence: `[1,2,3,4,5,6,5,6]` Pattern| Result| Comment ---|---|--- `[_]`| **Fail**| Input sequence size mismatch `[.._]`| **Ok**| `[@a]`| **Fail**| Input sequence size mismatch `[@a, .._]`| **Ok** , `a = 1`| `[any @a, .._]`| **Error**| `[any @a(it < 10)]`| **Ok** , `a = [1..6]`| Capture all elements that match `[until @a == 6, .._]`| **Ok**| All until first ocurrence of `6` `[all @a == 6, .._]`| **Ok** `a = []`| All leading `6` `[any @a(it > 100)]`| **Fail**| No elements `> 100` `[none @a(it in {6 .. 10})]`| **Fail**| There is an element `== 6` `[0 .. 2 is < 10, .._]`| **Ok**| First three elements `< 10` `[0 .. 2 is < 10]`| **Fail**| Missing trailing `.._` ``` -------------------------------- ### Example: Accessing Children by Index Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Demonstrates accessing and asserting the string representation of child nodes using index-based access. ```nim var f = newElement("myTag") f.add newElement("first") f.insert(newElement("second"), 0) assert $f[1] == "\n" assert $f[0] == "\n" ``` -------------------------------- ### Example: Adding Various Node Types Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Illustrates adding text, elements, and entities as children to an XmlNode and verifying the resulting string. ```nim var f = newElement("myTag") f.add newText("my text") f.add newElement("sonTag") f.add newEntity("my entity") assert $f == "my text&my entity;" ``` -------------------------------- ### Example: Finding a Child Element Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Demonstrates adding multiple child elements and then finding a specific child element by its name and asserting its string representation. ```nim var f = newElement("myTag") f.add newElement("firstSon") f.add newElement("secondSon") f.add newElement("thirdSon") assert $(f.child("secondSon")) == "\n" ``` -------------------------------- ### Example: Set Entity Text Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Illustrates creating an entity node and modifying its text content using the `text=` procedure. ```nim var e = newEntity("my entity") assert $e == "&my entity;" e.text = "a new entity text" assert $e == "&a new entity text;" ``` -------------------------------- ### Sequence Matching Use Cases Source: https://nim-lang.github.io/fusion/src/fusion/matching.html Provides practical examples of sequence matching for common tasks like capturing all elements or extracting data until a separator. ```nim * capture all elements in sequence: `[all @elems]` * get all elements until (not including "d"): `[until @a is "d"]` * All leading "d": `[all @leading is "d"]` * Match first two elements and ignore the rest `[_, _, .._]` * Match optional third element `[_, _, opt @trail]` * Match third element and if not matched use default value `[_, _, opt @trail or "default"]` * Capture all elements until first separator: `[until @leading is "sep", @middle is "sep", all @trailing]` * Extract all conditions from IfStmt: `IfStmt([all ElseIf([@cond, _]), .._])` ``` -------------------------------- ### Example: Set Element Tag Name Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Shows how to create an XML element, add a child, and then change the element's tag name using the `tag=` procedure. ```nim var a = newElement("firstTag") a.add newElement("childTag") assert $a == "\n \n \n" a.tag = "newTag" assert $a == "\n \n \n" ``` -------------------------------- ### Nim Variant Object Matching Examples Source: https://nim-lang.github.io/fusion/src/fusion/matching.html Demonstrates various ways to match on object variants using concise syntax. The `nnk` prefix can be omitted if enum names follow naming conventions. ```nim ForStmt Ident "i" Infix Ident ".." IntLit 1 IntLit 1 StmtList Command Ident "echo" IntLit 12 ``` ```nim ForStmt([== ident("i"), .._]) ``` ```nim ForStmt([@a is Ident(), .._]) ``` ```nim ForStmt([@a.isTuple(), .._]) ``` ```nim ForStmt([_, _, (len: in {1 .. 10})]) ``` ```nim ObjectName() ``` ```nim (fld: ) ``` ```nim (kind: in {nnkForStmt, nnkWhileStmt}) ``` -------------------------------- ### Example: Clearing an XmlTree Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Illustrates the effect of the 'clear' procedure by creating an XmlTree with various nodes and attributes, printing it, clearing it, and then printing it again to show the empty result. ```nim var g = newElement("myTag") g.add newText("some text") g.add newComment("this is comment") var h = newElement("secondTag") h.add newEntity("some entity") let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes var k = newXmlTree("treeTag", [g, h], att) echo k ## ## some text ## &some entity; ## clear(k) echo k ## ``` -------------------------------- ### Get Element Tag Name Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Gets the tag name of an XmlNode. The node must be an xnElement. Useful for identifying element types. ```nim proc tag(n: XmlNode): string {.inline, ...raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Option Matching with Some and None Source: https://nim-lang.github.io/fusion/src/fusion/matching.html Demonstrates how Some(@x) and None() are rewritten for better integration with optional types. This syntax works with any type providing isSome, isNone, and get functions. ```nim Some(@x) None() ``` -------------------------------- ### Get Node Text Content Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Gets the text content associated with a node. Applicable to CDATA, Text, comment, or entity nodes. Used for retrieving textual data within specific node types. ```nim proc text(n: XmlNode): string {.inline, ...raises: [], tags: [], forbids: [].} ``` -------------------------------- ### parsexml: proc getFilename Source: https://nim-lang.github.io/fusion/theindex.html Gets the filename from an XmlParser. ```APIDOC ## parsexml: proc getFilename ### Description Gets the filename from an XmlParser. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (string) - The filename. #### Response Example None ``` -------------------------------- ### Get or Default (`getOrDefault`) Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Procedures for retrieving an element's value by key, returning a default if the key is not found. ```APIDOC ## getOrDefault[A, B](t: OrderedTable[A, B]; key: A): B ### Description Retrieves the value associated with a key in an OrderedTable, or returns a default value if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (OrderedTable[A, B]) - The OrderedTable. - **key** (A) - The key to look up. ### Response - **B** - The value associated with the key, or the default value of type B. ``` ```APIDOC ## getOrDefault[A, B](t: OrderedTable[A, B]; key: A; default: B): B ### Description Retrieves the value associated with a key in an OrderedTable, returning a specified default value if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (OrderedTable[A, B]) - The OrderedTable. - **key** (A) - The key to look up. - **default** (B) - The default value to return if the key is not found. ### Response - **B** - The value associated with the key, or the provided default value. ``` ```APIDOC ## getOrDefault[A, B](t: OrderedTableRef[A, B]; key: A): B ### Description Retrieves the value associated with a key in an OrderedTableRef, or returns a default value if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (OrderedTableRef[A, B]) - The OrderedTableRef. - **key** (A) - The key to look up. ### Response - **B** - The value associated with the key, or the default value of type B. ``` ```APIDOC ## getOrDefault[A, B](t: OrderedTableRef[A, B]; key: A; default: B): B ### Description Retrieves the value associated with a key in an OrderedTableRef, returning a specified default value if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (OrderedTableRef[A, B]) - The OrderedTableRef. - **key** (A) - The key to look up. - **default** (B) - The default value to return if the key is not found. ### Response - **B** - The value associated with the key, or the provided default value. ``` ```APIDOC ## getOrDefault[A, B](t: Table[A, B]; x: A): B ### Description Retrieves the value associated with a key in a Table, or returns a default value if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (Table[A, B]) - The Table. - **x** (A) - The key to look up. ### Response - **B** - The value associated with the key, or the default value of type B. ``` ```APIDOC ## getOrDefault[A, B](t: Table[A, B]; x: A; default: B): B ### Description Retrieves the value associated with a key in a Table, returning a specified default value if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (Table[A, B]) - The Table. - **x** (A) - The key to look up. - **default** (B) - The default value to return if the key is not found. ### Response - **B** - The value associated with the key, or the provided default value. ``` ```APIDOC ## getOrDefault[A, B](t: TableRef[A, B]; key: A): B ### Description Retrieves the value associated with a key in a TableRef, or returns a default value if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (TableRef[A, B]) - The TableRef. - **key** (A) - The key to look up. ### Response - **B** - The value associated with the key, or the default value of type B. ``` ```APIDOC ## getOrDefault[A, B](t: TableRef[A, B]; key: A; default: B): B ### Description Retrieves the value associated with a key in a TableRef, returning a specified default value if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (TableRef[A, B]) - The TableRef. - **key** (A) - The key to look up. - **default** (B) - The default value to return if the key is not found. ### Response - **B** - The value associated with the key, or the provided default value. ``` ```APIDOC ## getOrDefault[A](t: CountTable[A]; key: A; default: int = 0): int ### Description Retrieves the count associated with a key in a CountTable, returning a default value (0) if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (CountTable[A]) - The CountTable. - **key** (A) - The key to look up. - **default** (int, optional, default=0) - The default value to return if the key is not found. ### Response - **int** - The count associated with the key, or the default value. ``` ```APIDOC ## getOrDefault[A](t: CountTableRef[A]; key: A; default: int): int ### Description Retrieves the count associated with a key in a CountTableRef, returning a specified default value if the key is not found. ### Method getOrDefault ### Endpoint N/A (Procedure Call) ### Parameters - **t** (CountTableRef[A]) - The CountTableRef. - **key** (A) - The key to look up. - **default** (int) - The default value to return if the key is not found. ### Response - **int** - The count associated with the key, or the provided default value. ``` -------------------------------- ### tag Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Gets the tag name of an `xnElement` node. ```APIDOC ## proc tag(n: XmlNode): string ### Description Gets the tag name of `n`. `n` has to be an `xnElement` node. ### Parameters * `n` (XmlNode) - The XML element node. ### Example ```nim var a = newElement("firstTag") a.add newElement("childTag") assert $a == "\n \n \n" assert a.tag == "firstTag" ``` ``` -------------------------------- ### Get Length of TableRef Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Returns the number of keys in a TableRef. ```nim let a = {'a': 5, 'b': 9}.newTable doAssert len(a) == 2 ``` -------------------------------- ### Example: Iterate Over Child Nodes Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Demonstrates iterating through the direct children of an XML element using the `items` iterator and printing their string representations. ```nim var g = newElement("myTag") g.add newText("some text") g.add newComment("this is comment") var h = newElement("secondTag") h.add newEntity("some entity") g.add h assert $g == "some text&some entity;" for x in g: # the same as `for x in items(g):` echo x # some text # # &some entity; ``` -------------------------------- ### Use withDir Template Source: https://nim-lang.github.io/fusion/src/fusion/scripting.html Demonstrates how to use the `withDir` template to temporarily change the current directory for executing code within a specific directory. ```nim withDir "foo": # inside foo directory # back to last directory ``` -------------------------------- ### matching: proc getKindNames Source: https://nim-lang.github.io/fusion/theindex.html Gets the kind names from a NimNode. ```APIDOC ## matching: proc getKindNames ### Description Gets the kind names from a NimNode. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (string, seq[string]) - A tuple containing the head kind name and a sequence of other kind names. #### Response Example None ``` -------------------------------- ### jsxmlhttprequest: proc getAllResponseHeaders Source: https://nim-lang.github.io/fusion/theindex.html Gets all response headers from an XMLHttpRequest. ```APIDOC ## jsxmlhttprequest: proc getAllResponseHeaders ### Description Gets all response headers from an XMLHttpRequest. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (cstring) - A C-style string containing all response headers. #### Response Example None ``` -------------------------------- ### open Source: https://nim-lang.github.io/fusion/src/fusion/js/jsxmlhttprequest.html Initializes a request that will be sent to a server. ```APIDOC ## open(this: XMLHttpRequest; metod, url: cstring; async = true; user = cstring.default; password = cstring.default) ### Description Opens a connection to another network location. This method prepares the XMLHttpRequest object for the request but does not send it. ### Parameters - **metod** (cstring) - The HTTP method to use (e.g., "GET", "POST"). - **url** (cstring) - The URL to send the request to. - **async** (bool, optional) - Whether the request should be asynchronous. Defaults to true. - **user** (cstring, optional) - The username for authentication. Defaults to an empty string. - **password** (cstring, optional) - The password for authentication. Defaults to an empty string. ``` -------------------------------- ### parsexml: proc errorMsg Source: https://nim-lang.github.io/fusion/theindex.html Gets the error message from an XmlParser. ```APIDOC ## parsexml: proc errorMsg ### Description Gets the error message from an XmlParser. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (string) - The error message. #### Response Example None ``` -------------------------------- ### Initialization (`initCountTable`, `initOrderedTable`, `initTable`) Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Procedures for creating new instances of CountTable, OrderedTable, and Table. ```APIDOC ## initCountTable[A](initialSize = 64): CountTable[A] ### Description Initializes a new CountTable with a specified initial size. ### Method initCountTable ### Endpoint N/A (Procedure Call) ### Parameters - **initialSize** (int, optional, default=64) - The initial capacity of the CountTable. ### Response - **CountTable[A]** - A new, empty CountTable. ``` ```APIDOC ## initOrderedTable[A, B](initialSize = 64): OrderedTable[A, B] ### Description Initializes a new OrderedTable with a specified initial size. ### Method initOrderedTable ### Endpoint N/A (Procedure Call) ### Parameters - **initialSize** (int, optional, default=64) - The initial capacity of the OrderedTable. ### Response - **OrderedTable[A, B]** - A new, empty OrderedTable. ``` ```APIDOC ## initTable[A, B](initialSize = 0): Table[A, B] ### Description Initializes a new Table with a specified initial size. ### Method initTable ### Endpoint N/A (Procedure Call) ### Parameters - **initialSize** (int, optional, default=0) - The initial capacity of the Table. ### Response - **Table[A, B]** - A new, empty Table. ``` -------------------------------- ### parsexml: template entityName Source: https://nim-lang.github.io/fusion/theindex.html Gets the entity name from an XmlParser. ```APIDOC ## parsexml: template entityName ### Description Gets the entity name from an XmlParser. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (string) - The entity name. #### Response Example None ``` -------------------------------- ### Create and Populate an XML Tree Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Demonstrates creating a new XML element, adding text and comments, creating another element with an entity, and then combining them into a parent XML tree with attributes. Finally, it prints the generated XML. ```nim import xmltree var g = newElement("myTag") g.add newText("some text") g.add newComment("this is comment") var h = newElement("secondTag") h.add newEntity("some entity") let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes let k = newXmlTree("treeTag", [g, h], att) echo k # # some text # &some entity; # ``` -------------------------------- ### parsexml: template elementName Source: https://nim-lang.github.io/fusion/theindex.html Gets the element name from an XmlParser. ```APIDOC ## parsexml: template elementName ### Description Gets the element name from an XmlParser. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (string) - The element name. #### Response Example None ``` -------------------------------- ### Tree Matching for ProcDef AST Source: https://nim-lang.github.io/fusion/src/fusion/matching.html An example of matching a Nim procedure declaration's AST structure. This pattern demonstrates how to capture specific parts of the AST like the procedure name, parameters, and implementation. ```nim procDecl.assertMatch: ProcDef: Ident(strVal: @name) | Postfix[_, Ident(strVal: @name)] _ # Term rewriting template _ # Generic params FormalParams: @returnType all IdentDefs[@trailArgsName, _, _] @pragmas _ # Reserved @implementation ``` -------------------------------- ### Variable of Iteration Template Source: https://nim-lang.github.io/fusion/src/fusion/matching.html Template to get the variable of an iteration. ```nim template varOfIteration(arg: untyped): untyped ``` -------------------------------- ### `[]` (Get child by index) Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Retrieves the i'th child of an XmlNode. ```APIDOC ## `[]` (Get child by index) ### Description Returns the `i`'th child of `n`. ### Method `[]` ### Parameters - **n** (XmlNode) - The parent XML node. - **i** (int) - The index of the child node. ### Returns XmlNode - The child node at the specified index. ### Example ```nim var f = newElement("myTag") f.add newElement("first") f.insert(newElement("second"), 0) assert $f[1] == "\n" assert $f[0] == "\n" ``` ``` -------------------------------- ### valuesFrom Source: https://nim-lang.github.io/fusion/theindex.html Iterates over values in a table starting from a specified key. ```APIDOC ## valuesFrom ### Description Iterates over values in a table starting from a specified key. ### Signature `iterator valuesFrom[A, B](b: Table[A, B]; fromKey: A): B` ### Module `btreetables` ``` -------------------------------- ### Initialize an Empty Ordered Table Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Demonstrates how to initialize an empty ordered table with specified key and value types. ```nim let a = initOrderedTable[int, string]() ``` -------------------------------- ### parsexml: proc getLine Source: https://nim-lang.github.io/fusion/theindex.html Gets the current line number from an XmlParser. ```APIDOC ## parsexml: proc getLine ### Description Gets the current line number from an XmlParser. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (int) - The current line number. #### Response Example None ``` -------------------------------- ### parsexml: proc getColumn Source: https://nim-lang.github.io/fusion/theindex.html Gets the current column number from an XmlParser. ```APIDOC ## parsexml: proc getColumn ### Description Gets the current column number from an XmlParser. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (int) - The current column number. #### Response Example None ``` -------------------------------- ### parsexml: proc errorMsgExpected Source: https://nim-lang.github.io/fusion/theindex.html Gets an expected error message from an XmlParser. ```APIDOC ## parsexml: proc errorMsgExpected ### Description Gets an expected error message from an XmlParser. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (string) - The expected error message. #### Response Example None ``` -------------------------------- ### Get String Representation of NimNode Source: https://nim-lang.github.io/fusion/src/fusion/matching.html Returns the string representation of a NimNode. ```nim func str(node: NimNode): string {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### AST DSL Build AST Source: https://nim-lang.github.io/fusion/theindex.html Macros for building Abstract Syntax Trees. ```APIDOC ## `buildAst` Macros for `astdsl` ### Description Macros provided by the `astdsl` module for constructing Abstract Syntax Trees (ASTs). ### Methods - `macro buildAst`(children: untyped): NimNode - `macro buildAst`(node, children: untyped): NimNode ``` -------------------------------- ### getLine Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/parsexml.html Gets the current line the parser has arrived at. This is an inline procedure. ```APIDOC ## proc getLine(my: XmlParser): int ### Description Gets the current line the parser has arrived at. ### Method `getLine` ### Parameters * **my** (XmlParser) - The XML parser instance. ### Returns (int) - The current line number. ``` -------------------------------- ### getFilename Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/parsexml.html Gets the filename of the file that the parser processes. This is an inline procedure. ```APIDOC ## proc getFilename(my: XmlParser): string ### Description Gets the filename of the file that the parser processes. ### Method `getFilename` ### Parameters * **my** (XmlParser) - The XML parser instance. ### Returns (string) - The filename being processed. ``` -------------------------------- ### Build AST Macro Source: https://nim-lang.github.io/fusion/theindex.html Constructs an Abstract Syntax Tree (AST). ```APIDOC ## `buildAst` Macro ### Description Constructs an Abstract Syntax Tree (AST) node, potentially from a list of children or a specific node and its children. ### Methods - `macro buildAst`(children: untyped): NimNode - `macro buildAst`(node, children: untyped): NimNode ``` -------------------------------- ### getColumn Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/parsexml.html Gets the current column the parser has arrived at. This is an inline procedure. ```APIDOC ## proc getColumn(my: XmlParser): int ### Description Gets the current column the parser has arrived at. ### Method `getColumn` ### Parameters * **my** (XmlParser) - The XML parser instance. ### Returns (int) - The current column number. ``` -------------------------------- ### Get Length of Table Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Returns the number of keys in a Table. This is an inline procedure. ```nim let a = {'a': 5, 'b': 9}.toTable doAssert len(a) == 2 ``` -------------------------------- ### initTable Source: https://nim-lang.github.io/fusion/theindex.html Initializes a new Table with an optional initial size. ```APIDOC ## proc initTable[A, B](initialSize = 0): Table[A, B] ### Description Initializes and returns a new Table. ### Parameters * **initialSize** (int) - The initial capacity of the table (defaults to 0). ### Returns (Table[A, B]) A new, empty Table. ``` -------------------------------- ### Get Length of OrderedTableRef Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Returns the number of keys in an OrderedTableRef. This is an inline procedure. ```nim let a = {'a': 5, 'b': 9}.newOrderedTable doAssert len(a) == 2 ``` -------------------------------- ### Get Length of OrderedTable Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Returns the number of keys in an OrderedTable. This is an inline procedure. ```nim let a = {'a': 5, 'b': 9}.toOrderedTable doAssert len(a) == 2 ``` -------------------------------- ### Create and Use XMLSerializer Source: https://nim-lang.github.io/fusion/src/fusion/js/jsxmlserializer.html Demonstrates how to create a new XMLSerializer instance and use it to serialize the entire document to a string. This requires the `fusionJsXMLSerializerTests` compilation flag to be defined. ```nim import src/fusion/js/jsxmlserializer from std/dom import document if defined(fusionJsXMLSerializerTests): let cerealizer: XMLSerializer = newXMLSerializer() echo cerealizer.serializeToString(node = document) ``` -------------------------------- ### Length (`len`) Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Procedures for getting the number of elements in various table types. ```APIDOC ## len[A, B](t: OrderedTable[A, B]): int ### Description Returns the number of elements in an OrderedTable. ### Method len ### Endpoint N/A (Procedure Call) ### Parameters - **t** (OrderedTable[A, B]) - The OrderedTable. ### Response - **int** - The number of elements. ``` ```APIDOC ## len[A, B](t: OrderedTableRef[A, B]): int ### Description Returns the number of elements in an OrderedTableRef. ### Method len ### Endpoint N/A (Procedure Call) ### Parameters - **t** (OrderedTableRef[A, B]) - The OrderedTableRef. ### Response - **int** - The number of elements. ``` ```APIDOC ## len[A, B](t: Table[A, B]): int ### Description Returns the number of elements in a Table. ### Method len ### Endpoint N/A (Procedure Call) ### Parameters - **t** (Table[A, B]) - The Table. ### Response - **int** - The number of elements. ``` ```APIDOC ## len[A, B](t: TableRef[A, B]): int ### Description Returns the number of elements in a TableRef. ### Method len ### Endpoint N/A (Procedure Call) ### Parameters - **t** (TableRef[A, B]) - The TableRef. ### Response - **int** - The number of elements. ``` ```APIDOC ## len[A](t: CountTable[A]): int ### Description Returns the number of elements in a CountTable. ### Method len ### Endpoint N/A (Procedure Call) ### Parameters - **t** (CountTable[A]) - The CountTable. ### Response - **int** - The number of elements. ``` ```APIDOC ## len[A](t: CountTableRef[A]): int ### Description Returns the number of elements in a CountTableRef. ### Method len ### Endpoint N/A (Procedure Call) ### Parameters - **t** (CountTableRef[A]) - The CountTableRef. ### Response - **int** - The number of elements. ``` -------------------------------- ### XML Tree Creation and Manipulation Source: https://nim-lang.github.io/fusion/src/fusion/htmlparser/xmltree.html Demonstrates how to create an XML tree using `newElement`, `add`, `newText`, `newComment`, `newEntity`, and `newXmlTree`. It also shows how to add attributes using `toXmlAttributes`. ```APIDOC ## XML Tree Generation Example ### Description This example shows the basic usage of the `xmltree` module to construct an XML document programmatically. It covers creating elements, adding text and comments, and assembling a complete XML tree with attributes. ### Method N/A (Illustrative Example) ### Endpoint N/A (SDK Usage) ### Parameters N/A ### Request Example ```nim import xmltree var g = newElement("myTag") g.add newText("some text") g.add newComment("this is comment") var h = newElement("secondTag") h.add newEntity("some entity") let att = {"key1": "first value", "key2": "second value"}.toXmlAttributes let k = newXmlTree("treeTag", [g, h], att) echo k ``` ### Response #### Success Response (Output) ``` some text &some entity; ``` ``` -------------------------------- ### Initialize Table Source: https://nim-lang.github.io/fusion/src/fusion/btreetables.html Creates a new empty Table. The initialSize parameter is for compatibility with hash table APIs and has no effect on BTree tables. ```nim let a = initTable[int, string]() b = initTable[char, seq[int]]() ``` -------------------------------- ### btreetables: proc getOrDefault Source: https://nim-lang.github.io/fusion/theindex.html Gets a value from a CountTable or returns a default value. ```APIDOC ## btreetables: proc getOrDefault ### Description Gets a value from a CountTable or returns a default value. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **return value** (int or B) - The value from the table or the default value. #### Response Example None ``` -------------------------------- ### Get Element from smartptrs Source: https://nim-lang.github.io/fusion/theindex.html Dereferences smart pointers to access the managed value. ```APIDOC ## Get Element (`[]`) for `smartptrs` ### Description Dereferences a smart pointer (`ConstPtr`, `SharedPtr`, `UniquePtr`) to access the managed value. Returns a variable reference for mutable pointers. ### Methods - `proc []`[T](p: ConstPtr[T]): lent T - `proc []`[T](p: SharedPtr[T]): var T - `proc []`[T](p: UniquePtr[T]): var T ``` -------------------------------- ### Get Element from btreetables Source: https://nim-lang.github.io/fusion/theindex.html Retrieves elements from CountTable, OrderedTable, and Table by key. ```APIDOC ## Get Element (`[]`) from `btreetables` ### Description Retrieves the value associated with a key from `CountTable`, `OrderedTable`, or `Table`. For mutable references, it returns a variable reference. ### Methods - `proc []`[A](t: CountTable[A]; key: A): int - `proc []`[A](t: CountTableRef[A]; key: A): int - `proc []`[A, B](t: OrderedTable[A, B]; key: A): B - `proc []`[A, B](t: var OrderedTable[A, B]; key: A): var B - `proc []`[A, B](t: OrderedTableRef[A, B]; key: A): var B - `proc []`[A, B](t: Table[A, B]; x: A): B - `proc []`[A, B](t: var Table[A, B]; x: A): var B - `proc []`[A, B](t: TableRef[A, B]; key: A): var B ``` -------------------------------- ### Get Element from Tuple Source: https://nim-lang.github.io/fusion/theindex.html Accesses a tuple element by a static field index. ```APIDOC ## `[]` Operator for Tuples ### Description Accesses an element within a tuple using a compile-time known `FieldIndex`. ### Methods - `template []`(t: tuple; idx: static[FieldIndex]): untyped ``` -------------------------------- ### BuildAst Macros Source: https://nim-lang.github.io/fusion/theindex.html Macros for building Abstract Syntax Trees (ASTs). ```APIDOC ## `buildAst` Macros ### Description Macros used to construct Abstract Syntax Trees (ASTs) from provided nodes and children. ### Methods - `macro buildAst`(children: untyped): NimNode - `macro buildAst`(node, children: untyped): NimNode ``` -------------------------------- ### Get Element from Smart Pointers Source: https://nim-lang.github.io/fusion/theindex.html Accesses the value managed by a smart pointer. ```APIDOC ## `[]` Operator for Smart Pointers ### Description Dereferences smart pointers (`ConstPtr`, `SharedPtr`, `UniquePtr`) to access the underlying managed value. For mutable pointers, it returns a variable reference. ### Methods - `proc []`[T](p: ConstPtr[T]): lent T - `proc []`[T](p: SharedPtr[T]): var T - `proc []`[T](p: UniquePtr[T]): var T ```