Skip to content

Fixed a bug with trigraphs and digraphs#589

Open
5BNeumann wants to merge 1 commit into42school:masterfrom
5BNeumann:master
Open

Fixed a bug with trigraphs and digraphs#589
5BNeumann wants to merge 1 commit into42school:masterfrom
5BNeumann:master

Conversation

@5BNeumann
Copy link
Copy Markdown

norminette/rules/check_preprocessor_indent.py does: spaces = context.peek_token(i).line_column - hash_.line_column - 1 to count the spaces after the # (or the ??= trigraph/%: digraph). This is flawed since digraphs and trigraphs are more than one character long.
Instead, we should probably count spaces as such:

        n = context.skip_ws(i)
        spaces = 0
        while context.check_token(i, "SPACE"):
            i += 1
            spaces += 1
        if context.check_token(i, "TAB"):
            context.new_error("TAB_REPLACE_SPACE", context.peek_token(i))
        while context.check_token(i, "TAB"):
            i += 1
            spaces += 1
        i = n

Sadly, this does induces overhead in the introduction of the second while loop that accounts for tabs.

Verification Steps

Please ensure the following steps have been completed:

  • Added new tests to cover the changes.
  • Fixed all broken tests.
  • Ran poetry run flake8 to check for linting issues.
  • Verified that all unit tests are passing:
    • Ran poetry run pytest to ensure unit tests pass.
    • Ran poetry run tox to validate compatibility across Python versions.

norminette/rules/check_preprocessor_indent.py does:
`spaces = context.peek_token(i).line_column - hash_.line_column - 1`
to count the spaces after the `#` (or the `??=` trigraph/`%:` digraph).
This is flawed since digraphs and trigraphs are more than one character
long.
Instead, we should probably count spaces as such:
```py
        n = context.skip_ws(i)
        spaces = 0
        while context.check_token(i, "SPACE"):
            i += 1
            spaces += 1
        if context.check_token(i, "TAB"):
            context.new_error("TAB_REPLACE_SPACE", context.peek_token(i))
        while context.check_token(i, "TAB"):
            i += 1
            spaces += 1
        i = n
```
This does induces overhead in the introduction of the second while loop
that accounts for tabs.
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.

1 participant