Skip to content

Handle mixed spaces and tabs. #234

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

Merged
merged 2 commits into from
Dec 17, 2018

Conversation

johndaniels
Copy link
Contributor

This allows the parser to handle tabs and spaces. Currently it
requires that spaces come after any tabs, which is slightly more
strict than python3. It also requires that neighboring indentation
levels have either both more spaces and tabs or less spaces and
tabs so that tab size can't make perception of indentation
differ from what the parser interprets.

I didn't opt to implement PartialOrd on IndentationLevel because I
wasn't sure that the comparison logic would meet the logical
requirements for that trait. One could easily switch to having it
implement PartialOrd though. This would necessitate switching to
manually implementing PartialEq so that it's behavior 'matches'.
It's unclear from the docs what 'matches' exactly means so for
now I'm avoiding implementing the traits.

This allows the parser to handle tabs and spaces. Currently it
requires that spaces come after any tabs, which is slightly more
strict than python3. It also requires that neighboring indentation
levels have either both more spaces and tabs or less spaces and
tabs so that tab size can't make perception of indentation
differ from what the parser interprets.

I didn't opt to implement PartialOrd on IndentationLevel because I
wasn't sure that the comparison logic would meet the logical
requirements for that trait. One could easily switch to having it
implement PartialOrd though. This would necessitate switching to
manually implementing PartialEq so that it's behavior 'matches'.
It's unclear from the docs what 'matches' exactly means so for
now I'm avoiding implementing the traits.
@johndaniels
Copy link
Contributor Author

This is a first pass. Not sure if it's the best behavior or the best way to implement the logic but it does handle some of the cases of tab usage.

@johndaniels
Copy link
Contributor Author

johndaniels commented Dec 16, 2018

The neighboring spaces needing strictly more spaces and tabs or less spaces and tabs is a Python 3 thing, but it looks like Python 3 allows reordering where those spaces are. I think it would be pretty easy to switch to that behavior, but it actually breaks the avowed goal of not having indentation dependent on the size of a tab (because tabs tend to fill in toward a multiple).

For example, python 3 considers space space space tab space space tab the same as space space space space space tab tab, but at a tab width of 4 those look different.

@johndaniels
Copy link
Contributor Author

Sorry, forgot rustfmt again...

@windelbouwman
Copy link
Contributor

Nice job!

@windelbouwman windelbouwman merged commit 8aaadb1 into RustPython:master Dec 17, 2018
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.

2 participants