Bug 424301 - Syntax highlighting for keywords and literals (including strings)
Summary: Syntax highlighting for keywords and literals (including strings)
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Recommenders.incubator (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Stefan Prisca CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2013-12-18 03:26 EST by Stefan Prisca CLA
Modified: 2019-07-24 14:36 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Prisca CLA 2013-12-18 03:26:46 EST
Quoting Andreas:
Keywords should be highlighted in
keyword-color when in a keyword position and highlighted in identified
color when in an identifier position:

${int:import(java.lang.Integer)}

Ideally, int would not be highlighted as keyword, but as identifier.But
this might be a bit trickier, as the token is certainly the keyword
"int"; only the grammar rule that applies is something like
IdentifierOrKeyword. But AFAIK Xtext has a two-phase syntax colorer; on
that quickly colors based on token-type alone and one that re-colors
based on grammer-rule/AST-node-type.
Comment 1 Andreas Sewe CLA 2014-06-04 12:57:06 EDT
Here are some more cases which are not covered by the current implementation (patch set 6 of <https://git.eclipse.org/r/#/c/27862/>):

  int[] array; // "array" is highlighted but should not be
  Object var = null; // "var" is highlighted but should not be

I think the grammar needs to treat template language keywords outside their ${...} context just as it treats Java keywords inside the ${...}.
Comment 2 Stefan Prisca CLA 2014-06-04 14:25:19 EDT
Ok. I have a question about this.

For example, in the case of 

int[] array;

the word array will be treated as an JavaIdentifier. The same goes for var. Nothing outside the template variables is treated as a template language keyword.(the grammar does not allow it).

My question is: do we want JavaIdentifiers highlighted or not? And if we don't, what exactly is the point of the JavaIdentifier grammar rule? Is is really necessary?
Comment 3 Andreas Sewe CLA 2014-06-05 03:07:54 EDT
(In reply to Stefan Prisca from comment #2)
> Ok. I have a question about this.
> 
> For example, in the case of 
> 
> int[] array;
> 
> the word array will be treated as an JavaIdentifier. The same goes for var.
> Nothing outside the template variables is treated as a template language
> keyword.(the grammar does not allow it).
> 
> My question is: do we want JavaIdentifiers highlighted or not?

I don't think we should highlight Java identifiers *by default*. We should, however, *be able* to distinguish when an identifier is used as a Java identifier and when an identifier is used as a template language identifier. Just like we should be able to distinguish between Java keywords and template language keywords.

That way the user can configure whether he wants to use the same or different highlight colors for Java and template language keywords (currently, both a purple) and whether to use different highlights for Java and template language identifiers (currently, both a not highlighted). In particular, using different colors for Java and template language keywords sounds like a real usability improvement to me.

Does this sound like a reasonable goal?
Comment 4 Stefan Prisca CLA 2014-06-05 04:57:19 EDT
Yes it does.
We can set the default token color using the DefaultAntlrTokenToAttributeIdMapper class.(See Lexical Highlighting from [1])

This will color the Java Identifiers with black (or with a java identifier text style which the user will then be able to change) by default at the token level. 
Which also means that we will not worry about JavaIdentifiers in the HighlightCalculator anymore.

What do you think?

[1]: http://www.eclipse.org/Xtext/documentation.html#highlighting
Comment 5 Stefan Prisca CLA 2014-06-07 08:46:09 EDT
Fixed with change <https://git.eclipse.org/r/#/c/27862/>

For further discussions about template keywords highlighting please refer to bug
<https://bugs.eclipse.org/bugs/show_bug.cgi?id=436902>