mirror of
https://github.com/status-im/NimYAML.git
synced 2025-01-12 20:44:46 +00:00
Properly handle newlines at end of file
This commit is contained in:
parent
2c9d065ecb
commit
d67c772cd8
@ -58,7 +58,33 @@ proc `==`*(left: YamlStreamEvent, right: YamlStreamEvent): bool =
|
|||||||
of yamlError, yamlWarning:
|
of yamlError, yamlWarning:
|
||||||
result = left.description == right.description and
|
result = left.description == right.description and
|
||||||
left.line == right.line and left.column == right.column
|
left.line == right.line and left.column == right.column
|
||||||
|
|
||||||
|
proc `$`*(event: YamlStreamEvent): string =
|
||||||
|
result = $event.kind & '('
|
||||||
|
case event.kind
|
||||||
|
of yamlEndMap, yamlEndSequence, yamlStartDocument, yamlEndDocument:
|
||||||
|
discard
|
||||||
|
of yamlStartMap:
|
||||||
|
result &= "tag=" & $event.mapTag
|
||||||
|
if event.mapAnchor != anchorNone:
|
||||||
|
result &= ", anchor=" & $event.mapAnchor
|
||||||
|
of yamlStartSequence:
|
||||||
|
result &= "tag=" & $event.seqTag
|
||||||
|
if event.seqAnchor != anchorNone:
|
||||||
|
result &= ", anchor=" & $event.seqAnchor
|
||||||
|
of yamlScalar:
|
||||||
|
result &= "tag=" & $event.scalarTag
|
||||||
|
if event.scalarAnchor != anchorNone:
|
||||||
|
result &= ", anchor=" & $event.scalarAnchor
|
||||||
|
result &= ", typeHint=" & $event.scalarType
|
||||||
|
result &= ", content=\"" & event.scalarContent & '\"'
|
||||||
|
of yamlAlias:
|
||||||
|
result &= "aliasTarget=" & $event.aliasTarget
|
||||||
|
of yamlWarning, yamlError:
|
||||||
|
result &= "line=" & $event.line & ", column=" & $event.column
|
||||||
|
result &= ", description=\"" & event.description & '\"'
|
||||||
|
result &= ")"
|
||||||
|
|
||||||
template yieldWarning(d: string) {.dirty.} =
|
template yieldWarning(d: string) {.dirty.} =
|
||||||
yield YamlStreamEvent(kind: yamlWarning, description: d,
|
yield YamlStreamEvent(kind: yamlWarning, description: d,
|
||||||
line: lex.line, column: lex.column)
|
line: lex.line, column: lex.column)
|
||||||
@ -502,13 +528,7 @@ proc parse*(parser: YamlSequentialParser, s: Stream): YamlStream =
|
|||||||
continue
|
continue
|
||||||
yieldUnexpectedToken()
|
yieldUnexpectedToken()
|
||||||
of tDocumentEnd, tStreamEnd:
|
of tDocumentEnd, tStreamEnd:
|
||||||
closeAllLevels()
|
state = ypBlockLineStart
|
||||||
scalarCache = nil
|
|
||||||
state = ypInitial
|
|
||||||
continue
|
|
||||||
of tDirectivesEnd:
|
|
||||||
closeAllLevels()
|
|
||||||
state = ypAfterDirectivesEnd
|
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
leaveMoreIndentedLevels()
|
leaveMoreIndentedLevels()
|
||||||
|
@ -95,6 +95,7 @@ const
|
|||||||
# interface
|
# interface
|
||||||
|
|
||||||
proc `==`*(left: YamlStreamEvent, right: YamlStreamEvent): bool
|
proc `==`*(left: YamlStreamEvent, right: YamlStreamEvent): bool
|
||||||
|
proc `$`*(event: YamlStreamEvent): string
|
||||||
|
|
||||||
proc `==`*(left, right: TagId): bool {.borrow.}
|
proc `==`*(left, right: TagId): bool {.borrow.}
|
||||||
proc `$`*(id: TagId): string {.borrow.}
|
proc `$`*(id: TagId): string {.borrow.}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user