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: allow inlined rules to match empty #3237

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rooney
Copy link
Contributor

@rooney rooney commented Mar 31, 2024

Fix #3220

@rooney rooney changed the title feat: allow inlined rules to be empty feat: allow inlined rules to match empty Mar 31, 2024
@amaanq
Copy link
Member

amaanq commented Apr 2, 2024

Tokens (terminals) can't be inlined - the linked issue doesn't have an example, is this for the case where a rule is an optional (thus can match nothing) but is inlined? So wouldn't these rules containing this inline need to be checked as well then? If rule a is comprised of a single rule b, and rule b is an inlined rule matching an optional, then rule a also becomes invalid since it can match an empty string.

@maxbrunsfeld
Copy link
Contributor

So wouldn't these rules containing this inline need to be checked as well then? If rule a is comprised of a single rule b, and rule b is an inlined rule matching an optional, then rule an also becomes invalid since it can match an empty string.

Yeah, I think you are right @amaanq. @rooney if we allow inline rules to match the empty string, we'll need additional logic to correctly check that other rules (which use inline rules) don't match the empty string due to inlined rules. Is the complexity worth it, or is the existing behavior fine?

@rooney
Copy link
Contributor Author

rooney commented Apr 3, 2024

Tokens (terminals) can't be inlined - the linked issue doesn't have an example, is this for the case where a rule is an optional (thus can match nothing) but is inlined?

Yes -- more specifically (in real-world scenario): some sequence of optionals that ultimately can match empty, that in turn be used as a common subrule by other (non empty-matching) rules.

So wouldn't these rules containing this inline need to be checked as well then? If rule a is comprised of a single rule b, and rule b is an inlined rule matching an optional, then rule an also becomes invalid since it can match an empty string.

Yeah, I think you are right @amaanq. @rooney if we allow inline rules to match the empty string, we'll need additional logic to correctly check that other rules (which use inline rules) don't match the empty string due to inlined rules. Is the complexity worth it, or is the existing behavior fine?

Right, ok, I'll try to find a way that handles the transitivity in a non-complex way.

Btw, current behavior (before this patch) can actually match empty string just fine, e.g:

  rules: {
    source_file: ($) => seq("foo", $.blank, "bar"),
    blank: () => "",
  },
image

(not sure if this is intentional or not)

@rooney rooney marked this pull request as draft April 14, 2024 11:30
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

Successfully merging this pull request may close these issues.

Is there a particular reason why inlining happens _after_ checking?
3 participants