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:
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user