package eu.modelwriter.specification.editor.scanner;

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

import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWhitespaceDetector;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;

import eu.modelwriter.specification.editor.RGBStorage;

public class FactScanner extends RuleBasedScanner {

  public static final String[] keywords =
      new String[] {"fact", "none", "univ", "iden", "this", "not", "no", "lone", "some", "one",
          "set", "or", "and", "iff", "implies", "in", "else", "let", "all", "sum", "disj"};

  public FactScanner() {
    final IToken keywordToken =
        new Token(new TextAttribute(new Color(Display.getCurrent(), RGBStorage.KEYWORD_RGB)));
    final IToken defaultToken =
        new Token(new TextAttribute(new Color(Display.getCurrent(), RGBStorage.DEFAULT_RGB)));

    final List<IRule> rules = new ArrayList<IRule>();

    // whitespace rule for skipping whitespaces.
    rules.add(new WhitespaceRule(new IWhitespaceDetector() {

      @Override
      public boolean isWhitespace(final char c) {
        return Character.isWhitespace(c);
      }
    }));

    final WordRule keywordRule = new WordRule(new IWordDetector() {

      @Override
      public boolean isWordPart(final char c) {
        return Character.isLetter(c);
      }

      @Override
      public boolean isWordStart(final char c) {
        return Character.isLetter(c);
      }
    }, defaultToken);

    // add all keywords to keyword rule for keyword matching.
    for (int i = 0; i < FactScanner.keywords.length; i++) {
      keywordRule.addWord(FactScanner.keywords[i], keywordToken);
    }
    rules.add(keywordRule);

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

@@ -144,16 +144,67 @@
 ribute;%0A
+import org.eclipse.jface.text.rules.EndOfLineRule;%0A
 import o
@@ -234,24 +234,24 @@
 ules.IRule;%0A
-
 import org.e
@@ -382,32 +382,83 @@
 .IWordDetector;%0A
+import org.eclipse.jface.text.rules.MultiLineRule;%0A
 import org.eclip
@@ -1334,16 +1334,143 @@
 _RGB)));
+%0A    final IToken commentToken =%0A        new Token(new TextAttribute(new Color(Display.getCurrent(), RGBStorage.COMMENT_RGB)));
 %0A%0A    fi
@@ -2290,16 +2290,184 @@
 rdRule);
+%0A    rules.add(new EndOfLineRule(%22--%22, commentToken));%0A    rules.add(new EndOfLineRule(%22//%22, commentToken));%0A    rules.add(new MultiLineRule(%22/*%22, %22*/%22, commentToken));
 %0A%0A    fi
@@ -2543,17 +2543,12 @@
 t);%0A
+
     
-this.
 setR

Comment rules for fact partition