mirror of https://github.com/status-im/NimYAML.git
Implemented anchors and aliases
This commit is contained in:
parent
f876c845b7
commit
8493015042
|
@ -60,7 +60,9 @@ type
|
|||
# tags
|
||||
ylTagHandle, ylTagSuffix, ylVerbatimTag,
|
||||
# document separation
|
||||
ylDashes, ylDots
|
||||
ylDashes, ylDots,
|
||||
# anchoring
|
||||
ylAnchor, ylAlias
|
||||
|
||||
YamlLexer* = object of BaseLexer
|
||||
indentations: seq[int]
|
||||
|
@ -549,9 +551,9 @@ iterator tokens*(my: var YamlLexer): YamlLexerEvent =
|
|||
my.content.add(c)
|
||||
state = ylTagHandle
|
||||
of '&':
|
||||
yieldError("TODO: anchors")
|
||||
state = ylAnchor
|
||||
of '*':
|
||||
yieldError("TODO: links")
|
||||
state = ylAlias
|
||||
of ' ':
|
||||
discard
|
||||
of '-':
|
||||
|
@ -795,6 +797,22 @@ iterator tokens*(my: var YamlLexer): YamlLexerEvent =
|
|||
continue
|
||||
else:
|
||||
my.content.add(c)
|
||||
of ylAnchor:
|
||||
case c
|
||||
of EndOfFile, '\r', '\x0A', ' ', '\t', '{', '}', '[', ']':
|
||||
yieldToken(yamlAnchor)
|
||||
state = ylInitialInLine
|
||||
continue
|
||||
else:
|
||||
my.content.add(c)
|
||||
of ylAlias:
|
||||
case c
|
||||
of EndOfFile, '\r', '\x0A', ' ', '\t', '{', '}', '[', ']':
|
||||
yieldToken(yamlAlias)
|
||||
state = ylInitialInLine
|
||||
continue
|
||||
else:
|
||||
my.content.add(c)
|
||||
|
||||
my.bufpos += my.charlen
|
||||
inc(position)
|
|
@ -167,9 +167,19 @@ foo:
|
|||
- baz
|
||||
- biz
|
||||
herp: derp""",
|
||||
[t(yamlLineStart, ""), t(yamlScalar, "foo"), t(yamlColon, nil),
|
||||
t(yamlLineStart, " "), t(yamlScalar, "bar"), t(yamlColon, nil),
|
||||
t(yamlLineStart, " "), t(yamlDash, nil), t(yamlScalar, "baz"),
|
||||
t(yamlLineStart, " "), t(yamlDash, nil), t(yamlScalar, "biz"),
|
||||
t(yamlLineStart, " "), t(yamlScalar, "herp"), t(yamlColon, nil),
|
||||
t(yamlScalar, "derp"), t(yamlStreamEnd, nil)])
|
||||
[t(yamlLineStart, ""), t(yamlScalar, "foo"), t(yamlColon, nil),
|
||||
t(yamlLineStart, " "), t(yamlScalar, "bar"), t(yamlColon, nil),
|
||||
t(yamlLineStart, " "), t(yamlDash, nil), t(yamlScalar, "baz"),
|
||||
t(yamlLineStart, " "), t(yamlDash, nil), t(yamlScalar, "biz"),
|
||||
t(yamlLineStart, " "), t(yamlScalar, "herp"), t(yamlColon, nil),
|
||||
t(yamlScalar, "derp"), t(yamlStreamEnd, nil)])
|
||||
|
||||
test "Anchor":
|
||||
ensure("foo: &bar", [t(yamlLineStart, ""), t(yamlScalar, "foo"),
|
||||
t(yamlColon, nil), t(yamlAnchor, "bar"),
|
||||
t(yamlStreamEnd, nil)])
|
||||
|
||||
test "Alias":
|
||||
ensure("foo: *bar", [t(yamlLineStart, ""), t(yamlScalar, "foo"),
|
||||
t(yamlColon, nil), t(yamlAlias, "bar"),
|
||||
t(yamlStreamEnd, nil)])
|
Loading…
Reference in New Issue