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

Reduce if statements for always-succeed cases #577

Open
hildjj opened this issue Nov 25, 2024 · 3 comments
Open

Reduce if statements for always-succeed cases #577

hildjj opened this issue Nov 25, 2024 · 3 comments

Comments

@hildjj
Copy link
Contributor

hildjj commented Nov 25, 2024

If a rule always succeeds, the code that calls that rule does not need to check the result of its parse function. The else from that check is difficult to test without resorting to tricks.

@hildjj
Copy link
Contributor Author

hildjj commented Nov 25, 2024

This is separate, but potentially related to #576.

@Mingun
Copy link
Member

Mingun commented Nov 26, 2024

This is already should be implemented, inference-match-result pass does the job. You found an example where something else can be removed?

@hildjj
Copy link
Contributor Author

hildjj commented Nov 26, 2024

Here is a cut-down example:

Foo
  = either " "

either
  = "."
  / [a-z]*

which has this in the output js:

  function peg$parseFoo() {
    var s0, s1, s2;

    s0 = peg$currPos;
    s1 = peg$parseeither();
    if (s1 !== peg$FAILED) {
...

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

2 participants