mirror of https://github.com/status-im/NimYAML.git
Refactoring: added yieldEmptyScalar()
This commit is contained in:
parent
cb6f73eb01
commit
1399d3ba22
|
@ -74,6 +74,11 @@ template lexerError(lx: BaseLexer, message: string) {.dirty.} =
|
||||||
repeat(' ', lx.getColNumber(lx.bufpos)) & "^\n"
|
repeat(' ', lx.getColNumber(lx.bufpos)) & "^\n"
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
template yieldEmptyScalar() {.dirty.} =
|
||||||
|
yield scalarEvent("", tag, anchor)
|
||||||
|
tag = yTagQuestionMark
|
||||||
|
anchor = yAnchorNone
|
||||||
|
|
||||||
template yieldLevelEnd() {.dirty.} =
|
template yieldLevelEnd() {.dirty.} =
|
||||||
case level.kind
|
case level.kind
|
||||||
of fplSequence:
|
of fplSequence:
|
||||||
|
@ -81,18 +86,13 @@ template yieldLevelEnd() {.dirty.} =
|
||||||
of fplMapKey:
|
of fplMapKey:
|
||||||
yield endMapEvent()
|
yield endMapEvent()
|
||||||
of fplMapValue, fplSinglePairValue:
|
of fplMapValue, fplSinglePairValue:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
yield endMapEvent()
|
yield endMapEvent()
|
||||||
of fplScalar:
|
of fplScalar:
|
||||||
yield scalarEvent(content, tag, anchor)
|
yield scalarEvent(content, tag, anchor)
|
||||||
tag = yTagQuestionMark
|
tag = yTagQuestionMark
|
||||||
anchor = yAnchorNone
|
anchor = yAnchorNone
|
||||||
of fplUnknown:
|
of fplUnknown: yieldEmptyScalar()
|
||||||
yield scalarEvent("", tag, anchor)
|
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
of fplSinglePairKey: assert(false)
|
of fplSinglePairKey: assert(false)
|
||||||
|
|
||||||
template handleLineEnd(insideDocument: bool) {.dirty.} =
|
template handleLineEnd(insideDocument: bool) {.dirty.} =
|
||||||
|
@ -212,10 +212,7 @@ template handleMapValueIndicator() {.dirty.} =
|
||||||
if level.indentation == -1:
|
if level.indentation == -1:
|
||||||
handleObjectStart(yamlStartMap)
|
handleObjectStart(yamlStartMap)
|
||||||
yield scalarEvent("", yTagQuestionMark, yAnchorNone)
|
yield scalarEvent("", yTagQuestionMark, yAnchorNone)
|
||||||
else:
|
else: yieldEmptyScalar()
|
||||||
yield scalarEvent("", tag, anchor)
|
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
ancestry[ancestry.high].kind = fplMapValue
|
ancestry[ancestry.high].kind = fplMapValue
|
||||||
of fplMapKey:
|
of fplMapKey:
|
||||||
if level.indentation != indentation:
|
if level.indentation != indentation:
|
||||||
|
@ -353,9 +350,7 @@ template handleBlockItemStart() {.dirty.} =
|
||||||
ancestry.add(level)
|
ancestry.add(level)
|
||||||
level = FastParseLevel(kind: fplUnknown, indentation: indentation)
|
level = FastParseLevel(kind: fplUnknown, indentation: indentation)
|
||||||
of fplMapValue:
|
of fplMapValue:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
level.kind = fplMapKey
|
level.kind = fplMapKey
|
||||||
ancestry.add(level)
|
ancestry.add(level)
|
||||||
level = FastParseLevel(kind: fplUnknown, indentation: indentation)
|
level = FastParseLevel(kind: fplUnknown, indentation: indentation)
|
||||||
|
@ -1466,17 +1461,13 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
|
||||||
level = ancestry.pop()
|
level = ancestry.pop()
|
||||||
case level.kind
|
case level.kind
|
||||||
of fplMapValue:
|
of fplMapValue:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
level.kind = fplMapKey
|
level.kind = fplMapKey
|
||||||
of fplMapKey:
|
of fplMapKey:
|
||||||
if tag != yTagQuestionMark or anchor != yAnchorNone or
|
if tag != yTagQuestionMark or anchor != yAnchorNone or
|
||||||
explicitFlowKey:
|
explicitFlowKey:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
yield scalarEvent("", yTagQuestionMark, yAnchorNone)
|
||||||
anchor = yAnchorNone
|
|
||||||
yield scalarEvent("", tag, anchor)
|
|
||||||
of fplSequence:
|
of fplSequence:
|
||||||
startToken()
|
startToken()
|
||||||
parserError("Unexpected token (expected ']')")
|
parserError("Unexpected token (expected ']')")
|
||||||
|
@ -1492,13 +1483,9 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
|
||||||
case level.kind
|
case level.kind
|
||||||
of fplSequence:
|
of fplSequence:
|
||||||
if tag != yTagQuestionMark or anchor != yAnchorNone:
|
if tag != yTagQuestionMark or anchor != yAnchorNone:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
of fplSinglePairValue:
|
of fplSinglePairValue:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
level = ancestry.pop()
|
level = ancestry.pop()
|
||||||
yield endMapEvent()
|
yield endMapEvent()
|
||||||
assert(level.kind == fplSequence)
|
assert(level.kind == fplSequence)
|
||||||
|
@ -1512,26 +1499,17 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
|
||||||
assert(level.kind == fplUnknown)
|
assert(level.kind == fplUnknown)
|
||||||
level = ancestry.pop()
|
level = ancestry.pop()
|
||||||
case level.kind
|
case level.kind
|
||||||
of fplSequence:
|
of fplSequence: yieldEmptyScalar()
|
||||||
yield scalarEvent("", tag, anchor)
|
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
of fplMapValue:
|
of fplMapValue:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
level.kind = fplMapKey
|
level.kind = fplMapKey
|
||||||
explicitFlowKey = false
|
explicitFlowKey = false
|
||||||
of fplMapKey:
|
of fplMapKey:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar
|
||||||
tag = yTagQuestionMark
|
yield scalarEvent("", yTagQuestionMark, yAnchorNone)
|
||||||
anchor = yAnchorNone
|
|
||||||
yield scalarEvent("", tag, anchor)
|
|
||||||
explicitFlowKey = false
|
explicitFlowKey = false
|
||||||
of fplSinglePairValue:
|
of fplSinglePairValue:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
level = ancestry.pop()
|
level = ancestry.pop()
|
||||||
yield endMapEvent()
|
yield endMapEvent()
|
||||||
assert(level.kind == fplSequence)
|
assert(level.kind == fplSequence)
|
||||||
|
@ -1560,14 +1538,10 @@ proc parse*(p: YamlParser, s: Stream): YamlStream =
|
||||||
startToken()
|
startToken()
|
||||||
parserError("Unexpected token (expected ',')")
|
parserError("Unexpected token (expected ',')")
|
||||||
of fplMapKey:
|
of fplMapKey:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
level.kind = fplMapValue
|
level.kind = fplMapValue
|
||||||
of fplSinglePairKey:
|
of fplSinglePairKey:
|
||||||
yield scalarEvent("", tag, anchor)
|
yieldEmptyScalar()
|
||||||
tag = yTagQuestionMark
|
|
||||||
anchor = yAnchorNone
|
|
||||||
level.kind = fplSinglePairValue
|
level.kind = fplSinglePairValue
|
||||||
of fplUnknown, fplScalar:
|
of fplUnknown, fplScalar:
|
||||||
assert(false)
|
assert(false)
|
||||||
|
|
Loading…
Reference in New Issue