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

Feature: allow Option<Skip>, Result<Filter<T>, _> in callbacks #235

Closed
Jeremy-Stafford opened this issue Feb 13, 2022 · 1 comment
Closed

Comments

@Jeremy-Stafford
Copy link
Contributor

Currently, logos does not allow nesting Skip and Filter in Option or Result.

This makes the following pattern very difficult (impossible?) to express:

  • Match a "start" pattern.
  • Compute the number of characters to skip, raising an error if this is not possible.
  • Match a "end" pattern.
  • Skip the whole token.

This pattern appears when lexing C-style block comments (/* ... */). For languages which forbid nesting (including C itself), this can be done using a regex (read: unreadable mess of stars and slashes). For languages which allow nesting, this cannot be fixed.

The current callback-result system is implemented as a trait. It would therefore be impossible to allow Option<Skip> (that would introduce overlapping implementations). This feature would therefore require a type defined as

enum FilterResult<T> {
    Error,
    Skip,
    Ok(T),
}
@evbo
Copy link

evbo commented Nov 20, 2022

@Jeremy-Stafford thank you and the contribution you made to the docs is excellent! Works like a charm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants