mirror of https://github.com/status-im/NimYAML.git
Properly handle comments in flow mode
This commit is contained in:
parent
1c61486739
commit
d1c8c171a1
|
@ -376,18 +376,19 @@ template skipWhitespace(lexer: BaseLexer) =
|
||||||
debug("lex: skipWhitespace")
|
debug("lex: skipWhitespace")
|
||||||
while lexer.buf[lexer.bufpos] in space: lexer.bufpos.inc()
|
while lexer.buf[lexer.bufpos] in space: lexer.bufpos.inc()
|
||||||
|
|
||||||
template skipWhitespaceAndNewlines(lexer: BaseLexer) =
|
template skipWhitespaceCommentsAndNewlines(lexer: BaseLexer) =
|
||||||
debug("lex: skipWhitespaceAndNewLines")
|
debug("lex: skipWhitespaceCommentsAndNewlines")
|
||||||
while true:
|
if lexer.buf[lexer.bufpos] != '#':
|
||||||
case lexer.buf[lexer.bufpos]
|
while true:
|
||||||
of space:
|
case lexer.buf[lexer.bufpos]
|
||||||
lexer.bufpos.inc()
|
of space: lexer.bufpos.inc()
|
||||||
of '\l':
|
of '\l': lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
||||||
lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
of '\c': lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
||||||
of '\c':
|
of '#': # also skip comments
|
||||||
lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
lexer.bufpos.inc()
|
||||||
else:
|
while lexer.buf[lexer.bufpos] notin {'\l', '\c', EndOfFile}:
|
||||||
break
|
lexer.bufpos.inc()
|
||||||
|
else: break
|
||||||
|
|
||||||
template skipIndentation(lexer: BaseLexer) =
|
template skipIndentation(lexer: BaseLexer) =
|
||||||
debug("lex: skipIndentation")
|
debug("lex: skipIndentation")
|
||||||
|
@ -1439,7 +1440,7 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
|
||||||
parserError("Unexpected content (expected document end)")
|
parserError("Unexpected content (expected document end)")
|
||||||
of fpFlow:
|
of fpFlow:
|
||||||
debug("state: flow")
|
debug("state: flow")
|
||||||
p.lexer.skipWhitespaceAndNewlines()
|
p.lexer.skipWhitespaceCommentsAndNewlines()
|
||||||
case p.lexer.buf[p.lexer.bufpos]
|
case p.lexer.buf[p.lexer.bufpos]
|
||||||
of '{':
|
of '{':
|
||||||
handleObjectStart(yamlStartMap)
|
handleObjectStart(yamlStartMap)
|
||||||
|
@ -1570,7 +1571,7 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
|
||||||
handleFlowPlainScalar()
|
handleFlowPlainScalar()
|
||||||
of fpFlowAfterObject:
|
of fpFlowAfterObject:
|
||||||
debug("state: flowAfterObject")
|
debug("state: flowAfterObject")
|
||||||
p.lexer.skipWhitespaceAndNewlines()
|
p.lexer.skipWhitespaceCommentsAndNewlines()
|
||||||
case p.lexer.buf[p.lexer.bufpos]
|
case p.lexer.buf[p.lexer.bufpos]
|
||||||
of ']':
|
of ']':
|
||||||
case level.kind
|
case level.kind
|
||||||
|
|
Loading…
Reference in New Issue