Small grammar fixes in json.nim (#5758)

This commit is contained in:
Daniil Yarancev 2017-04-26 21:29:53 +03:00 • committed by Andreas Rumpf
commit 40f79e6cdd

View file

@ -1213,22 +1213,22 @@ when not defined(js):
proc parseJson*(s: Stream, filename: string): JsonNode = proc parseJson*(s: Stream, filename: string): JsonNode =
## Parses from a stream `s` into a `JsonNode`. `filename` is only needed ## Parses from a stream `s` into a `JsonNode`. `filename` is only needed
## for nice error messages. ## for nice error messages.
## If `s` contains extra data, it will raising `JsonParsingError`. ## If `s` contains extra data, it will raise `JsonParsingError`.
var p: JsonParser var p: JsonParser
p.open(s, filename) p.open(s, filename)
defer: p.close() defer: p.close()
discard getTok(p) # read first token discard getTok(p) # read first token
result = p.parseJson() result = p.parseJson()
eat(p, tkEof) # check there are no exstra data eat(p, tkEof) # check if there is no extra data
proc parseJson*(buffer: string): JsonNode = proc parseJson*(buffer: string): JsonNode =
## Parses JSON from `buffer`. ## Parses JSON from `buffer`.
## If `buffer` contains extra data, it will raising `JsonParsingError`. ## If `buffer` contains extra data, it will raise `JsonParsingError`.
result = parseJson(newStringStream(buffer), "input") result = parseJson(newStringStream(buffer), "input")
proc parseFile*(filename: string): JsonNode = proc parseFile*(filename: string): JsonNode =
## Parses `file` into a `JsonNode`. ## Parses `file` into a `JsonNode`.
## If `file` contains extra data, it will raising `JsonParsingError`. ## If `file` contains extra data, it will raise `JsonParsingError`.
var stream = newFileStream(filename, fmRead) var stream = newFileStream(filename, fmRead)
if stream == nil: if stream == nil:
raise newException(IOError, "cannot read from file: " & filename) raise newException(IOError, "cannot read from file: " & filename)