Skip to content

Commit

Permalink
feat: Add withFilter
Browse files Browse the repository at this point in the history
x
  • Loading branch information
He-Pin committed Dec 8, 2024
1 parent d1003d4 commit 9323577
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fastparse/src-2/fastparse/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions fastparse/src-3/fastparse/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ 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.
Expand Down

0 comments on commit 9323577

Please sign in to comment.