From 51c9272b681c0105a2a98acf758e99ce65a3f4d9 Mon Sep 17 00:00:00 2001 From: George Lemon Date: Thu, 29 Aug 2024 21:01:54 +0300 Subject: [PATCH] fix `stream` type Signed-off-by: George Lemon --- src/timpkg/engine/ast.nim | 3 ++- src/timpkg/engine/compilers/html.nim | 22 ++++++++++++---------- src/timpkg/engine/parser.nim | 4 +++- src/timpkg/engine/std.nim | 8 ++++---- src/timpkg/engine/tokens.nim | 1 + 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/timpkg/engine/ast.nim b/src/timpkg/engine/ast.nim index da2234f..d517ab1 100755 --- a/src/timpkg/engine/ast.nim +++ b/src/timpkg/engine/ast.nim @@ -56,7 +56,7 @@ type ntInclude = "Include" ntImport = "Import" ntPlaceholder = "Placeholder" - ntStream = "Stream" + ntStream = "stream" ntJavaScriptSnippet = "JavaScriptSnippet" ntYamlSnippet = "YAMLSnippet" ntJsonSnippet = "JsonSnippet" @@ -133,6 +133,7 @@ type typeString = "string" typeFloat = "float" typeBool = "bool" + typeStream = "stream" typeArray = "array" typeObject = "object" typeFunction = "function" diff --git a/src/timpkg/engine/compilers/html.nim b/src/timpkg/engine/compilers/html.nim index 8086a1d..c0e5501 100755 --- a/src/timpkg/engine/compilers/html.nim +++ b/src/timpkg/engine/compilers/html.nim @@ -328,6 +328,16 @@ proc dumpHook*(s: var string, v: OrderedTableRef[string, Node]) = inc i s.add("}") +proc toString(node: JsonNode, escape = false): string = + result = + case node.kind + of JString: node.str + of JInt: $node.num + of JFloat: $node.fnum + of JBool: $node.bval + of JObject, JArray: $(node) + else: "null" + proc toString(node: Node, escape = false): string = if likely(node != nil): result = @@ -336,6 +346,7 @@ proc toString(node: Node, escape = false): string = of ntLitInt: $node.iVal of ntLitFloat: $node.fVal of ntLitBool: $node.bVal + of ntStream: toString(node.streamContent) of ntLitObject: if not escape: # fromJson(jsony.toJson(node.objectItems)).pretty @@ -390,16 +401,6 @@ proc toString(c: var HtmlCompiler, node: Node, if escape: result = escapeValue(result) -proc toString(node: JsonNode, escape = false): string = - result = - case node.kind - of JString: node.str - of JInt: $node.num - of JFloat: $node.fnum - of JBool: $node.bval - of JObject, JArray: $(node) - else: "null" - proc toString(value: Value, escape = false): string = result = case value.kind @@ -419,6 +420,7 @@ proc getDataType(node: Node): DataType = of ntLitArray: typeArray of ntLitObject: typeObject of ntFunction: typeFunction + of ntStream: typeStream of ntBlock, ntStmtList: typeBlock of ntHtmlElement: typeHtmlElement diff --git a/src/timpkg/engine/parser.nim b/src/timpkg/engine/parser.nim index a6c84ca..eec2f99 100755 --- a/src/timpkg/engine/parser.nim +++ b/src/timpkg/engine/parser.nim @@ -51,7 +51,7 @@ const tkComparable = tkAssignableSet tkTypedLiterals = { tkLitArray, tkLitBool, tkLitFloat, tkLitFunction, - tkLitInt, tkLitObject, tkLitString, tkBlock + tkLitInt, tkLitObject, tkLitString, tkBlock, tkLitStream } # @@ -233,6 +233,7 @@ proc getType(kind: TokenKind): NodeType = of tkLitArray: ntLitArray of tkLitObject: ntLitObject of tkLitFunction: ntFunction + of tkLitStream: ntStream of tkBlock: ntBlock of tkIdentifier: ntHtmlElement @@ -248,6 +249,7 @@ proc getDataType(p: var Parser): DataType = of tkLitArray: typeArray of tkLitObject: typeObject of tkLitFunction: typeFunction + of tkLitStream: typeStream of tkBlock: typeBlock of tkIdentifier: typeHtmlElement diff --git a/src/timpkg/engine/std.nim b/src/timpkg/engine/std.nim index 2235225..e14180e 100644 --- a/src/timpkg/engine/std.nim +++ b/src/timpkg/engine/std.nim @@ -130,8 +130,8 @@ macro initStandardLibrary() = let fnSystem = @[ - # fwd("json", ntStream, [(ntLitString, "path")], wrapper = getAst(systemStreamFunction())), - # fwd("yaml", ntStream, [(ntLitString, "path")], wrapper = getAst(systemStreamFunction())), + fwd("json", ntStream, [(ntLitString, "path")], wrapper = getAst(systemStreamFunction())), + fwd("yaml", ntStream, [(ntLitString, "path")], wrapper = getAst(systemStreamFunction())), fwd("rand", ntLitInt, [(ntLitInt, "max")], "random", wrapper = getAst(systemRandomize())), fwd("len", ntLitInt, [(ntLitString, "x")]), # fwd("len", ntLitInt, [(ntLitArray, "x")]), @@ -436,8 +436,8 @@ macro initStandardLibrary() = ) # when not defined release: # echo result.repr - # echo "std/" & lib[2] - # echo sourceCode + echo "std/" & lib[2] + echo sourceCode proc initModuleSystem* = {.gcsafe.}: diff --git a/src/timpkg/engine/tokens.nim b/src/timpkg/engine/tokens.nim index 846b36e..4998a96 100755 --- a/src/timpkg/engine/tokens.nim +++ b/src/timpkg/engine/tokens.nim @@ -226,6 +226,7 @@ registerTokens toktokSettings: litObject = "object" litArray = "array" litFunction = "function" + litStream = "stream" litVoid = "void" # magics