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
|
# tags
|
||||||
ylTagHandle, ylTagSuffix, ylVerbatimTag,
|
ylTagHandle, ylTagSuffix, ylVerbatimTag,
|
||||||
# document separation
|
# document separation
|
||||||
ylDashes, ylDots
|
ylDashes, ylDots,
|
||||||
|
# anchoring
|
||||||
|
ylAnchor, ylAlias
|
||||||
|
|
||||||
YamlLexer* = object of BaseLexer
|
YamlLexer* = object of BaseLexer
|
||||||
indentations: seq[int]
|
indentations: seq[int]
|
||||||
|
@ -549,9 +551,9 @@ iterator tokens*(my: var YamlLexer): YamlLexerEvent =
|
||||||
my.content.add(c)
|
my.content.add(c)
|
||||||
state = ylTagHandle
|
state = ylTagHandle
|
||||||
of '&':
|
of '&':
|
||||||
yieldError("TODO: anchors")
|
state = ylAnchor
|
||||||
of '*':
|
of '*':
|
||||||
yieldError("TODO: links")
|
state = ylAlias
|
||||||
of ' ':
|
of ' ':
|
||||||
discard
|
discard
|
||||||
of '-':
|
of '-':
|
||||||
|
@ -795,6 +797,22 @@ iterator tokens*(my: var YamlLexer): YamlLexerEvent =
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
my.content.add(c)
|
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
|
my.bufpos += my.charlen
|
||||||
inc(position)
|
inc(position)
|
|
@ -167,9 +167,19 @@ foo:
|
||||||
- baz
|
- baz
|
||||||
- biz
|
- biz
|
||||||
herp: derp""",
|
herp: derp""",
|
||||||
[t(yamlLineStart, ""), t(yamlScalar, "foo"), t(yamlColon, nil),
|
[t(yamlLineStart, ""), t(yamlScalar, "foo"), t(yamlColon, nil),
|
||||||
t(yamlLineStart, " "), t(yamlScalar, "bar"), 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, "baz"),
|
||||||
t(yamlLineStart, " "), t(yamlDash, nil), t(yamlScalar, "biz"),
|
t(yamlLineStart, " "), t(yamlDash, nil), t(yamlScalar, "biz"),
|
||||||
t(yamlLineStart, " "), t(yamlScalar, "herp"), t(yamlColon, nil),
|
t(yamlLineStart, " "), t(yamlScalar, "herp"), t(yamlColon, nil),
|
||||||
t(yamlScalar, "derp"), t(yamlStreamEnd, 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