From 31844ed68da6efaac563633cedf4f4fc34e2e946 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 4 May 2022 17:00:00 +0200 Subject: [PATCH] Always take initial builder on the first parser/builder [*] [*] Fixes bug where the builder would just copy the attributes of the previous element. --- src/parser/parser_types.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/parser/parser_types.nim b/src/parser/parser_types.nim index af6b422..eaa55f7 100644 --- a/src/parser/parser_types.nim +++ b/src/parser/parser_types.nim @@ -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 )