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

Properly handle side-effects in matchers #12

Open
BenWeber42 opened this issue Jun 17, 2020 · 1 comment
Open

Properly handle side-effects in matchers #12

BenWeber42 opened this issue Jun 17, 2020 · 1 comment
Labels
bug Something isn't working med-effort Requires medium effort/time med-prio Medium priority issue/task tech-debt Technical debt that is overdue

Comments

@BenWeber42
Copy link
Contributor

Capturer is a matcher with side-effects. The side-effects are applied when a Capturer submatcher matches. However, they should only be applied when the whole matcher matches.

Example:

OneOf(
  FixedList(
    Capture(_).append("wrong"),
    name("123) # this will always fail
  ),
  Capture(_).append("wrong")
)

The first Capture matcher is always executed, but the first option will fail. However, the state will already be modified.
The second Capture will succeed, but it will operate on the incorrectly modified state from the first Capture.

Since matchers are allowed to have side-effect, such side-effects should be properly supported.

@BenWeber42 BenWeber42 added bug Something isn't working med-prio Medium priority issue/task labels Jun 17, 2020
@BenWeber42
Copy link
Contributor Author

With this we can have a safer implementation of the Capture matcher as well. In particular, throw if a single variable is captured multiple times (

# TODO: throw if value already exists?
) as well as match first and only capture after the sub matcher succeeded (
# FIXME: figure out correct order of capturing/matching
)

@BenWeber42 BenWeber42 added med-effort Requires medium effort/time tech-debt Technical debt that is overdue labels Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working med-effort Requires medium effort/time med-prio Medium priority issue/task tech-debt Technical debt that is overdue
Projects
None yet
Development

No branches or pull requests

1 participant