Package tool.editors.text

Source Code of tool.editors.text.ToolScanner

package tool.editors.text;

import java.awt.Font;

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.RuleBasedScanner;
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;

import tool.ToolProjectSupport;
import tool.editors.ColorManager;
import tool.editors.IToolColorConstants;

public class ToolScanner extends RuleBasedScanner {

  public ToolScanner(ColorManager manager) {
    IToken reservedWord =
      new Token(
        new TextAttribute(
          manager.getColor(IToolColorConstants.KEYWORD), null, Font.BOLD));
   
   
    IToken udsLibrary =
      new Token(
        new TextAttribute(
          manager.getColor(IToolColorConstants.UDS_LIBRARY), null, Font.BOLD | Font.ITALIC));
    IToken type =
      new Token(
          new TextAttribute(manager.getColor(IToolColorConstants.TYPE), null, Font.BOLD));
   
    IToken string =
      new Token(new TextAttribute(manager
        .getColor(IToolColorConstants.STRING)));
   
//    IToken comment =
//      new Token(new TextAttribute(manager
//        .getColor(IToolColorConstants.TOOL_COMMENT)));
   
    IToken operator =
      new Token(new TextAttribute(manager
        .getColor(IToolColorConstants.DEFAULT), null, Font.BOLD));
   
    IToken other =
      new Token(new TextAttribute(manager.getColor(IToolColorConstants.DEFAULT)));
   
    IRule[] rules = new IRule[4];
   
    // Add generic whitespace rule.
    rules[0] = new WhitespaceRule(new ToolWhitespaceDetector());
   
    // Add rule for strings and character constants.
    rules[1] = new SingleLineRule("'", "'", string, '\\');

    WordRule wordRule = new WordRule(new ToolWordDetector(), other, true);
    for (int i = 0; i < IToolWords.ToolReservedWords.length; i++)
      wordRule.addWord(IToolWords.ToolReservedWords[i], reservedWord);
    for (int i = 0; i < IToolWords.ToolScalarTypes.length; i++)
      wordRule.addWord(IToolWords.ToolScalarTypes[i], type);
    for (int i = 0; i < ToolProjectSupport.forteLibrariesList.length; i++)
      wordRule.addWord(ToolProjectSupport.forteLibrariesList[i], udsLibrary);
    for (int i = 0; i < IToolWords.ToolConstants.length; i++)
      wordRule.addWord(IToolWords.ToolConstants[i], reservedWord);
   
    WordRule opWordRule = new WordRule(new ToolOperatorDetector(), operator, true);
   
    rules[3] = wordRule;
    rules[2] = opWordRule;
   
    setRules(rules);
  }
}
TOP

Related Classes of tool.editors.text.ToolScanner

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.