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

python.gram Rust/C++/Borgo compatible match syntax: parse without delimiters #107

Open
adsharma opened this issue Dec 12, 2024 · 1 comment

Comments

@adsharma
Copy link

Test case
Modified Grammar

If I remove the endpmatch delimiter from both the test case and the grammar, we fail to parse.
I've tried running parser.py -vv test3.py and tried to understand why it fails. But it isn't entirely clear.

Is there a solution to this problem such as:

  • Reordering rules
  • Add more invalid_foo rules

I would really like to avoid using endpmatch.

@adsharma
Copy link
Author

adsharma commented Dec 14, 2024

Replacing endpmatch with a semicolon works. However, I'd like to avoid these delimiters in the interest of keeping things clean.

Here's the fundamental issue:

def foo():
    a = 10
    return a

works fine. However,

def foo():
    a = pmatch ...
    return a

fails to parse because there is a DEDENT at the end of match_expr, which eats up multiple indentations and multiple newlines.

So after parsing a = pmatch ... as a simple_stmt or a statement, the parser is not able to proceed to consume return a as another statement.

How can I change the grammar so that INDENT means newline + n spaces and DEDENT means newline - n spaces? In this example n=4.

If it's not possible because this is baked deeply into python grammar, I could give up and accept the least intrusive delimiter and move on.

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

1 participant