diff --git a/.gitignore b/.gitignore index c68b95d..3c0dbb6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ package-lock.json nimble.develop nimble.paths vendor +tests/test_all diff --git a/toml_serialization.nim b/toml_serialization.nim index 3f7bbc1..f2643bb 100644 --- a/toml_serialization.nim +++ b/toml_serialization.nim @@ -91,7 +91,7 @@ template tomlDecodeImpl*(input: untyped, # from the fact that the dynamic dispatch mechanisms used in # faststreams may be reading from a file or a network device. try: - let stream = memInputStream(input) + let stream = unsafeMemoryInput(input) var reader = unpackArgs(init, [TomlReader, stream, tomlCase, params]) when RecordType is (seq or array) and uTypeIsRecord(RecordType): reader.readTableArray(RecordType, key, tomlCase) @@ -143,7 +143,7 @@ template tomlLoadImpl*(filename: string, var stream: InputStream when nimvm: let input = staticRead(filename) - stream = VMInputStream(pos: 0, data: toVMString(input)) + stream = unsafeMemoryInput(input) else: stream = memFileInput(filename) try: diff --git a/toml_serialization.nimble b/toml_serialization.nimble index 333a8c6..7d9c458 100644 --- a/toml_serialization.nimble +++ b/toml_serialization.nimble @@ -8,6 +8,7 @@ license = "Apache License 2.0" skipDirs = @["tests", "assets"] requires "nim >= 1.6.0", + "faststreams >= 0.5.0", "serialization", "stew" diff --git a/toml_serialization/lexer.nim b/toml_serialization/lexer.nim index 47f46bc..9c337ef 100644 --- a/toml_serialization/lexer.nim +++ b/toml_serialization/lexer.nim @@ -66,22 +66,13 @@ const invalidCommentChar = {'\x00'..'\x08', '\x0A'..'\x1F', '\x7F'} template readChar*(lex: TomlLexer): char = - when nimvm: - read(VMInputStream(lex.stream)) - else: - char inputs.read(lex.stream) + char inputs.read(lex.stream) template readable*(lex: TomlLexer): bool = - when nimvm: - readable(VMInputStream(lex.stream)) - else: - lex.stream.readable() + lex.stream.readable() template peekChar*(lex: TomlLexer): char = - when nimvm: - peekChar(VMInputStream(lex.stream)) - else: - lex.stream.peek().char + lex.stream.peek().char proc lineInfo(lex: TomlLexer): (int, int) {.inline.} = (lex.line, lex.col) @@ -1930,7 +1921,7 @@ proc parseKeyValue*(lex: var TomlLexer, checkEol(lex, line) proc parseKey*(key: string, tomlCase: TomlCase): seq[string] = - let stream = memInputStream(key) + let stream = unsafeMemoryInput(key) var lex = init(TomlLexer, stream) lex.scanKey(result) diff --git a/toml_serialization/types.nim b/toml_serialization/types.nim index 5c22476..8cfae16 100644 --- a/toml_serialization/types.nim +++ b/toml_serialization/types.nim @@ -245,33 +245,13 @@ proc toUgly(result: var string, p: TomlValueRef) = proc `$`*(p: TomlValueRef): string = toUgly(result, p) -type - VMInputStream* = ref object of InputStream - pos*: int - data*: string - -proc read*(s: VMInputStream): char = - result = s.data[s.pos] - inc s.pos - -proc readable*(s: VMInputStream): bool = - s.pos < s.data.len - -proc peekChar*(s: VMInputStream): char = - s.data[s.pos] - -template toVMString*(x: openArray[byte]): string = +template toVMString*(x: openArray[byte]): string {.deprecated.} = var z = newString(x.len) for i, c in x: z[i] = char(c) z -template toVMString*(x: string): string = +template toVMString*(x: string): string {.deprecated.} = x -template memInputStream*(input: untyped): auto = - var stream: InputStream - when nimvm: - stream = VMInputStream(pos: 0, data: toVMString(input)) - else: - stream = unsafeMemoryInput(input) - stream +template memInputStream*(input: untyped): auto {.deprecated: "use unsafeMemoryInput".} = + unsafeMemoryInput(input)