title: Syntax coloring my DSL in Xtext
body: <p>I'm doing a small academic assignment, in which I'm supposed to implement an eclipse plugin for the NuSMV language (a model checking language) using Xtext. The xtext grammar was provided (with some minor bugs).
  I've created an Xtext project and called it "smv.project" with language name of "NuSMV" and extension of "*.smv". I've coppied the provided Xtext grammar into smv.project/src/NuSMV.xtext, generated artifacts, and created runtime eclipse. Seems to work fine except those minor bugs (which are originated in the grammar in my opinion).</p>
  
  <p>Now, my next step is to change the default colors in my DSL. Obviously, every user can do that for himself in the eclipse menus when using my plugin, but I wand the DEFAULT color to change. I've read the Xtext documentation for syntax coloring. It was short and had many terms I didn't understand. What I did understand is that there are 2 kinds of syntax coloring in Xtext, Lexical and Semantic. I didn't understand the meaning of each but it seemed to me that Lexical coloring is simpler, so I went for it.
  The documentation said that I should implement the interface IHighlightingConfiguration. It showed an example of implementation called DefaultHighlightingConfiguration (full source can be seen here <a href="https://github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/syntaxcoloring/DefaultHighlightingConfiguration.java" rel="nofollow">https://github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/syntaxcoloring/DefaultHighlightingConfiguration.java</a>). I've coppied this implementation into my project, to smv.project.ui/src/smv.project.ui.editor.syntaxcoloring. Of course, I changed the "package" line in the beginning of the file.
  I've changed all red values to 255 to see difference.
  I've generated the artifacts again, created runtime eclipse, created a *.smv file but the colors were the same.</p>
  
  <p>My guess was that I need to set my new class in some variable or configuration class... I tried searching for "DefaultHighlightingConfiguration" in the example's repository and found out that it's used in the file XtextProposalProvider.java (full source <a href="https://github.com/eclipse/xtext/blob/87a6c7dc25074ca4ff28429c059e728ef420b926/plugins/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/ui/contentassist/XtextProposalProvider.java" rel="nofollow">https://github.com/eclipse/xtext/blob/87a6c7dc25074ca4ff28429c059e728ef420b926/plugins/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/ui/contentassist/XtextProposalProvider.java</a>) in line 235 - We're overriding getKeywordDisplayString(). So I've went to the already existing NuSMVProposalProvider.java in my repository and tried to add the same lines:</p>
  
  <pre><code>@Override
   protected StyledString getKeywordDisplayString(Keyword keyword) {
      return stylerFactory.createFromXtextStyle(keyword.getValue(),
              defaultLexicalHighlightingConfiguration.keywordTextStyle());
  }
  </code></pre>
  
  <p>Here is my full NuSMVProposalProvider.xtend:</p>
  
  <pre><code>/*
   * generated by Xtext
   */
  package smv.project.ui.contentassist
  
  import smv.project.ui.contentassist.AbstractNuSMVProposalProvider
  import javax.inject.Inject
  import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration
  import org.eclipse.jface.viewers.StyledString
  import org.eclipse.xtext.Keyword
  
  /**
   * see http://www.eclipse.org/Xtext/documentation.html#contentAssist on how to customize content assistant
   */
  class NuSMVProposalProvider extends AbstractNuSMVProposalProvider {
  
      @Inject
      private DefaultHighlightingConfiguration defaultLexicalHighlightingConfiguration;
  
      @Override
       protected StyledString getKeywordDisplayString(Keyword keyword) {
          return stylerFactory.createFromXtextStyle(keyword.getValue(),
                  defaultLexicalHighlightingConfiguration.keywordTextStyle());
      }
  
  }
  </code></pre>
  
  <p>However, the next errors appeared:</p>
  
  <ol>
  <li>"The annotation @Override is disallowed for this location."</li>
  <li>"extraneous input 'keyword' expecting ')'"</li>
  <li>"mismatched input '{' expecting '=>'"
  in the first 3 lines, respectively.</li>
  </ol>
  
  <p>My questions are:</p>
  
  <ol>
  <li>What exactly should I do with my class that implements
  IHighlightingConfiguration? </li>
  <li>What is Lexical and Semantic highlighing?</li>
  <li>Is there something else I need to know for my syntax coloring to work?</li>
  </ol>
  
  <p>Thanks a lot!! :)
  Chai</p>