Question

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).

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 https://github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/syntaxcoloring/DefaultHighlightingConfiguration.java). 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.

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 https://github.com/eclipse/xtext/blob/87a6c7dc25074ca4ff28429c059e728ef420b926/plugins/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/ui/contentassist/XtextProposalProvider.java) 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:

@Override
 protected StyledString getKeywordDisplayString(Keyword keyword) {
    return stylerFactory.createFromXtextStyle(keyword.getValue(),
            defaultLexicalHighlightingConfiguration.keywordTextStyle());
}

Here is my full NuSMVProposalProvider.xtend:

/*
 * 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());
    }

}

However, the next errors appeared:

  1. "The annotation @Override is disallowed for this location."
  2. "extraneous input 'keyword' expecting ')'"
  3. "mismatched input '{' expecting '=>'" in the first 3 lines, respectively.

My questions are:

  1. What exactly should I do with my class that implements IHighlightingConfiguration?
  2. What is Lexical and Semantic highlighing?
  3. Is there something else I need to know for my syntax coloring to work?

Thanks a lot!! :) Chai

Was it helpful?

Solution

NuSMVProposalProvider wasn't the way to go. I didn't have to add any code there at all. What I was looking for was adding the next lines in NuSMVUiModule.java:

public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration () {
     return DefaultHighlightingConfiguration.class;
}

Thanks everyone for their comments! Chai

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top