Skip to content

Commit

Permalink
fix stream type
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Aug 29, 2024
1 parent 5e8cc5d commit 51c9272
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/timpkg/engine/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type
ntInclude = "Include"
ntImport = "Import"
ntPlaceholder = "Placeholder"
ntStream = "Stream"
ntStream = "stream"
ntJavaScriptSnippet = "JavaScriptSnippet"
ntYamlSnippet = "YAMLSnippet"
ntJsonSnippet = "JsonSnippet"
Expand Down Expand Up @@ -133,6 +133,7 @@ type
typeString = "string"
typeFloat = "float"
typeBool = "bool"
typeStream = "stream"
typeArray = "array"
typeObject = "object"
typeFunction = "function"
Expand Down
22 changes: 12 additions & 10 deletions src/timpkg/engine/compilers/html.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/timpkg/engine/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const
tkComparable = tkAssignableSet
tkTypedLiterals = {
tkLitArray, tkLitBool, tkLitFloat, tkLitFunction,
tkLitInt, tkLitObject, tkLitString, tkBlock
tkLitInt, tkLitObject, tkLitString, tkBlock, tkLitStream
}

#
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/timpkg/engine/std.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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")]),
Expand Down Expand Up @@ -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.}:
Expand Down
1 change: 1 addition & 0 deletions src/timpkg/engine/tokens.nim
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ registerTokens toktokSettings:
litObject = "object"
litArray = "array"
litFunction = "function"
litStream = "stream"
litVoid = "void"

# magics
Expand Down

0 comments on commit 51c9272

Please sign in to comment.