From 22929ed54676170bb27f1532dae4a230f04ee688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=8E=E9=B8=A3?= Date: Sun, 8 Dec 2024 15:08:30 +0800 Subject: [PATCH] feat: Add withFilter x --- fastparse/src-2/fastparse/package.scala | 6 ++++++ fastparse/src-3/fastparse/package.scala | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/fastparse/src-2/fastparse/package.scala b/fastparse/src-2/fastparse/package.scala index 3b3633dd..1e67aab1 100644 --- a/fastparse/src-2/fastparse/package.scala +++ b/fastparse/src-2/fastparse/package.scala @@ -102,6 +102,12 @@ package object fastparse extends fastparse.SharedPackageDefs { def filter(f: T => Boolean) (implicit ctx: P[Any]): P[T] = macro MacroImpls.filterMacro[T] + /** + * Used by for-comprehensions. + */ + def withFilter(f: T => Boolean) + (implicit ctx: P[Any]): P[T] = macro MacroImpls.filterMacro[T] + /** * Transforms the result of this parser using the given partial function, * failing the parse if the partial function is not defined on the result diff --git a/fastparse/src-3/fastparse/package.scala b/fastparse/src-3/fastparse/package.scala index 638ab909..3e2ac32e 100644 --- a/fastparse/src-3/fastparse/package.scala +++ b/fastparse/src-3/fastparse/package.scala @@ -38,6 +38,12 @@ package object fastparse extends fastparse.SharedPackageDefs { inline def filter(f: T => Boolean)(using ctx: P[Any]): P[T] = MacroInlineImpls.filterInline[T](parse0)(f)(ctx) + /** + * Used by for-comprehensions. + */ + inline def withFilter(f: T => Boolean)(using ctx: P[Any]): P[T] = + MacroInlineImpls.filterInline[T](parse0)(f)(ctx) + /** Either-or operator: tries to parse the left-hand-side, and if that * fails it backtracks and tries to pass the right-hand-side. Can be * chained more than once to parse larger numbers of alternatives.