-
Notifications
You must be signed in to change notification settings - Fork 251
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
[RFC] How to highlight Cpp2 #459
Comments
Thanks.
It would be really nice. Currently I use |
I chose to not highlight discouraged spellings of fundamental types. Here's a glimpse as to why: Lines 251 to 269 in ebe5ebc
I made an exception for This does means that |
I found the criteria at github-linguist/linguist's
|
For purposes of linguistic (to highlight Cpp2 in GitHub code blocks),
or the relaxed
It seems there are 536 unique |
Title: [RFC] How to highlight Cpp2.
Description:
After #429,
I've written another Cpp2 parser at compiler-explorer/compiler-explorer#5061
to highlight code in the editor used by Compiler Explorer.
I've adopted the existing highlighting as-is.
I also took the opportunity to highlight type-only contexts.
I'd like to know
your opinions on my choices
and what you think can be improved.
Please, be aware that
there is science behind using color to represent information.
Color overload can also be detrimental.
So I'd prefer baby-step improvements
to a scheme that isn't demonstrated to benefit the Cpp2 programmer.
For reference, here is the one of two highlighters in the wiki that has a screenshot:
https://github.com/elazarcoh/cpp2-syntax/blob/master/resources/syntax-highligh-example.png.
Preview:
In terms of what Cpp1 and Cpp2 have in common,
the only difference in highlighting is that
Cpp2 highlights declarations and type-only contexts.
The default sample code.
int
receives no special treatment._
is a bit hard to see.As an anonymous declaration, deduced type, and placeholder, it is highlighted like a keyword.
As a non-anonymous declaration (a parameter) and use of an identifier (none of the others),
it is highlighted like any other declaration and use.
Benefit of contextual type highlighting.
Know at a glance that something might be wrong.
A type nested in a template.
The instantiated template can only be a type.
Metafunctions.
See what Herb said at commit d8c1a50:
Metafunction quote:
The default highlighting makes it all white.
Consistent with the provisions above (meta, science),
suggestions welcome.
A type declaration.
TBD Bold font for overloaded operator declaration consistent with other declarations.
Inspect.
jump-statement.
Iteration statements.
Contracts.
Uses-it-all declaration.
The example from https://github.com/hsutter/cppfront/wiki/Design-note%3A-Postfix-operators.
Anonymous return type.
Contextual highlighting of an identifier named after a parameter direction.
Special identifiers.
Chained comparisons.
Consistency with Cpp1.
Monaco's C++ isn't ready for C++23's
assume
attribute.Q&A:
Comment: Highlighting types in type-only contexts is color overload/unscientific.
Reason: I used Monarch's built-in
type
(CSS class for a token), so I hope it isn't.Comment: Highlighting types is inconsistent with Cpp1.
Reason:
Monaco's C++ and all language definitions at CE
don't parse the language, but rather
use rules to decide how to highlight the code.
This means, as seen in the preview,
that there's less chance for contextually correct highlighting.
E.g., in Cpp1,
final
is always highlighted as a keyword.Cpp2 has a greater set of contextual keywords,
and is simpler to parse.
So I took the chance to actually write a parser for it
and use contextual knowledge for correct highlighting.
What I want to do next:
```Cpp2
code blocks.The text was updated successfully, but these errors were encountered: