/* * Created on May 14, 2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package CDBuilder.couplingSyntaxEditor; import java.util.ArrayList; import java.util.List; import org.eclipse.jface.text.TextAttribute; 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.RuleBasedScanner; import org.eclipse.jface.text.rules.SingleLineRule; import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.rules.WordRule; /** *Sets all the rules for comments, strings, tags and text *Creates the tokens for returning when finding different syntax * *@author Sherwin Sim and Lucie Zhao *@version 1 May - August 2003 * */ public class cseScanner extends RuleBasedScanner { /** all the keywords (tags) */ private static String[] fgKeyword= {"components","in", "out", "Link" }; /** the starting tag, must be wrapped around in [] */ private static String fgStart = "top"; /** a separating tag */ private static String fgOther = "@"; /** * Sets the rules and tokens and match them up * There are rules for comments, containers, variables, strings * and character constants * @param manager the manager that sets the syntax colour based on these rules */ public cseScanner(ColorManager manager) { //initialize all the tokens with the different colours IToken keyword= new Token(new TextAttribute(manager.getColor(ICDColorConstants.KEYWORD))); IToken string= new Token(new TextAttribute(manager.getColor(ICDColorConstants.DEFAULT))); IToken comment= new Token(new TextAttribute(manager.getColor(ICDColorConstants.COMMENT))); IToken variable= new Token(new TextAttribute(manager.getColor(ICDColorConstants.VARIABLE))); IToken container =new Token(new TextAttribute(manager.getColor(ICDColorConstants.CONTAINER))); //make a list of rules List rules= new ArrayList(); // Add rule for single line comments. rules.add(new EndOfLineRule("%", comment)); //$NON-NLS-1$ // Add rule for containers rules.add(new SingleLineRule("[", "]", container)); //add rule for variables, anything after : rules.add(new EndOfLineRule(":", variable)); // Add rule for strings and character constants. rules.add(new SingleLineRule("\"", "\"", string, '\\')); rules.add(new SingleLineRule("'", "'", string, '\\')); //make a new word rule WordRule wordRule= new WordRule(new cseWordDetector(), variable); //add top and the rest of the key words to the wordrule wordRule.addWord(fgStart, container); for (int i= 0; i < fgKeyword.length; i++) { wordRule.addWord(fgKeyword[i], keyword); } wordRule.addWord(fgOther, keyword); rules.add(wordRule); //set the rules IRule[] result= new IRule[rules.size()]; rules.toArray(result); setRules(result); } }