2016-01-24 10:44:10 +00:00
|
|
|
# NimYAML - YAML implementation in Nim
|
|
|
|
# (c) Copyright 2015 Felix Krause
|
|
|
|
#
|
|
|
|
# See the file "copying.txt", included in this
|
|
|
|
# distribution, for details about the copyright.
|
|
|
|
|
2016-01-20 20:15:33 +00:00
|
|
|
type
|
|
|
|
FastParseState = enum
|
2016-01-22 20:36:11 +00:00
|
|
|
fpInitial, fpBlockLineStart, fpBlockAfterObject, fpBlockAfterPlainScalar,
|
2016-01-20 22:38:39 +00:00
|
|
|
fpBlockObjectStart, fpBlockContinueScalar, fpExpectDocEnd, fpFlow,
|
|
|
|
fpFlowAfterObject
|
2016-01-20 20:15:33 +00:00
|
|
|
|
|
|
|
FastParseLevelKind = enum
|
2016-03-17 19:28:00 +00:00
|
|
|
fplUnknown, fplSequence, fplMapKey, fplMapValue, fplSinglePairKey,
|
|
|
|
fplSinglePairValue, fplScalar
|
2016-01-20 20:15:33 +00:00
|
|
|
|
|
|
|
FastParseLevel = object
|
|
|
|
kind: FastParseLevelKind
|
|
|
|
indentation: int
|
|
|
|
|
|
|
|
LexedDirective = enum
|
|
|
|
ldYaml, ldTag, ldUnknown
|
|
|
|
|
|
|
|
LexedPossibleDirectivesEnd = enum
|
|
|
|
lpdeDirectivesEnd, lpdeSequenceItem, lpdeScalarContent
|
|
|
|
|
|
|
|
YamlContext = enum
|
2016-02-19 17:25:01 +00:00
|
|
|
cBlock, cFlow
|
2016-01-20 20:15:33 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
space = [' ', '\t']
|
2016-02-26 18:28:28 +00:00
|
|
|
lineEnd = ['\l', '\c', EndOfFile]
|
|
|
|
spaceOrLineEnd = [' ', '\t', '\l', '\c', EndOfFile]
|
2016-01-20 20:15:33 +00:00
|
|
|
digits = '0'..'9'
|
|
|
|
flowIndicators = ['[', ']', '{', '}', ',']
|
2016-01-24 10:44:10 +00:00
|
|
|
|
|
|
|
UTF8NextLine = toUTF8(0x85.Rune)
|
|
|
|
UTF8NonBreakingSpace = toUTF8(0xA0.Rune)
|
|
|
|
UTF8LineSeparator = toUTF8(0x2028.Rune)
|
|
|
|
UTF8ParagraphSeparator = toUTF8(0x2029.Rune)
|
|
|
|
|
|
|
|
proc newYamlParser*(tagLib: TagLibrary = initExtendedTagLibrary(),
|
|
|
|
callback: WarningCallback = nil): YamlParser =
|
|
|
|
new(result)
|
|
|
|
result.tagLib = tagLib
|
|
|
|
result.callback = callback
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 17:24:09 +00:00
|
|
|
proc getLineNumber*(p: YamlParser): int = p.lexer.lineNumber
|
|
|
|
|
|
|
|
proc getColNumber*(p: YamlParser): int = p.tokenstart + 1 # column is 1-based
|
|
|
|
|
|
|
|
proc getLineContent*(p: YamlParser, marker: bool = true): string =
|
|
|
|
result = p.lexer.getCurrentLine(false)
|
|
|
|
if marker:
|
|
|
|
result.add(repeat(' ', p.tokenstart) & "^\n")
|
|
|
|
|
2016-01-20 20:15:33 +00:00
|
|
|
template debug(message: string) {.dirty.} =
|
|
|
|
when defined(yamlDebug):
|
|
|
|
try: styledWriteLine(stdout, fgBlue, message)
|
|
|
|
except IOError: discard
|
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template parserError(message: string) {.dirty.} =
|
2016-01-20 20:15:33 +00:00
|
|
|
var e = newException(YamlParserError, message)
|
2016-01-24 10:44:10 +00:00
|
|
|
e.line = p.lexer.lineNumber
|
2016-01-24 17:24:09 +00:00
|
|
|
e.column = p.tokenstart + 1
|
|
|
|
e.lineContent = p.getLineContent(true)
|
2016-01-20 20:15:33 +00:00
|
|
|
raise e
|
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template lexerError(lx: BaseLexer, message: string) {.dirty.} =
|
2016-01-20 20:15:33 +00:00
|
|
|
var e = newException(YamlParserError, message)
|
2016-01-24 10:44:10 +00:00
|
|
|
e.line = lx.lineNumber
|
2016-01-24 17:24:09 +00:00
|
|
|
e.column = lx.bufpos + 1
|
2016-01-24 10:44:10 +00:00
|
|
|
e.lineContent = lx.getCurrentLine(false) &
|
|
|
|
repeat(' ', lx.getColNumber(lx.bufpos)) & "^\n"
|
2016-01-20 20:15:33 +00:00
|
|
|
raise e
|
|
|
|
|
2016-01-22 20:36:11 +00:00
|
|
|
template yieldLevelEnd() {.dirty.} =
|
2016-01-20 20:15:33 +00:00
|
|
|
case level.kind
|
|
|
|
of fplSequence:
|
|
|
|
yield endSeqEvent()
|
|
|
|
of fplMapKey:
|
|
|
|
yield endMapEvent()
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplMapValue, fplSinglePairValue:
|
2016-01-20 20:15:33 +00:00
|
|
|
yield scalarEvent("", tag, anchor)
|
|
|
|
tag = yTagQuestionMark
|
|
|
|
anchor = yAnchorNone
|
|
|
|
yield endMapEvent()
|
|
|
|
of fplScalar:
|
2016-01-22 20:36:11 +00:00
|
|
|
yield scalarEvent(content, tag, anchor)
|
2016-01-23 16:44:50 +00:00
|
|
|
tag = yTagQuestionMark
|
|
|
|
anchor = yAnchorNone
|
2016-01-20 20:15:33 +00:00
|
|
|
of fplUnknown:
|
2016-01-23 16:44:50 +00:00
|
|
|
yield scalarEvent("", tag, anchor)
|
|
|
|
tag = yTagQuestionMark
|
|
|
|
anchor = yAnchorNone
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairKey: assert(false)
|
2016-01-20 20:15:33 +00:00
|
|
|
|
|
|
|
template handleLineEnd(insideDocument: bool) {.dirty.} =
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
of '\c':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
of EndOfFile:
|
|
|
|
when insideDocument:
|
|
|
|
closeEverything()
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
discard
|
2016-03-04 20:51:37 +00:00
|
|
|
newlines.inc()
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-22 20:36:11 +00:00
|
|
|
template handleObjectEnd(nextState: FastParseState) {.dirty.} =
|
2016-03-17 19:28:00 +00:00
|
|
|
if ancestry.len == 0: state = fpExpectDocEnd
|
2016-01-22 20:36:11 +00:00
|
|
|
else:
|
|
|
|
level = ancestry.pop()
|
2016-03-17 19:28:00 +00:00
|
|
|
if level.kind == fplSinglePairValue:
|
|
|
|
yield endMapEvent()
|
|
|
|
level = ancestry.pop()
|
2016-01-22 20:36:11 +00:00
|
|
|
state = nextState
|
|
|
|
tag = yTagQuestionMark
|
|
|
|
anchor = yAnchorNone
|
|
|
|
case level.kind
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplMapKey: level.kind = fplMapValue
|
|
|
|
of fplSinglePairKey: level.kind = fplSinglePairValue
|
|
|
|
of fplMapValue: level.kind = fplMapKey
|
|
|
|
of fplSequence: discard
|
|
|
|
of fplUnknown, fplScalar, fplSinglePairValue: assert(false)
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-03-17 19:28:00 +00:00
|
|
|
template handleObjectStart(k: YamlStreamEventKind, single: bool = false)
|
|
|
|
{.dirty.} =
|
2016-01-22 20:36:11 +00:00
|
|
|
assert(level.kind == fplUnknown)
|
2016-01-20 20:15:33 +00:00
|
|
|
when k == yamlStartMap:
|
2016-01-23 16:44:50 +00:00
|
|
|
yield startMapEvent(tag, anchor)
|
2016-03-17 19:28:00 +00:00
|
|
|
if single:
|
|
|
|
debug("started single-pair map at " &
|
|
|
|
(if level.indentation == -1: $indentation else: $level.indentation))
|
|
|
|
level.kind = fplSinglePairKey
|
|
|
|
else:
|
|
|
|
debug("started map at " &
|
|
|
|
(if level.indentation == -1: $indentation else: $level.indentation))
|
|
|
|
level.kind = fplMapKey
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
2016-01-23 16:44:50 +00:00
|
|
|
yield startSeqEvent(tag, anchor)
|
|
|
|
debug("started sequence at " & (if level.indentation == -1: $indentation else:
|
|
|
|
$level.indentation))
|
2016-01-22 20:36:11 +00:00
|
|
|
level.kind = fplSequence
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-23 16:44:50 +00:00
|
|
|
anchor = yAnchorNone
|
|
|
|
if level.indentation == -1:
|
|
|
|
level.indentation = indentation
|
2016-01-22 20:36:11 +00:00
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-02-19 16:31:57 +00:00
|
|
|
template closeMoreIndentedLevels(atSequenceItem: bool = false) {.dirty.} =
|
2016-01-20 20:15:33 +00:00
|
|
|
while ancestry.len > 0:
|
|
|
|
let parent = ancestry[ancestry.high]
|
|
|
|
if parent.indentation >= indentation:
|
2016-02-19 16:31:57 +00:00
|
|
|
when atSequenceItem:
|
|
|
|
if (indentation == level.indentation and level.kind == fplSequence) or
|
2016-03-09 19:26:16 +00:00
|
|
|
(indentation == parent.indentation and level.kind == fplUnknown and
|
|
|
|
parent.kind != fplSequence):
|
2016-02-19 16:31:57 +00:00
|
|
|
break
|
2016-01-22 20:36:11 +00:00
|
|
|
debug("Closing because parent.indentation (" & $parent.indentation &
|
|
|
|
") >= indentation(" & $indentation & ")")
|
|
|
|
yieldLevelEnd()
|
2016-03-11 17:09:34 +00:00
|
|
|
handleObjectEnd(state)
|
|
|
|
else: break
|
2016-01-20 20:15:33 +00:00
|
|
|
|
|
|
|
template closeEverything() {.dirty.} =
|
|
|
|
indentation = 0
|
|
|
|
closeMoreIndentedLevels()
|
2016-01-22 20:36:11 +00:00
|
|
|
yieldLevelEnd()
|
2016-01-20 20:15:33 +00:00
|
|
|
yield endDocEvent()
|
|
|
|
|
2016-01-22 20:36:11 +00:00
|
|
|
template handleBlockSequenceIndicator() {.dirty.} =
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-01-20 20:15:33 +00:00
|
|
|
case level.kind
|
|
|
|
of fplUnknown:
|
2016-03-14 17:10:34 +00:00
|
|
|
handleObjectStart(yamlStartSeq)
|
2016-01-20 20:15:33 +00:00
|
|
|
of fplSequence:
|
|
|
|
if level.indentation != indentation:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Invalid indentation of block sequence indicator")
|
2016-01-22 20:36:11 +00:00
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Illegal sequence item in map")
|
|
|
|
p.lexer.skipWhitespace()
|
|
|
|
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
2016-01-22 22:44:26 +00:00
|
|
|
|
|
|
|
template handleMapKeyIndicator() {.dirty.} =
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-01-22 22:44:26 +00:00
|
|
|
case level.kind
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplUnknown: handleObjectStart(yamlStartMap)
|
2016-01-22 22:44:26 +00:00
|
|
|
of fplMapValue:
|
|
|
|
if level.indentation != indentation:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Invalid indentation of map key indicator")
|
2016-01-24 18:15:50 +00:00
|
|
|
yield scalarEvent("", yTagQuestionMark, yAnchorNone)
|
2016-01-22 22:44:26 +00:00
|
|
|
level.kind = fplMapKey
|
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-22 22:44:26 +00:00
|
|
|
of fplMapKey:
|
|
|
|
if level.indentation != indentation:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Invalid indentation of map key indicator")
|
2016-01-22 22:44:26 +00:00
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-22 22:44:26 +00:00
|
|
|
of fplSequence:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Unexpected map key indicator (expected '- ')")
|
2016-01-22 22:44:26 +00:00
|
|
|
of fplScalar:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Unexpected map key indicator (expected multiline scalar end)")
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairKey, fplSinglePairValue: assert(false)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.skipWhitespace()
|
|
|
|
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
2016-01-22 22:44:26 +00:00
|
|
|
|
|
|
|
template handleMapValueIndicator() {.dirty.} =
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-01-22 22:44:26 +00:00
|
|
|
case level.kind
|
|
|
|
of fplUnknown:
|
2016-01-23 16:44:50 +00:00
|
|
|
if level.indentation == -1:
|
|
|
|
handleObjectStart(yamlStartMap)
|
2016-01-24 18:15:50 +00:00
|
|
|
yield scalarEvent("", yTagQuestionMark, yAnchorNone)
|
2016-01-23 16:44:50 +00:00
|
|
|
else:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-23 16:44:50 +00:00
|
|
|
anchor = yAnchorNone
|
|
|
|
ancestry[ancestry.high].kind = fplMapValue
|
2016-01-22 22:44:26 +00:00
|
|
|
of fplMapKey:
|
|
|
|
if level.indentation != indentation:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Invalid indentation of map key indicator")
|
2016-01-24 18:15:50 +00:00
|
|
|
yield scalarEvent("", yTagQuestionMark, yAnchorNone)
|
2016-01-22 22:44:26 +00:00
|
|
|
level.kind = fplMapValue
|
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-22 22:44:26 +00:00
|
|
|
of fplMapValue:
|
|
|
|
if level.indentation != indentation:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Invalid indentation of map key indicator")
|
2016-01-22 22:44:26 +00:00
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-22 22:44:26 +00:00
|
|
|
of fplSequence:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Unexpected map value indicator (expected '- ')")
|
2016-01-22 22:44:26 +00:00
|
|
|
of fplScalar:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError(
|
|
|
|
"Unexpected map value indicator (expected multiline scalar end)")
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairKey, fplSinglePairValue: assert(false)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.skipWhitespace()
|
|
|
|
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
|
|
|
|
template initDocValues() {.dirty.} =
|
|
|
|
shorthands = initTable[string, string]()
|
|
|
|
anchors = initTable[string, AnchorId]()
|
|
|
|
shorthands["!"] = "!"
|
|
|
|
shorthands["!!"] = "tag:yaml.org,2002:"
|
|
|
|
nextAnchorId = 0.AnchorId
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-20 22:38:39 +00:00
|
|
|
anchor = yAnchorNone
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-20 22:38:39 +00:00
|
|
|
template handleTagHandle() {.dirty.} =
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-03-17 18:30:40 +00:00
|
|
|
if level.kind != fplUnknown: parserError("Unexpected tag handle")
|
2016-01-24 18:15:50 +00:00
|
|
|
if tag != yTagQuestionMark:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Only one tag handle is allowed per node")
|
2016-01-20 22:38:39 +00:00
|
|
|
content = ""
|
|
|
|
var
|
|
|
|
shorthandEnd: int
|
|
|
|
tagUri: string
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.tagHandle(content, shorthandEnd)
|
2016-01-20 22:38:39 +00:00
|
|
|
if shorthandEnd != -1:
|
|
|
|
try:
|
|
|
|
let prefix = shorthands[content[0..shorthandEnd]]
|
|
|
|
tagUri = prefix & content[shorthandEnd + 1 .. ^1]
|
|
|
|
except KeyError:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Undefined tag shorthand: " & content[0..shorthandEnd])
|
2016-03-17 18:30:40 +00:00
|
|
|
else: shallowCopy(tagUri, content)
|
|
|
|
try: tag = p.tagLib.tags[tagUri]
|
|
|
|
except KeyError: tag = p.tagLib.registerUri(tagUri)
|
2016-01-20 22:38:39 +00:00
|
|
|
|
|
|
|
template handleAnchor() {.dirty.} =
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-03-17 18:30:40 +00:00
|
|
|
if level.kind != fplUnknown: parserError("Unexpected token")
|
2016-01-20 22:38:39 +00:00
|
|
|
if anchor != yAnchorNone:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Only one anchor is allowed per node")
|
2016-01-20 22:38:39 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.anchorName(content)
|
2016-01-20 22:38:39 +00:00
|
|
|
anchor = nextAnchorId
|
|
|
|
anchors[content] = anchor
|
|
|
|
nextAnchorId = cast[AnchorId](cast[int](nextAnchorId) + 1)
|
|
|
|
|
|
|
|
template handleAlias() {.dirty.} =
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-03-17 18:30:40 +00:00
|
|
|
if level.kind != fplUnknown: parserError("Unexpected token")
|
2016-01-24 18:15:50 +00:00
|
|
|
if anchor != yAnchorNone or tag != yTagQuestionMark:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Alias may not have anchor or tag")
|
2016-01-20 22:38:39 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.anchorName(content)
|
2016-01-22 20:36:11 +00:00
|
|
|
var id: AnchorId
|
2016-03-17 18:30:40 +00:00
|
|
|
try: id = anchors[content]
|
|
|
|
except KeyError: parserError("Unknown anchor")
|
2016-01-22 20:36:11 +00:00
|
|
|
yield aliasEvent(id)
|
|
|
|
handleObjectEnd(fpBlockAfterObject)
|
2016-01-20 22:38:39 +00:00
|
|
|
|
|
|
|
template leaveFlowLevel() {.dirty.} =
|
|
|
|
flowdepth.inc(-1)
|
2016-01-22 20:36:11 +00:00
|
|
|
if flowdepth == 0:
|
|
|
|
yieldLevelEnd()
|
|
|
|
handleObjectEnd(fpBlockAfterObject)
|
2016-01-20 22:38:39 +00:00
|
|
|
else:
|
2016-01-22 20:36:11 +00:00
|
|
|
yieldLevelEnd()
|
|
|
|
handleObjectEnd(fpFlowAfterObject)
|
|
|
|
|
2016-03-17 19:28:00 +00:00
|
|
|
template handlePossibleMapStart(single: bool = false) {.dirty.} =
|
2016-01-23 16:44:50 +00:00
|
|
|
if level.indentation == -1:
|
|
|
|
var flowDepth = 0
|
2016-02-25 20:16:03 +00:00
|
|
|
var pos = p.lexer.bufpos
|
|
|
|
while pos < p.lexer.bufpos + 1024:
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[pos]
|
2016-01-23 16:44:50 +00:00
|
|
|
of ':':
|
2016-01-24 10:44:10 +00:00
|
|
|
if flowDepth == 0 and p.lexer.buf[pos + 1] in spaceOrLineEnd:
|
2016-03-17 19:28:00 +00:00
|
|
|
handleObjectStart(yamlStartMap, single)
|
2016-01-23 16:44:50 +00:00
|
|
|
break
|
2016-03-17 18:30:40 +00:00
|
|
|
of lineEnd: break
|
2016-02-25 20:16:03 +00:00
|
|
|
of '[', '{': flowDepth.inc()
|
2016-03-17 19:28:00 +00:00
|
|
|
of '}', ']':
|
|
|
|
flowDepth.inc(-1)
|
|
|
|
if flowDepth < 0: break
|
|
|
|
of '?', ',':
|
2016-01-23 16:44:50 +00:00
|
|
|
if flowDepth == 0: break
|
|
|
|
of '#':
|
2016-02-25 20:16:03 +00:00
|
|
|
if p.lexer.buf[pos - 1] in space: break
|
|
|
|
of '"':
|
|
|
|
pos.inc()
|
2016-02-26 18:28:28 +00:00
|
|
|
while p.lexer.buf[pos] notin {'"', EndOfFile, '\l', '\c'}:
|
2016-02-25 20:16:03 +00:00
|
|
|
if p.lexer.buf[pos] == '\\': pos.inc()
|
|
|
|
pos.inc()
|
|
|
|
if p.lexer.buf[pos] != '"': break
|
2016-03-10 18:59:56 +00:00
|
|
|
of '\'':
|
|
|
|
pos.inc()
|
|
|
|
while p.lexer.buf[pos] notin {'\'', '\l', '\c', EndOfFile}:
|
|
|
|
pos.inc()
|
|
|
|
of '&', '*', '!':
|
|
|
|
pos.inc()
|
|
|
|
while p.lexer.buf[pos] notin {' ', '\t', '\l', '\c', EndOfFile}:
|
|
|
|
pos.inc()
|
|
|
|
continue
|
2016-02-25 20:16:03 +00:00
|
|
|
else: discard
|
|
|
|
pos.inc()
|
2016-03-17 18:30:40 +00:00
|
|
|
if level.indentation == -1: level.indentation = indentation
|
2016-01-22 20:36:11 +00:00
|
|
|
|
|
|
|
template handleBlockItemStart() {.dirty.} =
|
|
|
|
case level.kind
|
2016-03-17 18:30:40 +00:00
|
|
|
of fplUnknown: handlePossibleMapStart()
|
2016-01-22 20:36:11 +00:00
|
|
|
of fplSequence:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Unexpected token (expected block sequence indicator)")
|
2016-01-22 20:36:11 +00:00
|
|
|
of fplMapKey:
|
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: indentation)
|
2016-01-22 20:36:11 +00:00
|
|
|
of fplMapValue:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-22 20:36:11 +00:00
|
|
|
anchor = yAnchorNone
|
|
|
|
level.kind = fplMapKey
|
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: indentation)
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplScalar, fplSinglePairKey, fplSinglePairValue: assert(false)
|
|
|
|
|
|
|
|
template handleFlowItemStart() {.dirty.} =
|
|
|
|
if level.kind == fplUnknown and ancestry.len > 0 and
|
|
|
|
ancestry[ancestry.high].kind == fplSequence:
|
|
|
|
handlePossibleMapStart(true)
|
2016-01-20 22:38:39 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template startToken() {.dirty.} =
|
|
|
|
p.tokenstart = p.lexer.getColNumber(p.lexer.bufpos)
|
|
|
|
|
|
|
|
template finishLine(lexer: BaseLexer) =
|
2016-01-20 20:15:33 +00:00
|
|
|
debug("lex: finishLine")
|
|
|
|
while lexer.buf[lexer.bufpos] notin lineEnd:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template skipWhitespace(lexer: BaseLexer) =
|
2016-01-20 20:15:33 +00:00
|
|
|
debug("lex: skipWhitespace")
|
|
|
|
while lexer.buf[lexer.bufpos] in space: lexer.bufpos.inc()
|
|
|
|
|
2016-03-16 18:30:51 +00:00
|
|
|
template skipWhitespaceCommentsAndNewlines(lexer: BaseLexer) =
|
|
|
|
debug("lex: skipWhitespaceCommentsAndNewlines")
|
|
|
|
if lexer.buf[lexer.bufpos] != '#':
|
|
|
|
while true:
|
|
|
|
case lexer.buf[lexer.bufpos]
|
|
|
|
of space: lexer.bufpos.inc()
|
|
|
|
of '\l': lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
|
|
|
of '\c': lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
|
|
|
of '#': # also skip comments
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
while lexer.buf[lexer.bufpos] notin {'\l', '\c', EndOfFile}:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
else: break
|
2016-01-20 22:38:39 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template skipIndentation(lexer: BaseLexer) =
|
2016-01-20 20:15:33 +00:00
|
|
|
debug("lex: skipIndentation")
|
|
|
|
while lexer.buf[lexer.bufpos] == ' ': lexer.bufpos.inc()
|
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template directiveName(lexer: BaseLexer, directive: var LexedDirective) =
|
2016-01-20 20:15:33 +00:00
|
|
|
debug("lex: directiveName")
|
|
|
|
directive = ldUnknown
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] == 'Y':
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] == 'A':
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] == 'M':
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] == 'L':
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] in spaceOrLineEnd:
|
|
|
|
directive = ldYaml
|
|
|
|
elif lexer.buf[lexer.bufpos] == 'T':
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] == 'A':
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] == 'G':
|
|
|
|
lexer.bufpos.inc()
|
2016-03-09 19:29:18 +00:00
|
|
|
if lexer.buf[lexer.bufpos] in {' ', '\t', '\l', '\c', EndOfFile}:
|
2016-01-20 20:15:33 +00:00
|
|
|
directive = ldTag
|
|
|
|
while lexer.buf[lexer.bufpos] notin spaceOrLineEnd:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template yamlVersion(lexer: BaseLexer, o: var string) =
|
2016-01-20 20:15:33 +00:00
|
|
|
debug("lex: yamlVersion")
|
2016-03-17 18:30:40 +00:00
|
|
|
while lexer.buf[lexer.bufpos] in space: lexer.bufpos.inc()
|
2016-01-20 20:15:33 +00:00
|
|
|
var c = lexer.buf[lexer.bufpos]
|
2016-03-17 18:30:40 +00:00
|
|
|
if c notin digits: lexerError(lexer, "Invalid YAML version number")
|
2016-01-20 20:15:33 +00:00
|
|
|
o.add(c)
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
c = lexer.buf[lexer.bufpos]
|
|
|
|
while c in digits:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
o.add(c)
|
|
|
|
c = lexer.buf[lexer.bufpos]
|
|
|
|
if lexer.buf[lexer.bufpos] != '.':
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Invalid YAML version number")
|
2016-01-24 17:24:09 +00:00
|
|
|
o.add('.')
|
2016-01-20 20:15:33 +00:00
|
|
|
lexer.bufpos.inc()
|
2016-01-24 17:24:09 +00:00
|
|
|
c = lexer.buf[lexer.bufpos]
|
2016-03-17 18:30:40 +00:00
|
|
|
if c notin digits: lexerError(lexer, "Invalid YAML version number")
|
2016-01-24 17:24:09 +00:00
|
|
|
o.add(c)
|
2016-01-20 20:15:33 +00:00
|
|
|
lexer.bufpos.inc()
|
2016-01-24 17:24:09 +00:00
|
|
|
c = lexer.buf[lexer.bufpos]
|
|
|
|
while c in digits:
|
|
|
|
o.add(c)
|
2016-01-20 20:15:33 +00:00
|
|
|
lexer.bufpos.inc()
|
2016-01-24 17:24:09 +00:00
|
|
|
c = lexer.buf[lexer.bufpos]
|
2016-01-20 20:15:33 +00:00
|
|
|
if lexer.buf[lexer.bufpos] notin spaceOrLineEnd:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Invalid YAML version number")
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template lineEnding(lexer: BaseLexer) =
|
2016-01-20 20:15:33 +00:00
|
|
|
debug("lex: lineEnding")
|
|
|
|
if lexer.buf[lexer.bufpos] notin lineEnd:
|
2016-03-17 18:30:40 +00:00
|
|
|
while lexer.buf[lexer.bufpos] in space: lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] in lineEnd: discard
|
2016-01-20 20:15:33 +00:00
|
|
|
elif lexer.buf[lexer.bufpos] == '#':
|
2016-03-17 18:30:40 +00:00
|
|
|
while lexer.buf[lexer.bufpos] notin lineEnd: lexer.bufpos.inc()
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected token (expected comment or line end)")
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template tagShorthand(lexer: BaseLexer, shorthand: var string) =
|
2016-01-20 20:15:33 +00:00
|
|
|
debug("lex: tagShorthand")
|
2016-03-17 18:30:40 +00:00
|
|
|
while lexer.buf[lexer.bufpos] in space: lexer.bufpos.inc()
|
2016-01-24 10:44:10 +00:00
|
|
|
assert lexer.buf[lexer.bufpos] == '!'
|
2016-01-20 20:15:33 +00:00
|
|
|
shorthand.add('!')
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
var c = lexer.buf[lexer.bufpos]
|
2016-03-17 18:30:40 +00:00
|
|
|
if c in spaceOrLineEnd: discard
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
|
|
|
while c != '!':
|
|
|
|
case c
|
|
|
|
of 'a' .. 'z', 'A' .. 'Z', '0' .. '9', '-':
|
|
|
|
shorthand.add(c)
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
c = lexer.buf[lexer.bufpos]
|
2016-03-17 18:30:40 +00:00
|
|
|
else: lexerError(lexer, "Illegal character in tag shorthand")
|
2016-01-20 20:15:33 +00:00
|
|
|
shorthand.add(c)
|
2016-03-11 17:32:17 +00:00
|
|
|
lexer.bufpos.inc()
|
2016-01-20 20:15:33 +00:00
|
|
|
if lexer.buf[lexer.bufpos] notin spaceOrLineEnd:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Missing space after tag shorthand")
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template tagUri(lexer: BaseLexer, uri: var string) =
|
2016-01-20 20:15:33 +00:00
|
|
|
debug("lex: tagUri")
|
|
|
|
while lexer.buf[lexer.bufpos] in space:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
var c = lexer.buf[lexer.bufpos]
|
2016-03-16 18:20:18 +00:00
|
|
|
if c == '!':
|
|
|
|
uri.add(c)
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
c = lexer.buf[lexer.bufpos]
|
2016-01-20 20:15:33 +00:00
|
|
|
while c notin spaceOrLineEnd:
|
|
|
|
case c
|
|
|
|
of 'a' .. 'z', 'A' .. 'Z', '0' .. '9', '#', ';', '/', '?', ':', '@', '&',
|
|
|
|
'-', '=', '+', '$', ',', '_', '.', '~', '*', '\'', '(', ')':
|
|
|
|
uri.add(c)
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
c = lexer.buf[lexer.bufpos]
|
2016-03-17 18:30:40 +00:00
|
|
|
else: lexerError(lexer, "Invalid tag uri")
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template directivesEnd(lexer: BaseLexer,
|
2016-01-20 20:15:33 +00:00
|
|
|
token: var LexedPossibleDirectivesEnd) =
|
|
|
|
debug("lex: directivesEnd")
|
2016-01-22 20:36:11 +00:00
|
|
|
var p = lexer.bufpos + 1
|
|
|
|
case lexer.buf[p]
|
2016-01-20 20:15:33 +00:00
|
|
|
of '-':
|
2016-01-22 20:36:11 +00:00
|
|
|
p.inc()
|
|
|
|
if lexer.buf[p] == '-':
|
|
|
|
p.inc()
|
2016-03-17 18:30:40 +00:00
|
|
|
if lexer.buf[p] in spaceOrLineEnd: token = lpdeDirectivesEnd
|
|
|
|
else: token = lpdeScalarContent
|
|
|
|
else: token = lpdeScalarContent
|
|
|
|
of spaceOrLineEnd: token = lpdeSequenceItem
|
|
|
|
else: token = lpdeScalarContent
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template documentEnd(lexer: var BaseLexer, isDocumentEnd: var bool) =
|
2016-01-22 20:36:11 +00:00
|
|
|
var p = lexer.bufpos + 1
|
|
|
|
if lexer.buf[p] == '.':
|
|
|
|
p.inc()
|
|
|
|
if lexer.buf[p] == '.':
|
|
|
|
p.inc()
|
2016-03-17 18:30:40 +00:00
|
|
|
if lexer.buf[p] in spaceOrLineEnd: isDocumentEnd = true
|
|
|
|
else: isDocumentEnd = false
|
|
|
|
else: isDocumentEnd = false
|
|
|
|
else: isDocumentEnd = false
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
proc unicodeSequence(lexer: var BaseLexer, length: int):
|
2016-01-20 20:15:33 +00:00
|
|
|
string {.raises: [YamlParserError].} =
|
|
|
|
debug("lex: unicodeSequence")
|
2016-01-24 10:44:10 +00:00
|
|
|
var unicodeChar = 0.int
|
2016-01-20 20:15:33 +00:00
|
|
|
for i in countup(0, length - 1):
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
let
|
|
|
|
digitPosition = length - i - 1
|
|
|
|
c = lexer.buf[lexer.bufpos]
|
|
|
|
case c
|
2016-03-17 20:25:30 +00:00
|
|
|
of EndOFFile, '\l', '\c':
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Unfinished unicode escape sequence")
|
2016-01-20 20:15:33 +00:00
|
|
|
of '0' .. '9':
|
|
|
|
unicodeChar = unicodechar or
|
|
|
|
(cast[int](c) - 0x30) shl (digitPosition * 4)
|
|
|
|
of 'A' .. 'F':
|
|
|
|
unicodeChar = unicodechar or
|
|
|
|
(cast[int](c) - 0x37) shl (digitPosition * 4)
|
|
|
|
of 'a' .. 'f':
|
|
|
|
unicodeChar = unicodechar or
|
|
|
|
(cast[int](c) - 0x57) shl (digitPosition * 4)
|
2016-03-17 17:44:35 +00:00
|
|
|
else: lexerError(lexer, "Invalid character in unicode escape sequence")
|
2016-01-24 10:44:10 +00:00
|
|
|
return toUTF8(cast[Rune](unicodeChar))
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-03-17 17:44:35 +00:00
|
|
|
proc byteSequence(lexer: var BaseLexer): char {.raises: [YamlParserError].} =
|
|
|
|
debug("lex: byteSequence")
|
|
|
|
var charCode = 0.int8
|
|
|
|
for i in 0 .. 1:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
let
|
|
|
|
digitPosition = int8(1 - i)
|
|
|
|
c = lexer.buf[lexer.bufpos]
|
|
|
|
case c
|
|
|
|
of EndOfFile, '\l', 'r':
|
|
|
|
lexerError(lexer, "Unfinished octet escape sequence")
|
|
|
|
of '0' .. '9':
|
|
|
|
charCode = charCode or (int8(c) - 0x30.int8) shl (digitPosition * 4)
|
|
|
|
of 'A' .. 'F':
|
|
|
|
charCode = charCode or (int8(c) - 0x37.int8) shl (digitPosition * 4)
|
|
|
|
of 'a' .. 'f':
|
|
|
|
charCode = charCode or (int8(c) - 0x57.int8) shl (digitPosition * 4)
|
|
|
|
else: lexerError(lexer, "Invalid character in octet escape sequence")
|
|
|
|
return char(charCode)
|
|
|
|
|
2016-03-17 20:25:30 +00:00
|
|
|
template processQuotedWhitespace(newlines: var int) {.dirty.} =
|
2016-03-17 18:30:40 +00:00
|
|
|
var after = ""
|
2016-01-23 14:29:45 +00:00
|
|
|
block outer:
|
|
|
|
while true:
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-03-17 18:30:40 +00:00
|
|
|
of ' ', '\t': after.add(p.lexer.buf[p.lexer.bufpos])
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-23 14:29:45 +00:00
|
|
|
break
|
|
|
|
of '\c':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-23 14:29:45 +00:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
content.add(after)
|
|
|
|
break outer
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-23 14:29:45 +00:00
|
|
|
while true:
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-03-17 18:30:40 +00:00
|
|
|
of ' ', '\t': discard
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-23 14:29:45 +00:00
|
|
|
newlines.inc()
|
2016-03-17 18:30:40 +00:00
|
|
|
continue
|
2016-01-23 14:29:45 +00:00
|
|
|
of '\c':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
2016-01-23 14:29:45 +00:00
|
|
|
newlines.inc()
|
2016-03-17 18:30:40 +00:00
|
|
|
continue
|
2016-01-23 14:29:45 +00:00
|
|
|
else:
|
2016-03-17 18:30:40 +00:00
|
|
|
if newlines == 0: discard
|
|
|
|
elif newlines == 1: content.add(' ')
|
|
|
|
else: content.add(repeat('\l', newlines - 1))
|
2016-01-23 14:29:45 +00:00
|
|
|
break
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-23 14:29:45 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template doubleQuotedScalar(lexer: BaseLexer, content: var string) =
|
2016-01-23 14:29:45 +00:00
|
|
|
debug("lex: doubleQuotedScalar")
|
|
|
|
lexer.bufpos.inc()
|
2016-01-20 20:15:33 +00:00
|
|
|
while true:
|
2016-01-23 14:29:45 +00:00
|
|
|
var c = lexer.buf[lexer.bufpos]
|
2016-01-20 20:15:33 +00:00
|
|
|
case c
|
|
|
|
of EndOfFile:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Unfinished double quoted string")
|
2016-01-20 20:15:33 +00:00
|
|
|
of '\\':
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
case lexer.buf[lexer.bufpos]
|
|
|
|
of EndOfFile:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Unfinished escape sequence")
|
2016-01-20 20:15:33 +00:00
|
|
|
of '0': content.add('\0')
|
|
|
|
of 'a': content.add('\x07')
|
|
|
|
of 'b': content.add('\x08')
|
|
|
|
of '\t', 't': content.add('\t')
|
2016-02-26 18:28:28 +00:00
|
|
|
of 'n': content.add('\l')
|
2016-01-20 20:15:33 +00:00
|
|
|
of 'v': content.add('\v')
|
|
|
|
of 'f': content.add('\f')
|
2016-03-17 20:25:30 +00:00
|
|
|
of 'r': content.add('\c')
|
2016-01-20 20:15:33 +00:00
|
|
|
of 'e': content.add('\e')
|
|
|
|
of ' ': content.add(' ')
|
|
|
|
of '"': content.add('"')
|
|
|
|
of '/': content.add('/')
|
|
|
|
of '\\': content.add('\\')
|
|
|
|
of 'N': content.add(UTF8NextLine)
|
|
|
|
of '_': content.add(UTF8NonBreakingSpace)
|
|
|
|
of 'L': content.add(UTF8LineSeparator)
|
|
|
|
of 'P': content.add(UTF8ParagraphSeparator)
|
|
|
|
of 'x': content.add(lexer.unicodeSequence(2))
|
|
|
|
of 'u': content.add(lexer.unicodeSequence(4))
|
|
|
|
of 'U': content.add(lexer.unicodeSequence(8))
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l', '\c':
|
2016-01-23 14:29:45 +00:00
|
|
|
var newlines = 0
|
2016-03-17 20:25:30 +00:00
|
|
|
processQuotedWhitespace(newlines)
|
2016-01-23 14:29:45 +00:00
|
|
|
continue
|
2016-03-17 18:30:40 +00:00
|
|
|
else: lexerError(lexer, "Illegal character in escape sequence")
|
2016-01-20 20:15:33 +00:00
|
|
|
of '"':
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
break
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l', '\c', '\t', ' ':
|
2016-01-23 14:29:45 +00:00
|
|
|
var newlines = 1
|
2016-03-17 20:25:30 +00:00
|
|
|
processQuotedWhitespace(newlines)
|
2016-01-23 14:29:45 +00:00
|
|
|
continue
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
|
|
|
content.add(c)
|
2016-01-23 14:29:45 +00:00
|
|
|
lexer.bufpos.inc()
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-03-17 20:25:30 +00:00
|
|
|
template singleQuotedScalar(lexer: BaseLexer, content: var string) =
|
|
|
|
debug("lex: singleQuotedScalar")
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
while true:
|
|
|
|
case lexer.buf[lexer.bufpos]
|
|
|
|
of '\'':
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] == '\'': content.add('\'')
|
|
|
|
else: break
|
|
|
|
of EndOfFile: lexerError(lexer, "Unfinished single quoted string")
|
|
|
|
of '\l', '\c', '\t', ' ':
|
|
|
|
var newlines = 1
|
|
|
|
processQuotedWhitespace(newlines)
|
|
|
|
continue
|
|
|
|
else: content.add(lexer.buf[lexer.bufpos])
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
proc isPlainSafe(lexer: BaseLexer, index: int, context: YamlContext): bool =
|
2016-01-20 20:15:33 +00:00
|
|
|
case lexer.buf[lexer.bufpos + 1]
|
2016-03-17 18:30:40 +00:00
|
|
|
of spaceOrLineEnd: result = false
|
|
|
|
of flowIndicators: result = context == cBlock
|
|
|
|
else: result = true
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template plainScalar(lexer: BaseLexer, content: var string,
|
2016-01-20 20:15:33 +00:00
|
|
|
context: YamlContext) =
|
|
|
|
debug("lex: plainScalar")
|
|
|
|
content.add(lexer.buf[lexer.bufpos])
|
|
|
|
block outer:
|
|
|
|
while true:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
let c = lexer.buf[lexer.bufpos]
|
|
|
|
case c
|
2016-03-17 18:30:40 +00:00
|
|
|
of lineEnd: break
|
2016-01-20 20:15:33 +00:00
|
|
|
of ' ', '\t':
|
|
|
|
var after = "" & c
|
|
|
|
while true:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
let c2 = lexer.buf[lexer.bufpos]
|
|
|
|
case c2
|
2016-03-11 16:56:42 +00:00
|
|
|
of ' ', '\t': after.add(c2)
|
|
|
|
of lineEnd: break outer
|
2016-01-20 20:15:33 +00:00
|
|
|
of ':':
|
|
|
|
if lexer.isPlainSafe(lexer.bufpos + 1, context):
|
|
|
|
content.add(after & ':')
|
2016-03-11 16:56:42 +00:00
|
|
|
break
|
|
|
|
else: break outer
|
|
|
|
of '#': break outer
|
2016-02-18 21:14:24 +00:00
|
|
|
of flowIndicators:
|
2016-02-19 17:25:01 +00:00
|
|
|
if context == cBlock:
|
2016-02-18 21:14:24 +00:00
|
|
|
content.add(after)
|
|
|
|
content.add(c2)
|
|
|
|
break
|
2016-03-11 16:56:42 +00:00
|
|
|
else: break outer
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
|
|
|
content.add(after)
|
|
|
|
content.add(c2)
|
|
|
|
break
|
|
|
|
of flowIndicators:
|
2016-03-11 16:56:42 +00:00
|
|
|
if context == cBlock: content.add(c)
|
|
|
|
else: break
|
2016-01-20 20:15:33 +00:00
|
|
|
of ':':
|
2016-03-11 16:56:42 +00:00
|
|
|
if lexer.isPlainSafe(lexer.bufpos + 1, context): content.add(':')
|
|
|
|
else: break outer
|
|
|
|
of '#': break outer
|
|
|
|
else: content.add(c)
|
|
|
|
debug("lex: \"" & content & '\"')
|
2016-01-20 20:15:33 +00:00
|
|
|
|
|
|
|
template continueMultilineScalar() {.dirty.} =
|
2016-02-26 18:28:28 +00:00
|
|
|
content.add(if newlines == 1: " " else: repeat('\l', newlines - 1))
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cBlock)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockAfterPlainScalar
|
|
|
|
|
2016-01-20 22:38:39 +00:00
|
|
|
template handleFlowPlainScalar() {.dirty.} =
|
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cFlow)
|
2016-03-09 19:29:18 +00:00
|
|
|
if p.lexer.buf[p.lexer.bufpos] in {'{', '}', '[', ']', ',', ':', '#'}:
|
2016-01-20 22:38:39 +00:00
|
|
|
discard
|
|
|
|
else:
|
|
|
|
var newlines = 0
|
|
|
|
while true:
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-01-20 22:38:39 +00:00
|
|
|
of ':':
|
2016-02-19 17:25:01 +00:00
|
|
|
if p.lexer.isPlainSafe(p.lexer.bufpos + 1, cFlow):
|
2016-01-22 22:44:26 +00:00
|
|
|
if newlines == 1:
|
|
|
|
content.add(' ')
|
|
|
|
newlines = 0
|
|
|
|
elif newlines > 1:
|
|
|
|
content.add(repeat(' ', newlines - 1))
|
|
|
|
newlines = 0
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cFlow)
|
2016-01-22 22:44:26 +00:00
|
|
|
elif explicitFlowKey:
|
|
|
|
break
|
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Multiline scalar is not allowed as implicit key")
|
2016-03-17 18:30:40 +00:00
|
|
|
of '#', EndOfFile: break
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-20 22:38:39 +00:00
|
|
|
newlines.inc()
|
|
|
|
of '\c':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
2016-01-20 22:38:39 +00:00
|
|
|
newlines.inc()
|
2016-03-17 18:30:40 +00:00
|
|
|
of flowIndicators: break
|
|
|
|
of ' ', '\t': p.lexer.skipWhitespace()
|
2016-01-20 22:38:39 +00:00
|
|
|
else:
|
|
|
|
if newlines == 1:
|
|
|
|
content.add(' ')
|
|
|
|
newlines = 0
|
|
|
|
elif newlines > 1:
|
|
|
|
content.add(repeat(' ', newlines - 1))
|
|
|
|
newlines = 0
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cFlow)
|
2016-01-20 22:38:39 +00:00
|
|
|
yield scalarEvent(content, tag, anchor)
|
2016-01-22 20:36:11 +00:00
|
|
|
handleObjectEnd(fpFlowAfterObject)
|
|
|
|
|
|
|
|
template ensureCorrectIndentation() {.dirty.} =
|
|
|
|
if level.indentation != indentation:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Invalid indentation (expected indentation of " &
|
|
|
|
$level.indentation & ")")
|
2016-01-20 22:38:39 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template tagHandle(lexer: var BaseLexer, content: var string,
|
2016-01-20 20:15:33 +00:00
|
|
|
shorthandEnd: var int) =
|
|
|
|
debug("lex: tagHandle")
|
|
|
|
shorthandEnd = 0
|
|
|
|
content.add(lexer.buf[lexer.bufpos])
|
|
|
|
var i = 0
|
|
|
|
while true:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
i.inc()
|
|
|
|
let c = lexer.buf[lexer.bufpos]
|
|
|
|
case c
|
|
|
|
of spaceOrLineEnd:
|
2016-03-17 18:30:40 +00:00
|
|
|
if shorthandEnd == -1: lexerError(lexer, "Unclosed verbatim tag")
|
2016-01-20 20:15:33 +00:00
|
|
|
break
|
|
|
|
of '!':
|
|
|
|
if shorthandEnd == -1 and i == 2:
|
|
|
|
content.add(c)
|
2016-03-17 17:44:35 +00:00
|
|
|
continue
|
2016-01-20 20:15:33 +00:00
|
|
|
elif shorthandEnd != 0:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Illegal character in tag suffix")
|
2016-01-20 20:15:33 +00:00
|
|
|
shorthandEnd = i
|
|
|
|
content.add(c)
|
|
|
|
of 'a' .. 'z', 'A' .. 'Z', '0' .. '9', '#', ';', '/', '?', ':', '@', '&',
|
2016-03-17 18:45:01 +00:00
|
|
|
'-', '=', '+', '$', '_', '.', '~', '*', '\'', '(', ')':
|
|
|
|
content.add(c)
|
|
|
|
of ',':
|
|
|
|
if shortHandEnd > 0: break # ',' after shorthand is flow indicator
|
2016-01-20 20:15:33 +00:00
|
|
|
content.add(c)
|
|
|
|
of '<':
|
|
|
|
if i == 1:
|
|
|
|
shorthandEnd = -1
|
|
|
|
content = ""
|
2016-03-17 17:44:35 +00:00
|
|
|
else: lexerError(lexer, "Illegal character in tag handle")
|
2016-01-20 20:15:33 +00:00
|
|
|
of '>':
|
|
|
|
if shorthandEnd == -1:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if lexer.buf[lexer.bufpos] notin spaceOrLineEnd:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Missing space after verbatim tag handle")
|
2016-01-20 20:15:33 +00:00
|
|
|
break
|
2016-03-17 17:44:35 +00:00
|
|
|
else: lexerError(lexer, "Illegal character in tag handle")
|
|
|
|
of '%':
|
2016-03-17 18:30:40 +00:00
|
|
|
if shorthandEnd != 0: content.add(lexer.byteSequence())
|
2016-03-17 17:44:35 +00:00
|
|
|
else: lexerError(lexer, "Illegal character in tag handle")
|
|
|
|
else: lexerError(lexer, "Illegal character in tag handle")
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template anchorName(lexer: BaseLexer, content: var string) =
|
2016-01-20 20:15:33 +00:00
|
|
|
debug("lex: anchorName")
|
|
|
|
while true:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
let c = lexer.buf[lexer.bufpos]
|
|
|
|
case c
|
2016-03-17 18:30:40 +00:00
|
|
|
of spaceOrLineEnd, '[', ']', '{', '}', ',': break
|
|
|
|
else: content.add(c)
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
template blockScalar(lexer: BaseLexer, content: var string,
|
2016-01-23 13:09:52 +00:00
|
|
|
stateAfter: var FastParseState) =
|
2016-03-11 16:56:42 +00:00
|
|
|
debug("lex: blockScalar")
|
2016-01-23 13:09:52 +00:00
|
|
|
type ChompType = enum
|
|
|
|
ctKeep, ctClip, ctStrip
|
|
|
|
var
|
|
|
|
literal: bool
|
|
|
|
blockIndent = 0
|
|
|
|
chomp: ChompType = ctClip
|
|
|
|
detectedIndent = false
|
2016-03-10 20:20:14 +00:00
|
|
|
recentLineMoreIndented = false
|
2016-01-24 10:44:10 +00:00
|
|
|
|
2016-01-23 13:09:52 +00:00
|
|
|
case lexer.buf[lexer.bufpos]
|
2016-03-04 16:45:47 +00:00
|
|
|
of '|': literal = true
|
|
|
|
of '>': literal = false
|
|
|
|
else: assert(false)
|
2016-01-23 13:09:52 +00:00
|
|
|
|
|
|
|
while true:
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
case lexer.buf[lexer.bufpos]
|
|
|
|
of '+':
|
|
|
|
if chomp != ctClip:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Only one chomping indicator is allowed")
|
2016-01-23 13:09:52 +00:00
|
|
|
chomp = ctKeep
|
|
|
|
of '-':
|
|
|
|
if chomp != ctClip:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Only one chomping indicator is allowed")
|
2016-01-23 13:09:52 +00:00
|
|
|
chomp = ctStrip
|
|
|
|
of '1'..'9':
|
|
|
|
if detectedIndent:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Only one indentation indicator is allowed")
|
2016-01-23 13:09:52 +00:00
|
|
|
blockIndent = int(lexer.buf[lexer.bufpos]) - int('\x30')
|
|
|
|
detectedIndent = true
|
2016-03-17 18:30:40 +00:00
|
|
|
of spaceOrLineEnd: break
|
|
|
|
else: lexerError(lexer, "Illegal character in block scalar header")
|
2016-01-23 13:09:52 +00:00
|
|
|
lexer.lineEnding()
|
|
|
|
case lexer.buf[lexer.bufpos]
|
2016-03-04 16:45:47 +00:00
|
|
|
of '\l': lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
|
|
|
of '\c': lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
2016-01-23 13:09:52 +00:00
|
|
|
of EndOfFile:
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(lexer, "Missing content of block scalar")
|
|
|
|
# TODO: is this correct?
|
2016-03-17 18:30:40 +00:00
|
|
|
else: assert(false)
|
2016-01-23 13:09:52 +00:00
|
|
|
var newlines = 0
|
2016-03-04 16:45:47 +00:00
|
|
|
let parentIndent = if ancestry.len > 0:
|
2016-03-04 20:51:37 +00:00
|
|
|
ancestry[ancestry.high].indentation else: 0
|
2016-01-23 13:09:52 +00:00
|
|
|
content = ""
|
|
|
|
block outer:
|
|
|
|
while true:
|
|
|
|
block inner:
|
|
|
|
for i in countup(1, parentIndent):
|
|
|
|
case lexer.buf[lexer.bufpos]
|
2016-03-04 16:45:47 +00:00
|
|
|
of ' ': discard
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-23 13:09:52 +00:00
|
|
|
lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break inner
|
|
|
|
of '\c':
|
|
|
|
lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break inner
|
|
|
|
else:
|
|
|
|
stateAfter = if i == 1: fpBlockLineStart else: fpBlockObjectStart
|
|
|
|
break outer
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
if detectedIndent:
|
|
|
|
for i in countup(1, blockIndent):
|
|
|
|
case lexer.buf[lexer.bufpos]
|
2016-03-04 16:45:47 +00:00
|
|
|
of ' ': discard
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-23 13:09:52 +00:00
|
|
|
lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break inner
|
|
|
|
of '\c':
|
|
|
|
lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break inner
|
|
|
|
of EndOfFile:
|
|
|
|
stateAfter = fpBlockLineStart
|
|
|
|
break outer
|
|
|
|
of '#':
|
|
|
|
lexer.lineEnding()
|
|
|
|
case lexer.buf[lexer.bufpos]
|
2016-03-04 16:45:47 +00:00
|
|
|
of '\l': lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
|
|
|
of '\c': lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
2016-01-23 13:09:52 +00:00
|
|
|
else: discard
|
|
|
|
stateAfter = fpBlockLineStart
|
|
|
|
break outer
|
|
|
|
else:
|
2016-03-11 16:56:42 +00:00
|
|
|
if i == 1:
|
|
|
|
stateAfter = if parentIndent == 0: fpBlockLineStart else:
|
|
|
|
fpBlockObjectStart
|
|
|
|
break outer
|
|
|
|
else:
|
2016-03-04 18:07:12 +00:00
|
|
|
startToken()
|
|
|
|
parserError("The text is less indented than expected ")
|
2016-01-23 13:09:52 +00:00
|
|
|
lexer.bufpos.inc()
|
|
|
|
else:
|
|
|
|
while true:
|
|
|
|
case lexer.buf[lexer.bufpos]
|
2016-03-04 16:45:47 +00:00
|
|
|
of ' ': discard
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-23 13:09:52 +00:00
|
|
|
lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break inner
|
|
|
|
of '\c':
|
|
|
|
lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break inner
|
|
|
|
of EndOfFile:
|
|
|
|
stateAfter = fpBlockLineStart
|
|
|
|
break outer
|
|
|
|
else:
|
2016-03-04 20:51:37 +00:00
|
|
|
blockIndent = lexer.getColNumber(lexer.bufpos) - parentIndent
|
2016-01-23 13:09:52 +00:00
|
|
|
detectedIndent = true
|
|
|
|
break
|
|
|
|
lexer.bufpos.inc()
|
|
|
|
case lexer.buf[lexer.bufpos]
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-23 13:09:52 +00:00
|
|
|
lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break inner
|
|
|
|
of '\c':
|
|
|
|
lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break inner
|
|
|
|
of EndOfFile:
|
|
|
|
stateAfter = fpBlockLineStart
|
|
|
|
break outer
|
2016-03-16 18:20:18 +00:00
|
|
|
of ' ', '\t':
|
2016-03-10 20:20:14 +00:00
|
|
|
if not literal:
|
|
|
|
if not recentLineMoreIndented:
|
|
|
|
recentLineMoreIndented = true
|
|
|
|
newlines.inc()
|
|
|
|
else:
|
|
|
|
if not literal:
|
|
|
|
if recentLineMoreIndented:
|
|
|
|
recentLineMoreIndented = false
|
|
|
|
newlines.inc()
|
2016-01-23 13:09:52 +00:00
|
|
|
if newlines > 0:
|
2016-03-04 16:45:47 +00:00
|
|
|
if literal: content.add(repeat('\l', newlines))
|
|
|
|
elif newlines == 1: content.add(' ')
|
|
|
|
else: content.add(repeat('\l', newlines - 1))
|
2016-01-23 13:09:52 +00:00
|
|
|
newlines = 0
|
|
|
|
while true:
|
|
|
|
let c = lexer.buf[lexer.bufpos]
|
|
|
|
case c
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-23 13:09:52 +00:00
|
|
|
lexer.bufpos = lexer.handleLF(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break
|
|
|
|
of '\c':
|
|
|
|
lexer.bufpos = lexer.handleCR(lexer.bufpos)
|
|
|
|
newlines.inc()
|
|
|
|
break inner
|
|
|
|
of EndOfFile:
|
|
|
|
stateAfter = fpBlockLineStart
|
|
|
|
break outer
|
2016-03-04 16:45:47 +00:00
|
|
|
else: content.add(c)
|
2016-01-23 13:09:52 +00:00
|
|
|
lexer.bufpos.inc()
|
|
|
|
case chomp
|
2016-03-04 16:45:47 +00:00
|
|
|
of ctClip: content.add('\l')
|
|
|
|
of ctKeep: content.add(repeat('\l', newlines))
|
|
|
|
of ctStrip: discard
|
2016-03-11 16:56:42 +00:00
|
|
|
debug("lex: \"" & content & '\"')
|
2016-01-23 13:09:52 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
proc parse*(p: YamlParser, s: Stream): YamlStream =
|
2016-02-12 18:53:25 +00:00
|
|
|
var backend = iterator(): YamlStreamEvent =
|
2016-01-20 20:15:33 +00:00
|
|
|
var
|
|
|
|
state = fpInitial
|
|
|
|
shorthands: Table[string, string]
|
|
|
|
anchors: Table[string, AnchorId]
|
|
|
|
nextAnchorId: AnchorId
|
|
|
|
content: string
|
2016-01-23 16:44:50 +00:00
|
|
|
tag: TagId
|
|
|
|
anchor: AnchorId
|
2016-01-20 20:15:33 +00:00
|
|
|
ancestry = newSeq[FastParseLevel]()
|
|
|
|
level: FastParseLevel
|
|
|
|
indentation: int
|
|
|
|
newlines: int
|
2016-01-20 22:38:39 +00:00
|
|
|
flowdepth: int = 0
|
2016-01-22 22:44:26 +00:00
|
|
|
explicitFlowKey: bool
|
2016-01-20 20:15:33 +00:00
|
|
|
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.open(s)
|
2016-01-20 20:15:33 +00:00
|
|
|
initDocValues()
|
|
|
|
|
|
|
|
while true:
|
|
|
|
case state
|
|
|
|
of fpInitial:
|
|
|
|
debug("state: initial")
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-01-20 20:15:33 +00:00
|
|
|
of '%':
|
|
|
|
var ld: LexedDirective
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.directiveName(ld)
|
2016-01-20 20:15:33 +00:00
|
|
|
case ld
|
|
|
|
of ldYaml:
|
|
|
|
var version = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.yamlVersion(version)
|
2016-01-20 20:15:33 +00:00
|
|
|
if version != "1.2":
|
2016-01-24 17:24:09 +00:00
|
|
|
if p.callback != nil:
|
|
|
|
p.callback(p.lexer.lineNumber, p.getColNumber(),
|
|
|
|
p.getLineContent(),
|
|
|
|
"Version is not 1.2, but " & version)
|
2016-01-20 20:15:33 +00:00
|
|
|
discard
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-20 20:15:33 +00:00
|
|
|
handleLineEnd(false)
|
|
|
|
of ldTag:
|
|
|
|
var shorthand, uri = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.tagShorthand(shorthand)
|
|
|
|
p.lexer.tagUri(uri)
|
2016-03-11 17:32:17 +00:00
|
|
|
shorthands[shorthand] = uri
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-20 20:15:33 +00:00
|
|
|
handleLineEnd(false)
|
|
|
|
of ldUnknown:
|
2016-01-24 17:24:09 +00:00
|
|
|
if p.callback != nil:
|
|
|
|
p.callback(p.lexer.lineNumber, p.getColNumber(),
|
|
|
|
p.getLineContent(), "Unknown directive")
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.finishLine()
|
2016-01-20 20:15:33 +00:00
|
|
|
handleLineEnd(false)
|
|
|
|
of ' ', '\t':
|
2016-01-23 16:44:50 +00:00
|
|
|
while true:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-03-17 18:30:40 +00:00
|
|
|
of ' ', '\t': discard
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-23 16:44:50 +00:00
|
|
|
break
|
|
|
|
of '\c':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
2016-01-23 16:44:50 +00:00
|
|
|
break
|
|
|
|
of '#', EndOfFile:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-23 16:44:50 +00:00
|
|
|
handleLineEnd(false)
|
|
|
|
break
|
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
2016-01-23 16:44:50 +00:00
|
|
|
yield startDocEvent()
|
|
|
|
state = fpBlockObjectStart
|
|
|
|
break
|
2016-03-17 18:30:40 +00:00
|
|
|
of '\l': p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
|
|
|
of '\c': p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
|
|
|
of EndOfFile: return
|
2016-01-20 20:15:33 +00:00
|
|
|
of '#':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-20 20:15:33 +00:00
|
|
|
handleLineEnd(false)
|
|
|
|
of '-':
|
|
|
|
var token: LexedPossibleDirectivesEnd
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.directivesEnd(token)
|
2016-01-20 20:15:33 +00:00
|
|
|
yield startDocEvent()
|
|
|
|
case token
|
|
|
|
of lpdeDirectivesEnd:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc(3)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockObjectStart
|
|
|
|
of lpdeSequenceItem:
|
|
|
|
indentation = 0
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockSequenceIndicator()
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockObjectStart
|
|
|
|
of lpdeScalarContent:
|
2016-01-22 20:36:11 +00:00
|
|
|
content = ""
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cBlock)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockAfterPlainScalar
|
|
|
|
else:
|
|
|
|
yield startDocEvent()
|
|
|
|
state = fpBlockLineStart
|
|
|
|
of fpBlockLineStart:
|
|
|
|
debug("state: blockLineStart")
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-01-20 20:15:33 +00:00
|
|
|
of '-':
|
|
|
|
var token: LexedPossibleDirectivesEnd
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.directivesEnd(token)
|
2016-01-20 20:15:33 +00:00
|
|
|
case token
|
|
|
|
of lpdeDirectivesEnd:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc(3)
|
2016-01-20 20:15:33 +00:00
|
|
|
closeEverything()
|
|
|
|
initDocValues()
|
|
|
|
yield startDocEvent()
|
|
|
|
state = fpBlockObjectStart
|
|
|
|
of lpdeSequenceItem:
|
|
|
|
indentation = 0
|
2016-02-19 16:31:57 +00:00
|
|
|
closeMoreIndentedLevels(true)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockSequenceIndicator()
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockObjectStart
|
|
|
|
of lpdeScalarContent:
|
2016-01-22 20:36:11 +00:00
|
|
|
case level.kind
|
2016-03-17 18:30:40 +00:00
|
|
|
of fplScalar: continueMultilineScalar()
|
|
|
|
of fplUnknown: handlePossibleMapStart()
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
2016-01-22 20:36:11 +00:00
|
|
|
ensureCorrectIndentation()
|
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-22 20:36:11 +00:00
|
|
|
content = ""
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cBlock)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockAfterPlainScalar
|
|
|
|
of '.':
|
|
|
|
var isDocumentEnd: bool
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.documentEnd(isDocumentEnd)
|
2016-01-20 20:15:33 +00:00
|
|
|
if isDocumentEnd:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc(3)
|
|
|
|
p.lexer.lineEnding()
|
2016-01-22 20:36:11 +00:00
|
|
|
handleLineEnd(true)
|
2016-01-20 20:15:33 +00:00
|
|
|
closeEverything()
|
|
|
|
initDocValues()
|
|
|
|
state = fpInitial
|
|
|
|
else:
|
2016-01-22 20:36:11 +00:00
|
|
|
indentation = 0
|
|
|
|
closeMoreIndentedLevels()
|
|
|
|
case level.kind
|
2016-03-17 18:30:40 +00:00
|
|
|
of fplUnknown: handlePossibleMapStart()
|
|
|
|
of fplScalar: continueMultilineScalar()
|
2016-01-22 20:36:11 +00:00
|
|
|
else:
|
|
|
|
ensureCorrectIndentation()
|
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-22 20:36:11 +00:00
|
|
|
content = ""
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cBlock)
|
2016-01-22 20:36:11 +00:00
|
|
|
state = fpBlockAfterPlainScalar
|
2016-01-20 20:15:33 +00:00
|
|
|
of ' ':
|
2016-03-17 20:25:30 +00:00
|
|
|
let c = p.lexer.buf[p.lexer.bufpos]
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.skipIndentation()
|
2016-03-17 20:25:30 +00:00
|
|
|
if c in {'\l', '\c', '#', EndOfFile}:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-23 13:09:52 +00:00
|
|
|
handleLineEnd(true)
|
2016-03-17 20:25:30 +00:00
|
|
|
elif c == '\t':
|
|
|
|
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
|
|
|
p.lexer.bufpos.inc()
|
|
|
|
while p.lexer.buf[p.lexer.bufpos] in {'\t', ' '}:
|
|
|
|
p.lexer.bufpos.inc()
|
|
|
|
if p.lexer.buf[p.lexer.bufpos] in {'\l', '\c', '#', EndOfFile}:
|
|
|
|
p.lexer.lineEnding()
|
|
|
|
handleLineEnd(true)
|
|
|
|
else:
|
|
|
|
closeMoreIndentedLevels(true)
|
|
|
|
if level.kind == fplScalar: state = fpBlockContinueScalar
|
|
|
|
else: lexerError(p.lexer, "tabular not allowed here")
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
2016-03-17 20:25:30 +00:00
|
|
|
if c == '-' and not
|
2016-02-19 16:31:57 +00:00
|
|
|
p.lexer.isPlainSafe(p.lexer.bufpos + 1, if flowdepth == 0:
|
2016-02-19 17:25:01 +00:00
|
|
|
cBlock else: cFlow):
|
2016-02-19 16:31:57 +00:00
|
|
|
closeMoreIndentedLevels(true)
|
|
|
|
else: closeMoreIndentedLevels()
|
2016-01-23 13:09:52 +00:00
|
|
|
case level.kind
|
2016-03-17 18:30:40 +00:00
|
|
|
of fplScalar: state = fpBlockContinueScalar
|
|
|
|
of fplUnknown: state = fpBlockObjectStart
|
2016-01-23 13:09:52 +00:00
|
|
|
else:
|
|
|
|
ensureCorrectIndentation()
|
|
|
|
state = fpBlockObjectStart
|
2016-02-18 21:32:25 +00:00
|
|
|
of EndOfFile:
|
|
|
|
closeEverything()
|
|
|
|
break
|
2016-03-17 20:25:30 +00:00
|
|
|
of '\t':
|
|
|
|
indentation = 0
|
|
|
|
p.lexer.bufpos.inc()
|
|
|
|
while p.lexer.buf[p.lexer.bufpos] in {'\t', ' '}: p.lexer.bufpos.inc()
|
|
|
|
if p.lexer.buf[p.lexer.bufpos] in {'\l', '\c', '#', EndOfFile}:
|
|
|
|
p.lexer.lineEnding()
|
|
|
|
handleLineEnd(true)
|
|
|
|
else:
|
|
|
|
closeMoreIndentedLevels(true)
|
|
|
|
if level.kind == fplScalar: state = fpBlockContinueScalar
|
|
|
|
else: lexerError(p.lexer, "tabular not allowed here")
|
|
|
|
of '\l', '\c', '#':
|
2016-02-18 21:32:25 +00:00
|
|
|
p.lexer.lineEnding()
|
|
|
|
handleLineEnd(true)
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
|
|
|
indentation = 0
|
|
|
|
closeMoreIndentedLevels()
|
|
|
|
case level.kind
|
2016-03-17 18:30:40 +00:00
|
|
|
of fplScalar: state = fpBlockContinueScalar
|
|
|
|
of fplUnknown: state = fpBlockObjectStart
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
2016-01-22 20:36:11 +00:00
|
|
|
ensureCorrectIndentation()
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockObjectStart
|
|
|
|
of fpBlockContinueScalar:
|
2016-03-04 18:07:12 +00:00
|
|
|
debug("state: fpBlockContinueScalar")
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.skipWhitespace()
|
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-20 20:15:33 +00:00
|
|
|
newlines.inc()
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockLineStart
|
|
|
|
of '\c':
|
|
|
|
newlines.inc()
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
of ':':
|
2016-02-19 17:25:01 +00:00
|
|
|
if p.lexer.isPlainSafe(p.lexer.bufpos + 1, cBlock):
|
2016-01-20 20:15:33 +00:00
|
|
|
continueMultilineScalar()
|
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected token")
|
2016-01-20 20:15:33 +00:00
|
|
|
of '#':
|
2016-01-22 20:36:11 +00:00
|
|
|
yield scalarEvent(content, tag, anchor)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-20 20:15:33 +00:00
|
|
|
handleLineEnd(true)
|
2016-01-22 20:36:11 +00:00
|
|
|
handleObjectEnd(fpBlockLineStart)
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
|
|
|
continueMultilineScalar()
|
|
|
|
of fpBlockAfterPlainScalar:
|
|
|
|
debug("state: blockAfterPlainScalar")
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.skipWhitespace()
|
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-03-09 19:29:18 +00:00
|
|
|
if level.kind notin {fplUnknown, fplScalar}:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected scalar")
|
2016-01-20 20:15:33 +00:00
|
|
|
newlines = 1
|
|
|
|
level.kind = fplScalar
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockLineStart
|
|
|
|
of '\c':
|
2016-03-09 19:29:18 +00:00
|
|
|
if level.kind notin {fplUnknown, fplScalar}:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected scalar")
|
2016-01-20 20:15:33 +00:00
|
|
|
newlines = 1
|
|
|
|
level.kind = fplScalar
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockLineStart
|
|
|
|
else:
|
2016-01-22 20:36:11 +00:00
|
|
|
yield scalarEvent(content, tag, anchor)
|
|
|
|
handleObjectEnd(fpBlockAfterObject)
|
|
|
|
of fpBlockAfterObject:
|
|
|
|
debug("state: blockAfterObject")
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.skipWhitespace()
|
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-01-20 20:15:33 +00:00
|
|
|
of EndOfFile:
|
|
|
|
closeEverything()
|
|
|
|
break
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-22 20:36:11 +00:00
|
|
|
state = fpBlockLineStart
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
of '\c':
|
2016-01-22 20:36:11 +00:00
|
|
|
state = fpBlockLineStart
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
of ':':
|
|
|
|
case level.kind
|
|
|
|
of fplUnknown:
|
2016-01-23 16:44:50 +00:00
|
|
|
handleObjectStart(yamlStartMap)
|
2016-01-20 20:15:33 +00:00
|
|
|
of fplMapKey:
|
2016-01-22 20:36:11 +00:00
|
|
|
yield scalarEvent("", yTagQuestionMark, yAnchorNone)
|
|
|
|
level.kind = fplMapValue
|
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-22 20:36:11 +00:00
|
|
|
of fplMapValue:
|
|
|
|
level.kind = fplMapValue
|
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-20 20:15:33 +00:00
|
|
|
of fplSequence:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Illegal token (expected sequence item)")
|
2016-01-20 20:15:33 +00:00
|
|
|
of fplScalar:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Multiline scalars may not be implicit map keys")
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairKey, fplSinglePairValue: assert(false)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
|
|
|
p.lexer.skipWhitespace()
|
|
|
|
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockObjectStart
|
|
|
|
of '#':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-20 20:15:33 +00:00
|
|
|
handleLineEnd(true)
|
2016-03-04 18:07:12 +00:00
|
|
|
state = fpBlockLineStart
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Illegal token (expected ':', comment or line end)")
|
2016-01-20 20:15:33 +00:00
|
|
|
of fpBlockObjectStart:
|
|
|
|
debug("state: blockObjectStart")
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.skipWhitespace()
|
|
|
|
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-02-26 18:28:28 +00:00
|
|
|
of '\l':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockLineStart
|
2016-01-23 16:44:50 +00:00
|
|
|
level.indentation = -1
|
2016-01-20 20:15:33 +00:00
|
|
|
of '\c':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockLineStart
|
2016-01-23 16:44:50 +00:00
|
|
|
level.indentation = -1
|
2016-01-20 20:15:33 +00:00
|
|
|
of EndOfFile:
|
|
|
|
closeEverything()
|
|
|
|
return
|
|
|
|
of '#':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-20 20:15:33 +00:00
|
|
|
handleLineEnd(true)
|
|
|
|
of '\'':
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-20 20:15:33 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.singleQuotedScalar(content)
|
2016-03-17 18:30:40 +00:00
|
|
|
if tag == yTagQuestionMark: tag = yTagExclamationMark
|
2016-01-22 20:36:11 +00:00
|
|
|
yield scalarEvent(content, tag, anchor)
|
|
|
|
handleObjectEnd(fpBlockAfterObject)
|
2016-01-20 20:15:33 +00:00
|
|
|
of '"':
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-20 20:15:33 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.doubleQuotedScalar(content)
|
2016-03-17 18:30:40 +00:00
|
|
|
if tag == yTagQuestionMark: tag = yTagExclamationMark
|
2016-01-22 20:36:11 +00:00
|
|
|
yield scalarEvent(content, tag, anchor)
|
|
|
|
handleObjectEnd(fpBlockAfterObject)
|
2016-01-23 13:09:52 +00:00
|
|
|
of '|', '>':
|
2016-01-23 16:44:50 +00:00
|
|
|
# TODO: this will scan for possible map start, which is not
|
|
|
|
# neccessary in this case
|
2016-01-23 13:09:52 +00:00
|
|
|
handleBlockItemStart()
|
|
|
|
var stateAfter: FastParseState
|
2016-01-23 16:44:50 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.blockScalar(content, stateAfter)
|
2016-03-04 18:07:12 +00:00
|
|
|
if tag == yTagQuestionMark: tag = yTagExclamationMark
|
2016-01-23 13:09:52 +00:00
|
|
|
yield scalarEvent(content, tag, anchor)
|
|
|
|
handleObjectEnd(stateAfter)
|
2016-03-11 17:09:34 +00:00
|
|
|
if stateAfter == fpBlockObjectStart:
|
|
|
|
indentation = p.lexer.getColNumber(p.lexer.bufpos)
|
|
|
|
closeMoreIndentedLevels()
|
2016-01-20 20:15:33 +00:00
|
|
|
of '-':
|
2016-02-19 17:25:01 +00:00
|
|
|
if p.lexer.isPlainSafe(p.lexer.bufpos + 1, cBlock):
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-23 16:44:50 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cBlock)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockAfterPlainScalar
|
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockSequenceIndicator()
|
2016-01-20 20:15:33 +00:00
|
|
|
of '!':
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-20 22:38:39 +00:00
|
|
|
handleTagHandle()
|
2016-01-20 20:15:33 +00:00
|
|
|
of '&':
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-20 22:38:39 +00:00
|
|
|
handleAnchor()
|
2016-01-20 20:15:33 +00:00
|
|
|
of '*':
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-20 22:38:39 +00:00
|
|
|
handleAlias()
|
|
|
|
of '[', '{':
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-20 22:38:39 +00:00
|
|
|
state = fpFlow
|
2016-01-22 22:44:26 +00:00
|
|
|
of '?':
|
2016-02-19 17:25:01 +00:00
|
|
|
if p.lexer.isPlainSafe(p.lexer.bufpos + 1, cBlock):
|
2016-01-22 22:44:26 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-23 16:44:50 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cBlock)
|
2016-01-22 22:44:26 +00:00
|
|
|
state = fpBlockAfterPlainScalar
|
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-22 22:44:26 +00:00
|
|
|
handleMapKeyIndicator()
|
|
|
|
of ':':
|
2016-02-19 17:25:01 +00:00
|
|
|
if p.lexer.isPlainSafe(p.lexer.bufpos + 1, cBlock):
|
2016-01-22 22:44:26 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-23 16:44:50 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cBlock)
|
2016-01-22 22:44:26 +00:00
|
|
|
state = fpBlockAfterPlainScalar
|
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-22 22:44:26 +00:00
|
|
|
handleMapValueIndicator()
|
2016-01-23 16:44:50 +00:00
|
|
|
of '@', '`':
|
2016-01-24 10:44:10 +00:00
|
|
|
lexerError(p.lexer, "Reserved characters cannot start a plain scalar")
|
2016-01-20 20:15:33 +00:00
|
|
|
else:
|
2016-01-22 20:36:11 +00:00
|
|
|
handleBlockItemStart()
|
2016-01-20 20:15:33 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
2016-02-19 17:25:01 +00:00
|
|
|
p.lexer.plainScalar(content, cBlock)
|
2016-01-20 20:15:33 +00:00
|
|
|
state = fpBlockAfterPlainScalar
|
|
|
|
of fpExpectDocEnd:
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-01-20 22:38:39 +00:00
|
|
|
of '-':
|
|
|
|
var token: LexedPossibleDirectivesEnd
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.directivesEnd(token)
|
2016-01-20 22:38:39 +00:00
|
|
|
case token
|
|
|
|
of lpdeDirectivesEnd:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc(3)
|
2016-01-20 22:38:39 +00:00
|
|
|
yield endDocEvent()
|
|
|
|
initDocValues()
|
|
|
|
yield startDocEvent()
|
|
|
|
state = fpBlockObjectStart
|
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Unexpected content (expected document end)")
|
2016-01-20 22:38:39 +00:00
|
|
|
of '.':
|
|
|
|
var isDocumentEnd: bool
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.documentEnd(isDocumentEnd)
|
2016-01-20 22:38:39 +00:00
|
|
|
if isDocumentEnd:
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc(3)
|
2016-01-20 22:38:39 +00:00
|
|
|
yield endDocEvent()
|
|
|
|
initDocValues()
|
|
|
|
state = fpInitial
|
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
parserError("Unexpected content (expected document end)")
|
2016-01-20 22:38:39 +00:00
|
|
|
of ' ', '\t', '#':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-20 22:38:39 +00:00
|
|
|
handleLineEnd(true)
|
2016-03-17 18:30:40 +00:00
|
|
|
of '\l': p.lexer.bufpos = p.lexer.handleLF(p.lexer.bufpos)
|
|
|
|
of '\c': p.lexer.bufpos = p.lexer.handleCR(p.lexer.bufpos)
|
2016-01-20 22:38:39 +00:00
|
|
|
of EndOfFile:
|
|
|
|
yield endDocEvent()
|
|
|
|
break
|
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected content (expected document end)")
|
2016-01-20 22:38:39 +00:00
|
|
|
of fpFlow:
|
2016-01-22 20:36:11 +00:00
|
|
|
debug("state: flow")
|
2016-03-16 18:30:51 +00:00
|
|
|
p.lexer.skipWhitespaceCommentsAndNewlines()
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-01-20 22:38:39 +00:00
|
|
|
of '{':
|
2016-03-17 19:28:00 +00:00
|
|
|
handleFlowItemStart()
|
2016-01-23 16:44:50 +00:00
|
|
|
handleObjectStart(yamlStartMap)
|
2016-01-20 22:38:39 +00:00
|
|
|
flowdepth.inc()
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-22 22:44:26 +00:00
|
|
|
explicitFlowKey = false
|
2016-01-20 22:38:39 +00:00
|
|
|
of '[':
|
2016-03-17 19:28:00 +00:00
|
|
|
handleFlowItemStart()
|
2016-03-14 17:10:34 +00:00
|
|
|
handleObjectStart(yamlStartSeq)
|
2016-01-20 22:38:39 +00:00
|
|
|
flowdepth.inc()
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-20 22:38:39 +00:00
|
|
|
of '}':
|
|
|
|
assert(level.kind == fplUnknown)
|
|
|
|
level = ancestry.pop()
|
|
|
|
case level.kind
|
|
|
|
of fplMapValue:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-20 22:38:39 +00:00
|
|
|
anchor = yAnchorNone
|
2016-01-22 20:36:11 +00:00
|
|
|
level.kind = fplMapKey
|
2016-01-20 22:38:39 +00:00
|
|
|
of fplMapKey:
|
2016-01-24 18:15:50 +00:00
|
|
|
if tag != yTagQuestionMark or anchor != yAnchorNone or
|
2016-01-22 22:44:26 +00:00
|
|
|
explicitFlowKey:
|
2016-01-22 21:40:22 +00:00
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-22 21:40:22 +00:00
|
|
|
anchor = yAnchorNone
|
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-20 22:38:39 +00:00
|
|
|
of fplSequence:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected token (expected ']')")
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairValue:
|
|
|
|
startToken()
|
|
|
|
parserError("Unexpected token (expected ']')")
|
|
|
|
of fplUnknown, fplScalar, fplSinglePairKey: assert(false)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-22 20:36:11 +00:00
|
|
|
leaveFlowLevel()
|
2016-01-20 22:38:39 +00:00
|
|
|
of ']':
|
|
|
|
assert(level.kind == fplUnknown)
|
|
|
|
level = ancestry.pop()
|
|
|
|
case level.kind
|
|
|
|
of fplSequence:
|
2016-01-24 18:15:50 +00:00
|
|
|
if tag != yTagQuestionMark or anchor != yAnchorNone:
|
2016-01-22 21:40:22 +00:00
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-22 21:40:22 +00:00
|
|
|
anchor = yAnchorNone
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairValue:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
|
|
|
tag = yTagQuestionMark
|
|
|
|
anchor = yAnchorNone
|
|
|
|
level = ancestry.pop()
|
|
|
|
yield endMapEvent()
|
|
|
|
assert(level.kind == fplSequence)
|
2016-01-20 22:38:39 +00:00
|
|
|
of fplMapKey, fplMapValue:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected token (expected '}')")
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplUnknown, fplScalar, fplSinglePairKey: assert(false)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-22 20:36:11 +00:00
|
|
|
leaveFlowLevel()
|
2016-01-20 22:38:39 +00:00
|
|
|
of ',':
|
|
|
|
assert(level.kind == fplUnknown)
|
|
|
|
level = ancestry.pop()
|
|
|
|
case level.kind
|
|
|
|
of fplSequence:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-20 22:38:39 +00:00
|
|
|
anchor = yAnchorNone
|
|
|
|
of fplMapValue:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-20 22:38:39 +00:00
|
|
|
anchor = yAnchorNone
|
|
|
|
level.kind = fplMapKey
|
2016-01-22 22:44:26 +00:00
|
|
|
explicitFlowKey = false
|
2016-01-20 22:38:39 +00:00
|
|
|
of fplMapKey:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-20 22:38:39 +00:00
|
|
|
anchor = yAnchorNone
|
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-22 22:44:26 +00:00
|
|
|
explicitFlowKey = false
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairValue:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
|
|
|
tag = yTagQuestionMark
|
|
|
|
anchor = yAnchorNone
|
|
|
|
level = ancestry.pop()
|
|
|
|
yield endMapEvent()
|
|
|
|
assert(level.kind == fplSequence)
|
|
|
|
of fplUnknown, fplScalar, fplSinglePairKey: assert(false)
|
2016-01-20 22:38:39 +00:00
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-20 22:38:39 +00:00
|
|
|
of ':':
|
|
|
|
assert(level.kind == fplUnknown)
|
2016-02-19 17:25:01 +00:00
|
|
|
if p.lexer.isPlainSafe(p.lexer.bufpos + 1, cFlow):
|
2016-03-17 19:28:00 +00:00
|
|
|
handleFlowItemStart()
|
2016-03-17 17:57:14 +00:00
|
|
|
handleFlowPlainScalar()
|
|
|
|
else:
|
2016-01-20 22:38:39 +00:00
|
|
|
level = ancestry.pop()
|
|
|
|
case level.kind
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSequence, fplMapValue, fplSinglePairValue:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected token (expected ',')")
|
2016-01-20 22:38:39 +00:00
|
|
|
of fplMapKey:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
2016-01-24 18:15:50 +00:00
|
|
|
tag = yTagQuestionMark
|
2016-01-20 22:38:39 +00:00
|
|
|
anchor = yAnchorNone
|
|
|
|
level.kind = fplMapValue
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairKey:
|
|
|
|
yield scalarEvent("", tag, anchor)
|
|
|
|
tag = yTagQuestionMark
|
|
|
|
anchor = yAnchorNone
|
|
|
|
level.kind = fplSinglePairValue
|
2016-01-20 22:38:39 +00:00
|
|
|
of fplUnknown, fplScalar:
|
|
|
|
assert(false)
|
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-21 18:23:45 +00:00
|
|
|
of '\'':
|
2016-03-17 19:28:00 +00:00
|
|
|
handleFlowItemStart()
|
2016-01-21 18:23:45 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.singleQuotedScalar(content)
|
2016-03-17 18:30:40 +00:00
|
|
|
if tag == yTagQuestionMark: tag = yTagExclamationMark
|
2016-01-21 18:23:45 +00:00
|
|
|
yield scalarEvent(content, tag, anchor)
|
2016-01-22 20:36:11 +00:00
|
|
|
handleObjectEnd(fpFlowAfterObject)
|
2016-01-21 18:23:45 +00:00
|
|
|
of '"':
|
2016-03-17 19:28:00 +00:00
|
|
|
handleFlowItemStart()
|
2016-01-21 18:23:45 +00:00
|
|
|
content = ""
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
p.lexer.doubleQuotedScalar(content)
|
2016-03-17 18:30:40 +00:00
|
|
|
if tag == yTagQuestionMark: tag = yTagExclamationMark
|
2016-01-21 18:23:45 +00:00
|
|
|
yield scalarEvent(content, tag, anchor)
|
2016-01-22 20:36:11 +00:00
|
|
|
handleObjectEnd(fpFlowAfterObject)
|
2016-03-17 19:28:00 +00:00
|
|
|
of '!':
|
|
|
|
handleFlowItemStart()
|
|
|
|
handleTagHandle()
|
|
|
|
of '&':
|
|
|
|
handleFlowItemStart()
|
|
|
|
handleAnchor()
|
2016-01-20 22:38:39 +00:00
|
|
|
of '*':
|
|
|
|
handleAlias()
|
2016-01-21 18:23:45 +00:00
|
|
|
state = fpFlowAfterObject
|
2016-01-22 22:44:26 +00:00
|
|
|
of '?':
|
2016-02-19 17:25:01 +00:00
|
|
|
if p.lexer.isPlainSafe(p.lexer.bufpos + 1, cFlow):
|
2016-03-17 19:28:00 +00:00
|
|
|
handleFlowItemStart()
|
2016-01-22 22:44:26 +00:00
|
|
|
handleFlowPlainScalar()
|
|
|
|
elif explicitFlowKey:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Duplicate '?' in flow mapping")
|
2016-01-22 22:44:26 +00:00
|
|
|
else:
|
|
|
|
explicitFlowKey = true
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-03-17 19:28:00 +00:00
|
|
|
else:
|
|
|
|
handleFlowItemStart()
|
|
|
|
handleFlowPlainScalar()
|
2016-01-20 22:38:39 +00:00
|
|
|
of fpFlowAfterObject:
|
2016-01-22 20:36:11 +00:00
|
|
|
debug("state: flowAfterObject")
|
2016-03-16 18:30:51 +00:00
|
|
|
p.lexer.skipWhitespaceCommentsAndNewlines()
|
2016-01-24 10:44:10 +00:00
|
|
|
case p.lexer.buf[p.lexer.bufpos]
|
2016-01-20 22:38:39 +00:00
|
|
|
of ']':
|
|
|
|
case level.kind
|
2016-03-17 17:57:14 +00:00
|
|
|
of fplSequence: discard
|
2016-01-20 22:38:39 +00:00
|
|
|
of fplMapKey, fplMapValue:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected token (expected '}')")
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairValue:
|
|
|
|
level = ancestry.pop()
|
|
|
|
assert(level.kind == fplSequence)
|
|
|
|
yield endMapEvent()
|
|
|
|
of fplScalar, fplUnknown, fplSinglePairKey: assert(false)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-20 22:38:39 +00:00
|
|
|
leaveFlowLevel()
|
|
|
|
of '}':
|
|
|
|
case level.kind
|
2016-03-17 17:57:14 +00:00
|
|
|
of fplMapKey, fplMapValue: discard
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSequence, fplSinglePairValue:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected token (expected ']')")
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplUnknown, fplScalar, fplSinglePairKey: assert(false)
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-20 22:38:39 +00:00
|
|
|
leaveFlowLevel()
|
|
|
|
of ',':
|
|
|
|
case level.kind
|
2016-03-17 17:57:14 +00:00
|
|
|
of fplSequence: discard
|
2016-01-20 22:38:39 +00:00
|
|
|
of fplMapValue:
|
2016-01-24 18:15:50 +00:00
|
|
|
yield scalarEvent("", yTagQuestionMark, yAnchorNone)
|
2016-01-20 22:38:39 +00:00
|
|
|
level.kind = fplMapKey
|
2016-01-22 22:44:26 +00:00
|
|
|
explicitFlowKey = false
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplSinglePairValue:
|
|
|
|
level = ancestry.pop()
|
|
|
|
assert(level.kind == fplSequence)
|
|
|
|
yield endMapEvent()
|
2016-03-17 17:57:14 +00:00
|
|
|
of fplMapKey: explicitFlowKey = false
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplUnknown, fplScalar, fplSinglePairKey: assert(false)
|
2016-01-20 22:38:39 +00:00
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-20 22:38:39 +00:00
|
|
|
state = fpFlow
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-20 22:38:39 +00:00
|
|
|
of ':':
|
|
|
|
case level.kind
|
2016-01-22 20:36:11 +00:00
|
|
|
of fplSequence, fplMapKey:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected token (expected ',')")
|
2016-03-17 19:28:00 +00:00
|
|
|
of fplMapValue, fplSinglePairValue: discard
|
|
|
|
of fplUnknown, fplScalar, fplSinglePairKey: assert(false)
|
2016-01-20 22:38:39 +00:00
|
|
|
ancestry.add(level)
|
2016-01-23 16:44:50 +00:00
|
|
|
level = FastParseLevel(kind: fplUnknown, indentation: -1)
|
2016-01-20 22:38:39 +00:00
|
|
|
state = fpFlow
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.bufpos.inc()
|
2016-01-20 22:38:39 +00:00
|
|
|
of '#':
|
2016-01-24 10:44:10 +00:00
|
|
|
p.lexer.lineEnding()
|
2016-01-22 20:36:11 +00:00
|
|
|
handleLineEnd(true)
|
2016-01-20 22:38:39 +00:00
|
|
|
of EndOfFile:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unclosed flow content")
|
2016-01-20 22:38:39 +00:00
|
|
|
else:
|
2016-01-24 10:44:10 +00:00
|
|
|
startToken()
|
|
|
|
parserError("Unexpected content (expected flow indicator)")
|
2016-03-17 17:57:14 +00:00
|
|
|
try: result = initYamlStream(backend)
|
2016-02-12 18:53:25 +00:00
|
|
|
except Exception: assert(false) # compiler error
|