Skip to content

Fix python call syntax highlighting#1987

Open
pencels wants to merge 3 commits into
rouge-ruby:mainfrom
pencels:python-call-hl
Open

Fix python call syntax highlighting#1987
pencels wants to merge 3 commits into
rouge-ruby:mainfrom
pencels:python-call-hl

Conversation

@pencels

@pencels pencels commented Aug 20, 2023

Copy link
Copy Markdown

Summary

Fixes an issue with the Python lexer where any identifier used before an opening paren ( would be highlighted as a function name. This led to inconsistent highlighting in the case of for loops, where one for would be rendered as a keyword while the other was rendered as a function name:

image

This pull request also addresses other edge cases for call expressions:

  • distinguishes Exception classes from normal classes in a call expr context
  • distinguishes Builtin calls from identically named method calls

Visual Before and After

Before After
Screenshot 2023-08-20 132415 Screenshot 2023-08-20 132000

@tancnle
tancnle self-requested a review August 25, 2023 00:56
@tancnle tancnle added the needs-review The PR needs to be reviewed label Aug 25, 2023
@jneen

jneen commented Feb 25, 2026

Copy link
Copy Markdown
Member

@tancnle I've rebased this (had some conflicts) but it seems to have broken match/case. Would you mind taking a look?

@tancnle

tancnle commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

@jneen I have rebased and resolved the conflicts. Could you please have another look?

Screenshot 2026-07-08 at 8 39 42 am

@tancnle

tancnle commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

@jneen Good catch. I think the included example does not demonstrate the changes introduced by this branch correctly (item 2, 4). Also, I have noted that the changes have introduced some regressions (item 1, 3, 5).

No Code Old (main) New (this branch) Expected (need to fix)
1 raise ValueError("bad") Name.Exception:"ValueError" Name.Builtin:"ValueError" Name.Exception:"ValueError"
2 raise MyCustomError("bad") Name:"MyCustomError" Name.Class:"MyCustomError" Name.Class:"MyCustomError"
3 err = ValueError Name.Exception:"ValueError" Name.Builtin:"ValueError" Name.Exception:"ValueError"
4 foo() Name:"foo" Name.Function:"foo" Name.Function:"foo"
5 self.list Name:"list" Name.Builtin:"list" Name:"list"

@jneen

jneen commented Jul 12, 2026

Copy link
Copy Markdown
Member

Hey Tan, Can you explain in your own words the meaning of this table and how you constructed it? To which changes are you referring? Which revisions are you referring to with "new" and "old"? The code on main is significantly newer than the code in this repository.

@tancnle

tancnle commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

@jneen I ran each of test example with rougify to compile the table.

echo "self.list" | ./bin/rougify -l python -f null
Name "self"
Punctuation "."
Name "list"
Text "\n"

Which revisions are you referring to with "new" and "old"?

To which changes are you referring?

Apology I could be more specific. I will need to submit another patch to point out the problematic parts.

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

Labels

needs-review The PR needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants