Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add withFilter #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]

He-Pin marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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
6 changes: 6 additions & 0 deletions fastparse/src-3/fastparse/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down