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

Add soft keywords #20370

Merged
merged 4 commits into from
May 26, 2020
Merged

Add soft keywords #20370

merged 4 commits into from
May 26, 2020

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented May 25, 2020

These are like keywords but they only work in context; they are not reserved except when there is an exact match.

This would enable things like match statements without reserving match (which would be bad for the re.match() function and probably lots of other places).

Automerge-Triggered-By: @gvanrossum

@gvanrossum
Copy link
Member Author

gvanrossum commented May 25, 2020

Looks like the failing tests all have to do with print statements.

    test_exceptions test_future test_grammar test_print
    test_source_encoding

(UPDATE:)
And that was just a lark anyway (not meant seriously).

It does make me wonder if we shouldn't have a way to state that (certain) soft keywords should only be considered when the next character is a space.

These are like keywords but they only work in context;
they are not reserved except when there is an exact match.

This would enable things like match statements.
@gvanrossum gvanrossum marked this pull request as ready for review May 25, 2020 23:40
@gvanrossum
Copy link
Member Author

Fixed an unfortunate interaction with the new D() macro calls. Deleted the print statement easter egg. Now ready for review. (How to test this other than by adding a print statement?)

@pablogsal
Copy link
Member

pablogsal commented May 26, 2020

How to test this other than by adding a print statement?

A weak test would be adding something like this that uses the double quotes in the grammar and checks that _PyPegen_expect_soft_keyword is generated in the source and that something with single quotes in the grammar does not include _PyPegen_expect_soft_keyword in the source.

@gvanrossum
Copy link
Member Author

gvanrossum commented May 26, 2020

Now with tests. I'd like to keep this as an easter egg, hence the skip issue label. No need to backport to 3.9 (unless you'd rather keep the source of Tools/peg_generator identical).

Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

I left one question

@miss-islington
Copy link
Contributor

@gvanrossum: Status check is done, and it's a success ✅ .

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

Successfully merging this pull request may close these issues.

5 participants