Always take initial builder on the first parser/builder [*]

[*] Fixes bug where the builder would just copy the attributes of the
previous element.
This commit is contained in:
Florian Schroedl
2022-05-04 17:00:00 +02:00
parent 178bbed09d
commit 31844ed68d

View File

@@ -168,6 +168,7 @@ proc applyParsersToSingle*[T](
tokenFoldFn: (seq[ParserToken], T) -> T,
optional = false,
initT: T,
isFirst: bool,
): BuilderResult[T] =
# Apply the current parsing functions and convert to text tokens wrapped in ParserResult
let newParser = ParserResult.ok(Parser(
@@ -188,6 +189,7 @@ proc applyParsersToSingle*[T](
newParser.unsafeGet(),
builder.tree
.last()
.filter(x => not isFirst)
.orElse(just(initT))
.map((x: T) => @[tokenFoldFn(newTokens, x)])
.getOrElse(newSeq[T]())
@@ -211,7 +213,8 @@ proc applyParsersSeqToSingle*[T](
b.parsers,
b.tokenFoldFn,
b.ignoreEmpty,
initT
initT,
isFirst = a == builderResult
)),
builderResult
)