I'm making a syntax highlighting plugin for my company. I'm not making a new editor, I am using an eclipse template that uses the Extensions for generic editor. 

*Disclaimer: I've had a lot of trouble getting XText to work consistently on 3 different machines due to versioning issues, missing files etc. so that's out of the question*

```
org.eclipse.ui.genericeditor.presentationReconcilers
org.eclipse.ui.genericeditor.contentTypes
org.eclipse.ui.genericeditor.hoverProviders
org.eclipse.ui.genericeditor.contentAssistProcessors
org.eclipse.ui.editors
org.eclipse.core.filebuffers.documentSetup

```

I'm using I'm having some odd issues. Before I get started:

* The plugin is detected in Help > About Eclipse > Installation Details > Plugins 
Other sample plugins run using the same method i used to run this plugin

**Problems:**

* I'm getting the following error message when placing any content in
the file except `<?xml version='1.0'>`: 

> 
> "Content is not allowed in Prolog"
> 
> 
>
* The keywords seem to be highlighted in Blue. As you can see in my
source code, they should be highlighted in red.

[Click here](https://i.stack.imgur.com/QCCho.png)  to view what my runtime Eclipe editor looks like
when i'm trying to test my syntax rules.

Below are my classes source code.
I'm wondering:

1. why my keywords are being recognized in syntax coloring but are
 invalid commands with that "*prolog*" error above
2. Why the prolog errors above are occurring
3. Why it's validating the file not to my specification or to a different specification
4. Point me in the right direction

Hope you can help.
Thanks :).

Reconciler Class:

```
package myplugin;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;

public class MyReconciler extends PresentationReconciler {

    public MyReconciler() {
        // TODO this is logic for .project file to color tags in blue. Replace with your language logic!
        MyScanner scanner = new MyScanner(new SyntaxColorProvider());

        DefaultDamagerRepairer dr= new DefaultDamagerRepairer(scanner);
        this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
        this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
    }
}

```

Scanner class:

```
package myplugin;

import java.util.ArrayList; 
import java.util.List; 

import org.eclipse.jface.text.TextAttribute; 
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; 
import org.eclipse.jface.text.rules.EndOfLineRule; 
import org.eclipse.jface.text.rules.IRule; 
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.MultiLineRule;
import org.eclipse.jface.text.rules.PatternRule; 
import org.eclipse.jface.text.rules.SingleLineRule; 
import org.eclipse.jface.text.rules.Token; 
import org.eclipse.jface.text.rules.WhitespaceRule; 
import org.eclipse.jface.text.rules.WordRule; 

public class MyScanner extends BufferedRuleBasedScanner 
{ 

private static String[] misc = {
     true",
    "false", 
    "unsigned",
    "jump",
    "read",     
    "write",
};

// Tokens
private final IToken KEYWORD_TOKEN;

private List<IRule> basicRules;

public MyScanner(SyntaxColorProvider colorProvider)
{
    super(5000);

    // CREATE TOKENS
    KEYWORD_TOKEN = new Token(new TextAttribute(colorProvider.getColor(SyntaxColorProvider.KEYWORD)));

    // CREATE RULES
    List rules = new ArrayList<IRule>();

    // Add rule for strings and character constants.
    rules.add(new SingleLineRule("\"", "\"", STRING_TOKEN, '\\'));
    rules.add(new SingleLineRule("'", "'", STRING_TOKEN, '\\'));

    // Add word rule for keywords, types, and constants.
    WordRule wordRule = new WordRule(new WordDetector(), OTHER_TOKEN);

    // Single-line comments
    rules.add(new EndOfLineRule("//", STRING_TOKEN));

    // Multi-line comments
    rules.add(new MultiLineRule("/$", "$/", COMMENT_TOKEN));

    // KEYWORDS
    for (String misc : misc)
    {
        wordRule.addWord(misc, KEYWORD_TOKEN);
    }
    rules.add(wordRule);

    IRule[] result= new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}

```

}

ValidatorDocumentSetupParticipant:

```
package myplugin;

import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;

public class ValidatorDocumentSetupParticipant implements IDocumentSetupParticipant, IDocumentSetupParticipantExtension {

    private final class DocumentValidator implements IDocumentListener {
        private final IFile file;
        private IMarker marker;

        private DocumentValidator(IFile file) {
            this.file = file;
        }

        @Override
        public void documentChanged(DocumentEvent event) {
            if (this.marker != null) {
                try {
                    this.marker.delete();
                } catch (CoreException e) {
                    e.printStackTrace();
                }
                this.marker = null;
            }
            try (StringReader reader = new StringReader(event.getDocument().get());) {
                DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                documentBuilder.parse(new InputSource(reader));
            } catch (Exception ex) {
                try {
                    this.marker = file.createMarker(IMarker.PROBLEM);
                    this.marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                    this.marker.setAttribute(IMarker.MESSAGE, ex.getMessage());
                    if (ex instanceof SAXParseException) {
                        SAXParseException saxParseException = (SAXParseException)ex;
                        int lineNumber = saxParseException.getLineNumber();
                        int offset = event.getDocument().getLineInformation(lineNumber - 1).getOffset() + saxParseException.getColumnNumber() - 1;
                        this.marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
                        this.marker.setAttribute(IMarker.CHAR_START, offset);
                        this.marker.setAttribute(IMarker.CHAR_END, offset + 1);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void documentAboutToBeChanged(DocumentEvent event) {
        }
    }

    @Override
    public void setup(IDocument document) {
    }

    @Override
    public void setup(IDocument document, IPath location, LocationKind locationKind) {
        if (locationKind == LocationKind.IFILE) {
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(location);
            document.addDocumentListener(new DocumentValidator(file));
        }

```

WordDetector Class:

```
 package myplugin;

import org.eclipse.jface.text.rules.IWordDetector; 

public class WordDetector implements IWordDetector 
{    
    public boolean isWordPart(char character) {
        return Character.isJavaIdentifierPart(character);
    }

    public boolean isWordStart(char character) {
        return Character.isJavaIdentifierStart(character);
    }
}

```

SyntaxColorProvider Class:

```
package myplugin;

import java.util.HashMap; 

public class SyntaxColorProvider 
{ 

public static final RGB RED = new RGB(200, 0, 0); 

public static final RGB GREEN = new RGB(0, 200, 0); 

public static final RGB BLUE = new RGB(0, 0, 200); 

public static final RGB COMMENT = new RGB(128, 128, 128);  

public static final RGB KEYWORD = new RGB(255, 0, 0); 

public static final RGB TYPE = new RGB(0, 0, 128); 

public static final RGB STRING = new RGB(0, 128, 0); 

public static final RGB DEFAULT = new RGB(0, 0, 0); 

protected Map fColorTable = new HashMap(10); 

/**
 * Release all of the color resources held onto by the receiver. 
 */ 
public void dispose() 
{ 
    Iterator e = fColorTable.values().iterator(); 
    while (e.hasNext()) 
        ((Color) e.next()).dispose(); 
} 

/**
 * Return the Color that is stored in the Color table as rgb. 
 */ 
public Color getColor(RGB rgb) 
{ 
    Color color = (Color) fColorTable.get(rgb); 
    if (color == null) 
    { 
        color = new Color(Display.getCurrent(), rgb); 
        fColorTable.put(rgb, color); 
    } 
    return color; 
}

```