Skip to content

Commit

Permalink
update comment | bugfix pos checker
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Mar 27, 2024
1 parent 20da5cc commit eeb74de
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
6 changes: 3 additions & 3 deletions nyml.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

version = "0.1.6"
author = "George Lemon"
description = "A stupid simple YAML Parser. From YAML to stringified JSON (fastest) or JsonNode"
description = "A stupid simple YAML Parser. YAML to stringified JSON, JsonNode or Nim objects via pkg/jsony"
license = "MIT"
srcDir = "src"
# Dependencies
Expand All @@ -16,7 +16,7 @@ task tests, "Run test":

task dev, "compile nyml":
echo "\n✨ Compiling..." & "\n"
exec "nim --gc:arc --out:bin/nyml --hints:off --threads:on c src/nyml.nim"
exec "nim --mm:arc --out:bin/nyml --hints:off --threads:on c src/nyml.nim"

task bench, "benchmark":
exec "nim c --gc:arc -d:danger -d:release benchmarks/test.nim"
exec "nim c --mm:arc -d:danger -d:release benchmarks/test.nim"
15 changes: 7 additions & 8 deletions src/nyml.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# A stupid simple YAML-like parser.
# A stupid simple YAML-like parser. From YAML to JsonNode,
# stringified JSON or Nim objects via pkg/jsony.
#
# Can parse YAML to JsonNode, stringified JSON or Nim objects via JSONY
#
# (c) 2023 yamlike | MIT License
# Made by Humans from OpenPeep
# https://github.com/openpeeps/yamlike
# (c) 2023 nyml | MIT License
# Made by Humans from OpenPeeps
# https://github.com/openpeeps/nyml

import jsony
import std/macros
Expand Down Expand Up @@ -70,5 +69,5 @@ template fromYaml*(str: string, obj: typedesc[object]): untyped =
jsony.fromJson(jsonContent, obj)

# when isMainModule:
# # echo yaml(readFile("test.yml"), data = %*{"hello": "yepsi"})
# echo yaml(readFile("test.yml"), data = %*{"hello": "yepsi"}).toJsonStr()
# echo yaml(readFile("test.yml"), data = %*{"hello": "yepsi"})
# echo yaml(readFile("test.yml"), data = %*{"hello": "yepsi"}).toJsonStr()
11 changes: 5 additions & 6 deletions src/nyml/dump.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# A stupid simple YAML-like parser.
# A stupid simple YAML-like parser. From YAML to JsonNode,
# stringified JSON or Nim objects via pkg/jsony.
#
# Can parse YAML to JsonNode, stringified JSON or Nim objects via JSONY
#
# (c) 2023 yamlike | MIT License
# Made by Humans from OpenPeep
# https://github.com/openpeeps/yamlike
# (c) 2023 nyml | MIT License
# Made by Humans from OpenPeeps
# https://github.com/openpeeps/nyml

import jsony
import std/[json, strutils]
Expand Down
11 changes: 5 additions & 6 deletions src/nyml/meta.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# A stupid simple YAML-like parser.
# A stupid simple YAML-like parser. From YAML to JsonNode,
# stringified JSON or Nim objects via pkg/jsony.
#
# Can parse YAML to JsonNode, stringified JSON or Nim objects via JSONY
#
# (c) 2023 yamlike | MIT License
# Made by Humans from OpenPeep
# https://github.com/openpeeps/yamlike
# (c) 2023 nyml | MIT License
# Made by Humans from OpenPeeps
# https://github.com/openpeeps/nyml

import std/json
from std/strutils import `%`, contains, split, join
Expand Down
16 changes: 8 additions & 8 deletions src/nyml/parser.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# A stupid simple YAML-like parser.
# A stupid simple YAML-like parser. From YAML to JsonNode,
# stringified JSON or Nim objects via pkg/jsony.
#
# Can parse YAML to JsonNode, stringified JSON or Nim objects via JSONY
#
# (c) 2023 yamlike | MIT License
# Made by Humans from OpenPeep
# https://github.com/openpeeps/yamlike
# (c) 2023 nyml | MIT License
# Made by Humans from OpenPeeps
# https://github.com/openpeeps/nyml

import toktok
import std/[json, jsonutils]
Expand Down Expand Up @@ -413,7 +412,7 @@ proc parseObject(p: var Parser, this: TokenTuple): Node =
if p.curr.kind == tkIdentifier and p.curr.pos == this.pos:
p.setError("Invalid indentation")
return
while p.curr.pos >= this.pos and p.curr.kind in {tkIdentifier, tkHyphen}:
while p.curr.pos > this.pos and p.curr.kind in {tkIdentifier, tkHyphen}:
if p.curr.kind == tkIdentifier and p.next.kind != tkColon:
p.setError("Missing assignment token")
return
Expand Down Expand Up @@ -472,7 +471,8 @@ proc parseYAML*(yml: YAML, strContents: string): Parser =
if p.rootType == Array:
p.writeNodes(p.program.nodes)
else:
echo p.program.nodes
p.code &= "{"
p.writeNodes(p.program.nodes)
p.code &= "}"
result = p
result = p

0 comments on commit eeb74de

Please sign in to comment.