From 860839efd0e6b77b4bc4cc46333040dd3951c0a1 Mon Sep 17 00:00:00 2001 From: Jamie Willis Date: Thu, 8 Jun 2023 23:26:13 +0100 Subject: [PATCH] `traverse` => `traverse_` to avoid building list of units! --- parsley/shared/src/main/scala/parsley/combinator.scala | 1 + .../main/scala/parsley/errors/tokenextractors/LexToken.scala | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/parsley/shared/src/main/scala/parsley/combinator.scala b/parsley/shared/src/main/scala/parsley/combinator.scala index ad8d5e3df..42340cd0c 100644 --- a/parsley/shared/src/main/scala/parsley/combinator.scala +++ b/parsley/shared/src/main/scala/parsley/combinator.scala @@ -185,6 +185,7 @@ object combinator { def traverse[A, B](f: A => Parsley[B], xs: A*): Parsley[List[B]] = sequence(xs.map(f): _*) // this will be used in future! private [parsley] def traverse5[A, B](xs: A*)(f: A => Parsley[B]): Parsley[List[B]] = traverse(f, xs: _*) + private [parsley] def traverse_[A](xs: A*)(f: A => Parsley[_]): Parsley[Unit] = skip(unit, xs.map(f): _*) /** This combinator will parse each of `ps` in order, discarding the results. * diff --git a/parsley/shared/src/main/scala/parsley/errors/tokenextractors/LexToken.scala b/parsley/shared/src/main/scala/parsley/errors/tokenextractors/LexToken.scala index 810c2a174..37b3e179b 100644 --- a/parsley/shared/src/main/scala/parsley/errors/tokenextractors/LexToken.scala +++ b/parsley/shared/src/main/scala/parsley/errors/tokenextractors/LexToken.scala @@ -10,7 +10,7 @@ import parsley.Success import parsley.XAssert.assert import parsley.XCompat.unused import parsley.character.{item, stringOfSome} -import parsley.combinator.{option, traverse5} +import parsley.combinator.{option, traverse5, traverse_} import parsley.errors.{ErrorBuilder, Token, TokenSpan} import parsley.position @@ -58,7 +58,7 @@ trait LexToken { this: ErrorBuilder[_] => private lazy val makeParser: Parsley[Either[::[(String, (Int, Int))], String]] = { val toks = traverse5(tokens: _*)(p => option(lookAhead(attempt(p) <~> position.pos))).map(_.flatten).collect { case toks@(_::_) => toks } // this can only fail if either there is no input (which there must be), or there is a token at the front, in which case `rawTok` is not parsed anyway - val rawTok = stringOfSome(traverse5(tokens: _*)(notFollowedBy) *> item) + val rawTok = stringOfSome(traverse_(tokens: _*)(notFollowedBy) *> item) toks <+> rawTok }