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

[D] Add highlighting for recognised __traits/pragmas #3963

Merged
merged 3 commits into from
May 4, 2024

Conversation

ichordev
Copy link
Contributor

Changes:

  • Valid __traits are highlighted with constant.other.d.
  • Invalid __traits now trigger invalid.illegal.d, because they cause compile errors.
  • Highlight known pragmas with constant.other.d. Invalid pragmas are not meant to cause compile errors in D (currently they do, but it's being fixed), so they do NOT trigger invalid.illegal.d.

Copy link
Collaborator

@deathaxe deathaxe left a comment

Choose a reason for hiding this comment

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

A certain identifier not being supported by a compiler (causing compiler errors) may not directly be equal to invalid syntax.

In general being too over-eager may be annyoing to end users due to seeeing tons of red (illegal highlighted) code all the time while editing code.

That's however too late to question for D anyway though.

D/D.sublime-syntax Outdated Show resolved Hide resolved
D/D.sublime-syntax Outdated Show resolved Hide resolved
@ichordev
Copy link
Contributor Author

A certain identifier not being supported by a compiler (causing compiler errors) may not directly be equal to invalid syntax.

Valid __traits are specified in D's grammar. The reference compiler (DMD) gives you an error, so LDC and GDC will both give you an error too because they use the same backend. As far as I know, this is intentional behaviour.

Like I noted, unrecognised pragmas are not supposed to cause errors because implementation-specific pragmas are provided for by the spec, and so they don't trigger invalid syntax highlighting here. Instead, unrecognised pragmas just don't get special highlighting so that you can see that something is wrong (i.e. you probably made a typo).

@deathaxe
Copy link
Collaborator

A synatx definition should highlight tokens and ideally handle incomplete token/statements in sane ways to create the impression of it already knowing what's up next.

It is not necessarily required to do a linter's job. Even though the compiler isn't happy with a certain token, currently, support for new ones may be added at any time. So unsupported pragmas are not a syntax error. The compiler's parser would also read the full token, but just throw an error at a later point, as it doesn't know it.

@ichordev
Copy link
Contributor Author

So unsupported pragmas are not a syntax error. The compiler's parser would also read the full token, but just throw an error at a later point, as it doesn't know it.

Yes, pragmas are designed to accommodate compiler-specific identifiers, so my PR already accounts for the fact that their identifiers are arbitrary by just ignoring unrecognised identifiers.

Traits, on the other hand, are defined as an exhaustive list of keywords. A traits expression, by definition, must use one of these keywords. Yes, new keywords may be added, but the same holds for every other aspect of the language's syntax.

@ichordev ichordev closed this May 2, 2024
@FichteFoll FichteFoll reopened this May 4, 2024
@deathaxe deathaxe merged commit 06e513e into sublimehq:master May 4, 2024
4 checks passed
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.

3 participants