add more keywords to python #2

Closed
BrianHung wants to merge 1 commit from patch-1 into main
BrianHung commented 2021-07-12 02:18:57 +02:00 (Migrated from github.com)
Commit adds more keywords, specifically python built-ins. https://github.com/codemirror/CodeMirror/blob/master/mode/python/python.js https://docs.python.org/3/library/functions.html https://docs.python.org/3/library/constants.html
marijnh commented 2021-07-12 16:06:51 +02:00 (Migrated from github.com)

Built-in functions aren't keywords, and shouldn't be highlighted as such. In any case, this change will not do anything since it makes the highlighting target syntax nodes that don't exist.

Built-in functions aren't keywords, and shouldn't be highlighted as such. In any case, this change will not do anything since it makes the highlighting target syntax nodes that don't exist.
BrianHung commented 2021-07-12 20:28:49 +02:00 (Migrated from github.com)

Does that mean to syntax highlight python built-ins, it would require both a change to grammers in lezer python and a new tag for built-ins in codemirror?

Does that mean to syntax highlight python built-ins, it would require both a change to [grammers in lezer python](https://github.com/lezer-parser/python/blob/master/src/python.grammar) and a new [tag](https://codemirror.net/6/docs/ref/#highlight.tags) for built-ins in codemirror?
marijnh commented 2021-07-20 13:53:46 +02:00 (Migrated from github.com)

There is a tag modifier called standard that is intended to be used for builtins. But yes, you do need cooperation from the grammar to parse them, and doing so reliably may not even be possible on the syntax level (many languages allow you to shadow standard globals, for example, or make them contextual in other ways).

There are some half-baked plans for adding scope tracking support to the highlighting system, and it might be reasonable to integrate some way to highlight standard identifiers with that, but for the moment there's no solid (or even easy) way to do this.

There is a tag modifier called [`standard`](https://codemirror.net/6/docs/ref/#highlight.tags.standard) that is intended to be used for builtins. But yes, you do need cooperation from the grammar to parse them, and doing so reliably may not even be possible on the syntax level (many languages allow you to shadow standard globals, for example, or make them contextual in other ways). There are some half-baked plans for adding scope tracking support to the highlighting system, and it might be reasonable to integrate some way to highlight standard identifiers with that, but for the moment there's no solid (or even easy) way to do this.
Dazaer commented 2023-07-25 19:02:49 +02:00 (Migrated from github.com)

@marijnh Is there a way to achieve highlighting for python built-in functions currently? All the links to tags are no longer valid, as that's something that was removed I assume.

@marijnh Is there a way to achieve highlighting for python built-in functions currently? All the links to tags are no longer valid, as that's something that was removed I assume.
marijnh commented 2023-07-25 21:56:26 +02:00 (Migrated from github.com)

Is there a way to achieve highlighting for python built-in functions currently?

No, there isn't, without forking the Python parser.

> Is there a way to achieve highlighting for python built-in functions currently? No, there isn't, without forking the Python parser.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/lang-python!2
No description provided.