Stop using the AsciiStream flavour

This commit is contained in:
Zahary Karadjov 2020-04-13 17:01:49 +03:00
parent 16931f4fa3
commit a8c5604808
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 9 additions and 9 deletions

View File

@ -41,7 +41,7 @@ type
errNonPortableInt = "number is outside the range of portable values"
JsonLexer* = object
stream: AsciiInputStream
stream: InputStream
mode*: JsonMode
line*: int
@ -61,6 +61,12 @@ const
1e20, 1e21, 1e22] # TODO: this table should be much larger
# The largest JSON number value is 1E308
template peek(s: InputStream): char =
char input_stream.peek(s)
template read(s: InputStream): char =
char input_stream.read(s)
proc hexCharValue(c: char): int {.inline.} =
case c
of '0'..'9': ord(c) - ord('0')
@ -77,7 +83,7 @@ proc col*(lexer: JsonLexer): int =
proc tokenStartCol*(lexer: JsonLexer): int =
1 + lexer.tokenStart - lexer.lineStartPos
proc init*(T: type JsonLexer, stream: AsciiInputStream, mode = defaultJsonMode): T =
proc init*(T: type JsonLexer, stream: InputStream, mode = defaultJsonMode): T =
T(stream: stream,
mode: mode,
line: 1,
@ -89,9 +95,6 @@ proc init*(T: type JsonLexer, stream: AsciiInputStream, mode = defaultJsonMode):
floatVal: 0'f,
strVal: "")
proc init*(T: type JsonLexer, stream: InputStream, mode = defaultJsonMode): T =
init(JsonLexer, AsciiInputStream(stream), mode)
template error(error: JsonErrorKind) {.dirty.} =
lexer.err = error
lexer.tok = tkError

View File

@ -61,9 +61,6 @@ method formatMsg*(err: ref GenericJsonReaderError, filename: string): string =
method formatMsg*(err: ref IntOverflowError, filename: string): string =
fmt"{filename}({err.line}, {err.col}) The value '{err.valueStr}' is outside of the allowed range"
template init*(T: type JsonReader, stream: InputStream, mode = defaultJsonMode): auto =
init JsonReader, AsciiInputStream(stream), mode
proc assignLineNumber*(ex: ref JsonReaderError, r: JsonReader) =
ex.line = r.lexer.line
ex.col = r.lexer.tokenStartCol
@ -100,7 +97,7 @@ proc handleReadException*(r: JsonReader,
ex.innerException = err
raise ex
proc init*(T: type JsonReader, stream: AsciiInputStream, mode = defaultJsonMode): T =
proc init*(T: type JsonReader, stream: InputStream, mode = defaultJsonMode): T =
result.lexer = JsonLexer.init(stream, mode)
result.lexer.next()