Sadık
Sadık

Reputation: 4419

Add keywords that consist of two words to CDT

To have custom keywords for I do the following:

This works for "input" and "output", but not for "input port" or "output port". How can I have keyword highlighting for "port" but only in the combinations "input port" or "output port"?

Upvotes: 1

Views: 61

Answers (1)

HighCommander4
HighCommander4

Reputation: 52819

I can think of two options:

  1. Modify CDT's lexer to support keywords containing whitespace. I don't think this is something you can do using the public API, you'd have to modify core CDT classes like org.eclipse.cdt.internal.core.parser.scanner.Lexer. (Alternatively, you could consider upstreaming a patch to add such support to the lexer.)

  2. Use semantic highlighting to highlight your whitespace-containing keywords. There's an org.eclipse.cdt.ui.semanticHighlighting extension point that allows plugins to provide custom semantic highlighting.

The difference in the user experience would be that lexical highlighting is applied immediately after every keystroke, while semantic highlighting is applied after a short delay after typing stops (since it's more expensive to compute). You can see this effect if you compare how the override and final keywords are currently highlighted in C++, compared to other keywords: override and final use semantic highlighting because they're context-sensitive keywords.

I should also mention that whether the second approach works, depends on how your new keywords fit into the grammar. They need to be parsed as IASTName in order for semantic highlighting to be applied to them.

Upvotes: 1

Related Questions