Java Code Examples for org.eclipse.jface.text.rules.WordRule#addWord()

The following examples show how to use org.eclipse.jface.text.rules.WordRule#addWord() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSDocScanner.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a new javadoc scanner for the given color provider.
 */
public JSDocScanner()
{
	super();

	List<IRule> list = new ArrayList<IRule>();

	// Add rule for tags.
	list.add(new SingleLineRule("<", ">", getToken("text.html.basic"))); //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-1$

	// Add rule for links.
	list.add(new SingleLineRule("{", "}", getToken("markup.underline.link"))); //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-1$

	// Add word rule for keywords.
	IToken keyword = getToken("meta.tag.documentation.js"); //$NON-NLS-1$
	WordRule wordRule = new WordRule(new JSDocWordDetector());
	for (String word : KEYWORDS)
	{
		wordRule.addWord(word, keyword);
	}
	list.add(wordRule);

	setDefaultReturnToken(getToken("comment.block.documentation.js")); //$NON-NLS-1$
	setRules(list.toArray(new IRule[list.size()]));
}
 
Example 2
Source File: CSSCodeScannerRuleBased.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * createScannerSpecificRules
 * 
 * @return
 */
protected Collection<? extends IRule> createScannerSpecificRules()
{
	List<IRule> rules = new ArrayList<IRule>();
	WordRule wordRule = new WordRule(new KeywordIdentifierDetector(), Token.UNDEFINED);
	wordRule.addWord("em", createToken(CSSTokenType.EMS));
	wordRule.addWord("ex", createToken(CSSTokenType.EXS));
	wordRule.addWord("px", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("cm", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("mm", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("in", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("pt", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("pc", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("deg", createToken(CSSTokenType.ANGLE));
	wordRule.addWord("rad", createToken(CSSTokenType.ANGLE));
	wordRule.addWord("grad", createToken(CSSTokenType.ANGLE));
	wordRule.addWord("ms", createToken(CSSTokenType.TIME));
	wordRule.addWord("s", createToken(CSSTokenType.TIME));
	wordRule.addWord("hz", createToken(CSSTokenType.FREQUENCY));
	wordRule.addWord("khz", createToken(CSSTokenType.FREQUENCY));
	wordRule.addWord("Hz", createToken(CSSTokenType.FREQUENCY));
	wordRule.addWord("kHz", createToken(CSSTokenType.FREQUENCY));
	addWordsToRule(wordRule, FUNCTIONS, CSSTokenType.FUNCTION);
	rules.add(wordRule);
	return rules;
}
 
Example 3
Source File: InstructionsRuleScanner.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
public InstructionsRuleScanner(ColorProvider provider) {
	IToken stringToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_STRING_COLOR))));
	IToken commentToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_COMMENT_COLOR))));
	IToken instructToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_INSTRUCT_COLOR)), null, Font.ITALIC));
	IToken definitionsToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_DEF_COLOR)), null, Font.ITALIC));

	List<IRule> rules = Lists.newArrayList();
	// rule for Strings - may spanning multiple lines
	rules.add(new MultiLineRule("\"", "\"", stringToken));
	rules.add(new MultiLineRule("\'", "\'", stringToken));
	rules.add(new EndOfLineRule("#%", instructToken));
	// rule for comments - ended by a line delimiter
	rules.add(new EndOfLineRule("//", commentToken));

	WordRule wordRule = RuleFactory.buildRule(ImpexRules.KEYWORD, null);		
	// rule for instructions
	for (String word : Formatter.INSTRUCTION_CLASS_PROPOSALS) {
		wordRule.addWord(word, instructToken);
	}

	rules.add(wordRule);

	// rule for definitions
	wordRule = RuleFactory.buildRule(ImpexRules.VARIABLE, definitionsToken);
	rules.add(wordRule);
	IRule[] ruleArray = new IRule[rules.size()];
	setRules(rules.toArray(ruleArray));
}
 
Example 4
Source File: JSPartitionScanner.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void addWords( WordRule rule, String[] tokens, IToken token )
{
	for ( int i = 0; i < tokens.length; i++ )
	{
		rule.addWord( tokens[i], token );
	}

}
 
Example 5
Source File: SyntaxHighlighter.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
protected void initialize(String[] keywords) {
    ColorRegistry registry = JFaceResources.getColorRegistry();

    IToken keyword = new Token(new TextAttribute(registry.get(KEYWORD_COLOR), null, SWT.BOLD));
    IToken string = new Token(new TextAttribute(registry.get(STRING_COLOR)));
    IToken number = new Token(new TextAttribute(registry.get(NUMBER_COLOR)));
    IToken annotation = new Token(new TextAttribute(registry.get(ANNOTATION_COLOR)));
    IToken defaultToken = new Token(new TextAttribute(registry.get(DEFAULT_COLOR)));

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

    // strings
    rules.add(new SingleLineRule("\"", "\"", string, '\\'));

    // annotations
    rules.add(new MultiLineRule("[", "]", annotation));

    // numbers
    rules.add(new NumberRule(number));

    // keywords and normal (default) text
    WordRule wordRule = new WordRule(new WordDetector(), defaultToken);
    for (int i = 0; i < keywords.length; i++) {
        wordRule.addWord(keywords[i], keyword);
    }
    rules.add(wordRule);

    setRules(rules.toArray(new IRule[rules.size()]));
}
 
Example 6
Source File: JavaDocScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected List<IRule> createRules() {

	List<IRule> list= new ArrayList<IRule>();

	// Add rule for tags
	Token token= getToken(IJavaColorConstants.JAVADOC_TAG);
	list.add(new TagRule(token));


	// Add rule for HTML comments
	WordRule wordRule= new WordRule(new HTMLCommentDetector(), token);
	wordRule.addWord("<!--", token); //$NON-NLS-1$
	wordRule.addWord("--!>", token); //$NON-NLS-1$
	list.add(wordRule);


	// Add rules for links
	token= getToken(IJavaColorConstants.JAVADOC_LINK);
	list.add(new MultiLineRule("{@link", "}", token)); //$NON-NLS-2$ //$NON-NLS-1$
	list.add(new MultiLineRule("{@value", "}", token)); //$NON-NLS-2$ //$NON-NLS-1$
	list.add(new MultiLineRule("{@inheritDoc", "}", token)); //$NON-NLS-2$ //$NON-NLS-1$

	// Add rules for @code and @literals
	token= getToken(IJavaColorConstants.JAVADOC_DEFAULT);
	list.add(new MultiLineRule("{@code", "}", token)); //$NON-NLS-2$ //$NON-NLS-1$
	list.add(new MultiLineRule("{@literal", "}", token)); //$NON-NLS-2$ //$NON-NLS-1$

	// Add generic whitespace rule
	token= getToken(IJavaColorConstants.JAVADOC_DEFAULT);
	list.add(new WhitespaceRule(new JavaWhitespaceDetector(), token));


	list.addAll(super.createRules());
	return list;
}
 
Example 7
Source File: CommentScanner.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected List<IRule> createRules()
{
	List<IRule> rules = new ArrayList<IRule>();
	WordRule wordRule = new WordRule(new WordDetector(), Token.UNDEFINED, !TaskTag.isCaseSensitive());
	IToken taskToken = new Token(TASK_TAG_SCOPE);
	for (TaskTag tag : TaskTag.getTaskTags())
	{
		wordRule.addWord(tag.getName(), taskToken);
	}
	rules.add(wordRule);
	return rules;
}
 
Example 8
Source File: HTMLDoctypeScanner.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public HTMLDoctypeScanner()
{
	List<IRule> rules = new ArrayList<IRule>();

	// Add rule for double quotes
	rules.add(new MultiLineRule(
			"\"", "\"", createToken("string.quoted.double.doctype.identifiers-and-DTDs.html"), '\\')); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

	// Add a rule for single quotes
	rules.add(new MultiLineRule(
			"'", "'", createToken("string.quoted.single.doctype.identifiers-and-DTDs.html"), '\\')); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

	// Add generic whitespace rule.
	rules.add(new WhitespaceRule(new WhitespaceDetector()));

	// Tags
	WordRule wordRule = new WordRule(new WordDetector(), createToken(StringUtil.EMPTY), true);
	wordRule.addWord("DOCTYPE", createToken("entity.name.tag.doctype.html")); //$NON-NLS-1$ //$NON-NLS-2$
	rules.add(wordRule);

	CharacterMapRule rule = new CharacterMapRule();
	rule.add('>', createToken(HTMLTokenType.TAG_END));
	rule.add('=', createToken(HTMLTokenType.EQUAL));
	rules.add(rule);
	// Tag start <(/)?
	rules.add(new TagStartRule(new TagStartWordDetector(), createToken(HTMLTokenType.TAG_START), false));

	setRules(rules.toArray(new IRule[rules.size()]));
	setDefaultReturnToken(createToken(StringUtil.EMPTY));
}
 
Example 9
Source File: CSSTokenScanner.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * createAtWordsRule
 * 
 * @return
 */
private WordRule createAtWordsRule()
{
	WordRule atRule = new WordRule(new IdentifierWithPrefixDetector('@'), createToken(CSSTokenType.AT_RULE), true);

	atRule.addWord("@import", createToken(CSSTokenType.IMPORT));
	atRule.addWord("@page", createToken(CSSTokenType.PAGE));
	atRule.addWord("@media", createToken(CSSTokenType.MEDIA_KEYWORD));
	atRule.addWord("@charset", createToken(CSSTokenType.CHARSET));
	atRule.addWord("@font-face", createToken(CSSTokenType.FONTFACE));
	atRule.addWord("@namespace", createToken(CSSTokenType.NAMESPACE));

	return atRule;
}
 
Example 10
Source File: CSSCodeScannerRuleBased.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * createAtWordsRule
 * 
 * @return
 */
protected WordRule createAtWordsRule()
{
	WordRule atRule = new WordRule(new IdentifierWithPrefixDetector('@'), createToken(CSSTokenType.AT_RULE));

	atRule.addWord("@import", createToken(CSSTokenType.IMPORT));
	atRule.addWord("@page", createToken(CSSTokenType.PAGE));
	atRule.addWord(KEYWORD_MEDIA, createToken(CSSTokenType.MEDIA_KEYWORD));
	atRule.addWord("@charset", createToken(CSSTokenType.CHARSET));
	atRule.addWord("@font-face", createToken(CSSTokenType.FONTFACE));
	atRule.addWord("@namespace", createToken(CSSTokenType.NAMESPACE));

	return atRule;
}
 
Example 11
Source File: CSSCodeScannerRuleBased.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * addWordsToRule
 * 
 * @param wordRule
 * @param words
 * @param tokenType
 */
private void addWordsToRule(WordRule wordRule, String[] words, CSSTokenType tokenType)
{
	IToken token = createToken(tokenType);

	for (String word : words)
	{
		wordRule.addWord(word, token);
	}
}
 
Example 12
Source File: TLACodeScanner.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Construct the rules
 */
public TLACodeScanner()
{
    TLAColorProvider provider = TLAEditorActivator.getDefault().getTLAColorProvider();

    IToken keyword = new Token(new TextAttribute(provider.getColor(TLAColorProvider.TLA_KEYWORD_KEY), null, SWT.BOLD));
    IToken value = new Token(new TextAttribute(provider.getColor(TLAColorProvider.TLA_VALUE_KEY)));
    IToken other = new Token(new TextAttribute(provider.getColor(TLAColorProvider.DEFAULT_TEXT_KEY)));

    List rules = new ArrayList();

    // Add generic whitespace rule.
    // rules.add(new WhitespaceRule(DocumentHelper.getDefaultWhitespaceDetector()));

    // Add word rule for standard words
    WordRule wordRule = new WordRule(DocumentHelper.getDefaultWordDetector(), other);
    
    // add values
    for (int i = 0; i < ITLAReserveredWords.ALL_VALUES_ARRAY.length; i++)
    {
        wordRule.addWord(ITLAReserveredWords.ALL_VALUES_ARRAY[i], value);
    }
    
    // add reserved words
    for (int i = 0; i < ITLAReserveredWords.ALL_WORDS_ARRAY.length; i++)
    {
        wordRule.addWord(ITLAReserveredWords.ALL_WORDS_ARRAY[i], keyword);
    }
    
    rules.add(wordRule);

    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
 
Example 13
Source File: CSSTokenScanner.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * createRules
 * 
 * @return
 */
protected List<IRule> createRules()
{
	List<IRule> rules = new ArrayList<IRule>();

	// Add generic whitespace rule.
	rules.add(new WhitespaceRule(new WhitespaceDetector()));

	// multi-line comments
	rules.add(new MultiLineRule("/*", "*/", createToken(CSSTokenType.COMMENT), (char) 0, true));

	// strings
	rules.addAll(createStringRules());

	// at-keywords
	rules.add(createAtWordsRule());

	// units
	rules.addAll(createUnitRules());

	// numbers
	rules.add(new CSSNumberRule(createToken(CSSTokenType.NUMBER)));

	// hex colors
	// TODO: we need separate scanners for inside and outside of rules. This will erroneously pick up some ids as
	// well
	rules.add(new CSSHexColorRule(createToken(CSSTokenType.RGB)));

	// classes;
	rules.add(new WordRule(new IdentifierWithPrefixDetector('.'), createToken(CSSTokenType.CLASS)));

	// ids
	rules.add(new WordRule(new IdentifierWithPrefixDetector('#'), createToken(CSSTokenType.ID)));

	// !important
	rules.add(new CSSImportantRule(createToken(CSSTokenType.IMPORTANT)));

	// url
	rules.add(new CSSURLRule(createToken(CSSTokenType.URL)));

	// TODO: functions

	// TODO: Unicode

	// identifiers
	rules.add(new CSSIdentifierRule(createToken(CSSTokenType.IDENTIFIER)));

	// single character punctuators
	rules.add(createPunctuatorsRule());

	// multi-character punctuators
	WordRule punctuatorRule2 = new WordRule(new EqualOperatorWordDetector(), Token.UNDEFINED);
	punctuatorRule2.addWord("~=", createToken(CSSTokenType.INCLUDES));
	punctuatorRule2.addWord("|=", createToken(CSSTokenType.DASHMATCH));
	punctuatorRule2.addWord("^=", createToken(CSSTokenType.BEGINS_WITH));
	punctuatorRule2.addWord("$=", createToken(CSSTokenType.ENDS_WITH));
	rules.add(punctuatorRule2);

	return rules;
}
 
Example 14
Source File: DTDTagScanner.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 
 */
public DTDTagScanner()
{
	List<IRule> rules = new ArrayList<IRule>();

	rules.add(new WhitespaceRule(new WhitespaceDetector()));

	// NOTE: There is no String, but we're using this to generalize pubid,
	// att value, entity value
	rules.add(new MultiLineRule("\"", "\"", createToken(DTDTokenType.STRING), '\0', true)); //$NON-NLS-1$ //$NON-NLS-2$
	rules.add(new MultiLineRule("'", "'", createToken(DTDTokenType.STRING), '\0', true)); //$NON-NLS-1$ //$NON-NLS-2$

	WordRule operatorRule = new WordRule(new DTDOperatorWordDetector(), Token.UNDEFINED);
	operatorRule.addWord("<![", createToken(DTDTokenType.SECTION_START)); //$NON-NLS-1$
	operatorRule.addWord("]]>", createToken(DTDTokenType.SECTION_END)); //$NON-NLS-1$
	rules.add(operatorRule);

	WordRule wordRule = new WordRule(new DTDWordDetector(), Token.UNDEFINED);
	wordRule.addWord("<!ATTLIST", createToken(DTDTokenType.ATTLIST)); //$NON-NLS-1$
	wordRule.addWord("<!ELEMENT", createToken(DTDTokenType.ELEMENT)); //$NON-NLS-1$
	wordRule.addWord("<!ENTITY", createToken(DTDTokenType.ENTITY)); //$NON-NLS-1$
	wordRule.addWord("<!NOTATION", createToken(DTDTokenType.NOTATION)); //$NON-NLS-1$
	wordRule.addWord("#FIXED", createToken(DTDTokenType.FIXED)); //$NON-NLS-1$
	wordRule.addWord("#IMPLIED", createToken(DTDTokenType.IMPLIED)); //$NON-NLS-1$
	wordRule.addWord("#PCDATA", createToken(DTDTokenType.PCDATA)); //$NON-NLS-1$
	wordRule.addWord("#REQUIRED", createToken(DTDTokenType.REQUIRED)); //$NON-NLS-1$
	wordRule.addWord("ANY", createToken(DTDTokenType.ANY)); //$NON-NLS-1$
	wordRule.addWord("CDATA", createToken(DTDTokenType.CDATA_TYPE)); //$NON-NLS-1$
	wordRule.addWord("EMPTY", createToken(DTDTokenType.EMPTY)); //$NON-NLS-1$
	wordRule.addWord("ENTITY", createToken(DTDTokenType.ENTITY_TYPE)); //$NON-NLS-1$
	wordRule.addWord("ENTITIES", createToken(DTDTokenType.ENTITIES_TYPE)); //$NON-NLS-1$
	wordRule.addWord("ID", createToken(DTDTokenType.ID_TYPE)); //$NON-NLS-1$
	wordRule.addWord("IDREF", createToken(DTDTokenType.IDREF_TYPE)); //$NON-NLS-1$
	wordRule.addWord("IDREFS", createToken(DTDTokenType.IDREFS_TYPE)); //$NON-NLS-1$
	wordRule.addWord("IGNORE", createToken(DTDTokenType.IGNORE)); //$NON-NLS-1$
	wordRule.addWord("INCLUDE", createToken(DTDTokenType.INCLUDE)); //$NON-NLS-1$
	wordRule.addWord("NDATA", createToken(DTDTokenType.NDATA)); //$NON-NLS-1$
	wordRule.addWord("NMTOKEN", createToken(DTDTokenType.NMTOKEN_TYPE)); //$NON-NLS-1$
	wordRule.addWord("NMTOKENS", createToken(DTDTokenType.NMTOKENS_TYPE)); //$NON-NLS-1$
	wordRule.addWord("NOTATION", createToken(DTDTokenType.NOTATION_TYPE)); //$NON-NLS-1$
	wordRule.addWord("PUBLIC", createToken(DTDTokenType.PUBLIC)); //$NON-NLS-1$
	wordRule.addWord("SYSTEM", createToken(DTDTokenType.SYSTEM)); //$NON-NLS-1$
	rules.add(wordRule);

	rules.add(new DTDEntityRule('%', createToken(DTDTokenType.PE_REF)));
	rules.add(new DTDEntityRule('&', createToken(DTDTokenType.PE_REF)));

	CharacterMapRule charsRule = new CharacterMapRule();
	charsRule.add('>', createToken(DTDTokenType.GREATER_THAN));
	charsRule.add('(', createToken(DTDTokenType.LPAREN));
	charsRule.add('|', createToken(DTDTokenType.PIPE));
	charsRule.add(')', createToken(DTDTokenType.RPAREN));
	charsRule.add('?', createToken(DTDTokenType.QUESTION));
	charsRule.add('*', createToken(DTDTokenType.STAR));
	charsRule.add('+', createToken(DTDTokenType.PLUS));
	charsRule.add(',', createToken(DTDTokenType.COMMA));
	charsRule.add('%', createToken(DTDTokenType.PERCENT));
	charsRule.add('[', createToken(DTDTokenType.LBRACKET));
	rules.add(charsRule);

	rules.add(new WordRule(new DTDNameDetector(), createToken(DTDTokenType.NAME)));
	rules.add(new WordRule(new DTDNmtokenWordDetector(), createToken(DTDTokenType.NMTOKEN)));

	setRules(rules.toArray(new IRule[rules.size()]));
}
 
Example 15
Source File: JsniScanner.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public JsniScanner(IColorManager colorManager) {
  // TODO: get these from GWT preference store instead of Java's

  // TODO: need to refresh colorManager when prefs change
  //
  IToken jsniJavaRef = new Token(new TextAttribute(
      colorManager.getColor(JsniColorConstants.JSNI_JAVA_REF)));

  IToken jsniComment = new Token(new TextAttribute(
      colorManager.getColor(JsniColorConstants.JSNI_COMMENT)));

  IToken jsniKeyword = new Token(new TextAttribute(
      colorManager.getColor(JsniColorConstants.JSNI_KEYWORD)));

  IToken jsniDefault = new Token(new TextAttribute(
      colorManager.getColor(JsniColorConstants.JSNI_DEFAULT)));

  IToken jsniString = new Token(new TextAttribute(
      colorManager.getColor(JsniColorConstants.JSNI_STRING)));

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

  // Java references
  rules.add(new JavaRefRule(jsniJavaRef));

  // single line comments
  rules.add(new EndOfLineRule("//", jsniComment));

  // JS keywords
  WordRule keywordRules = new WordRule(new JsWordDetector(), jsniDefault);
  for (String keyword : JS_KEYWORDS) {
    keywordRules.addWord(keyword, jsniKeyword);
  }
  rules.add(keywordRules);

  // Strings
  rules.add(new SingleLineRule("\"", "\"", jsniString, '\\', true));
  rules.add(new SingleLineRule("'", "'", jsniString, '\\', true));

  // Add generic whitespace rule.
  rules.add(new WhitespaceRule(new WhitespaceDetector()));

  // convert to array and set them for RuleBasedScanner to use
  setRules(rules.toArray(new IRule[rules.size()]));
}
 
Example 16
Source File: PCALCodeScanner.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * Construct the rules
 */
public PCALCodeScanner()
{
    TLAColorProvider provider = TLAEditorActivator.getDefault().getTLAColorProvider();

    IToken keyword = new Token(new TextAttribute(provider.getColor(TLAColorProvider.TLA_KEYWORD_KEY), null, SWT.BOLD));
    IToken value = new Token(new TextAttribute(provider.getColor(TLAColorProvider.TLA_VALUE_KEY)));
    IToken other = new Token(new TextAttribute(provider.getColor(TLAColorProvider.DEFAULT_TEXT_KEY)));
    IToken pcal = new Token(new TextAttribute(provider.getColor(TLAColorProvider.PCAL_KEYWORD_KEY)));
    
    List<WordRule> rules = new ArrayList<WordRule>();

    // Add generic whitespace rule.
    // rules.add(new WhitespaceRule(DocumentHelper.getDefaultWhitespaceDetector()));

    // Add word rule for standard words
    WordRule wordRule = new WordRule(DocumentHelper.getDefaultWordDetector(), other);
    
    // add values
    for (int i = 0; i < ITLAReserveredWords.ALL_VALUES_ARRAY.length; i++)
    {
        wordRule.addWord(ITLAReserveredWords.ALL_VALUES_ARRAY[i], value);
    }
    
    // add reserved words
    for (int i = 0; i < ITLAReserveredWords.ALL_WORDS_ARRAY.length; i++)
    {
        wordRule.addWord(ITLAReserveredWords.ALL_WORDS_ARRAY[i], keyword);
    }
    
 // add PlusCal keywords
    for (int i = 0; i < ITLAReserveredWords.PCAL_WORDS_ARRAY.length; i++)
    {
        wordRule.addWord(ITLAReserveredWords.PCAL_WORDS_ARRAY[i], pcal);
    }
    
    rules.add(wordRule);

    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
 
Example 17
Source File: ImpexRuleScanner.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
public ImpexRuleScanner(ColorProvider provider) {
	IToken stringToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_STRING_COLOR))));
	IToken commentToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_COMMENT_COLOR))));
	IToken instructToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_INSTRUCT_COLOR)), null, Font.ITALIC));
	IToken modifiersToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_MODIF_COLOR))));
	IToken impexTagsToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_TAG_COLOR)), null, Font.BOLD));
	IToken keywordsValuesToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_KVAL_COLOR))));
	IToken referenceToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_REF_COLOR)), null, Font.BOLD));
	IToken definitionsToken = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PreferenceConstants.P_DEF_COLOR)), null, Font.ITALIC));

	List<IRule> rules = Lists.newArrayList();
	// trap instruction within quotes first to prevent being picked up by next rules
	rules.add(new EndOfLineRule("\"#%", instructToken));
	
	// rule for Strings - may span multiple lines
	rules.add(new MultiLineRule("\"", "\"", stringToken));
	rules.add(new MultiLineRule("\'", "\'", stringToken));
	
	rules.add(new EndOfLineRule("#%", instructToken));
	// rule for comments - ended by a line delimiter
	rules.add(new EndOfLineRule("#", commentToken));

	WordRule wordRule = RuleFactory.buildRule(ImpexRules.KEYWORD, null);		
	// rule for modifiers
	for (String word : Formatter.IMPEX_KEYWORDS_ATTRIBUTES) {
		wordRule.addWord(word, modifiersToken);
	}

	// rule for impex tags
	for (String header : Formatter.HEADER_MODE_PROPOSALS) {
		wordRule.addWord(header, impexTagsToken);
	}
	
	// rule for keyword values
	for (String value : Formatter.KEYWORDS_VALUES) {
		wordRule.addWord(value, keywordsValuesToken);
	}

	rules.add(wordRule);

	// rule for definitions
	wordRule = RuleFactory.buildRule(ImpexRules.VARIABLE, definitionsToken);
	rules.add(wordRule);
	wordRule = RuleFactory.buildRule(ImpexRules.REFERENCE, referenceToken);
	rules.add(wordRule);
	
	wordRule = RuleFactory.buildRule(ImpexRules.SEMICOLON, modifiersToken);
	rules.add(wordRule);
	wordRule = RuleFactory.buildRule(ImpexRules.COMMA, modifiersToken);
	rules.add(wordRule);
	
	IRule[] ruleArray = new IRule[rules.size()];
	setRules(rules.toArray(ruleArray));
}
 
Example 18
Source File: GoScanner.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void initRules(ArrayList2<IRule> rules) {
	
	// Add generic whitespace rule.
	rules.add(new WhitespaceRule(new LangWhitespaceDetector()));
	
	
	final IToken tkDefault = getToken(GoUIPreferenceConstants.DEFAULT);
	
	WordRule wordRule = new WordRule(new JavaWordDetector(), tkDefault);
	
	final IToken keyword         = getToken(GoUIPreferenceConstants.KEYWORD);
	final IToken primitive       = getToken(GoUIPreferenceConstants.KW_NATIVE_TYPES);
	final IToken builtinFunction = getToken(GoUIPreferenceConstants.BUILTIN_FUNCTION);
	final IToken textToken       = getToken(GoUIPreferenceConstants.DEFAULT);
	setDefaultReturnToken(textToken);
	
	// add tokens for each reserved word
	wordRule.addWord("break",       keyword);
	wordRule.addWord("default",     keyword);
	wordRule.addWord("func",        keyword);
	wordRule.addWord("interface",   keyword);
	wordRule.addWord("select",      keyword);
	wordRule.addWord("case",        keyword);
	wordRule.addWord("defer",       keyword);
	wordRule.addWord("go",          keyword);
	wordRule.addWord("map",         keyword);
	wordRule.addWord("struct",      keyword);
	wordRule.addWord("chan",        keyword);
	wordRule.addWord("else",        keyword);
	wordRule.addWord("goto",        keyword);
	wordRule.addWord("package",     keyword);
	wordRule.addWord("switch",      keyword);
	wordRule.addWord("const",       keyword);
	wordRule.addWord("fallthrough", keyword);
	wordRule.addWord("if",          keyword);
	wordRule.addWord("range",       keyword);
	wordRule.addWord("type",        keyword);
	wordRule.addWord("continue",    keyword);
	wordRule.addWord("for",         keyword);
	wordRule.addWord("import",      keyword);
	wordRule.addWord("return",      keyword);
	wordRule.addWord("var",         keyword);
	
	wordRule.addWord("iota",        keyword);
	
	wordRule.addWord("append",  builtinFunction);
	wordRule.addWord("cap",     builtinFunction);
	wordRule.addWord("close",   builtinFunction);
	wordRule.addWord("complex", builtinFunction);
	wordRule.addWord("copy",    builtinFunction);
	wordRule.addWord("delete",  builtinFunction);
	wordRule.addWord("imag",    builtinFunction);
	wordRule.addWord("len",     builtinFunction);
	wordRule.addWord("make",    builtinFunction);
	wordRule.addWord("new",     builtinFunction);
	wordRule.addWord("panic",   builtinFunction);
	wordRule.addWord("print",   builtinFunction);
	wordRule.addWord("println", builtinFunction);
	wordRule.addWord("real",    builtinFunction);
	wordRule.addWord("recover", builtinFunction);
	
	final IToken value = getToken(GoUIPreferenceConstants.KW_LITERAL);
	wordRule.addWord("nil",   value);
	wordRule.addWord("true",  value);
	wordRule.addWord("false", value);
	
	wordRule.addWord("uint8", primitive);
	wordRule.addWord("uint16", primitive);
	wordRule.addWord("uint32", primitive);
	wordRule.addWord("uint64", primitive);
	wordRule.addWord("int8", primitive);
	wordRule.addWord("int16", primitive);
	wordRule.addWord("int32", primitive);
	wordRule.addWord("int64", primitive);
	wordRule.addWord("float32", primitive);
	wordRule.addWord("float64", primitive);
	wordRule.addWord("complex64",  primitive);
	wordRule.addWord("complex128", primitive);
	wordRule.addWord("rune",       primitive);
	wordRule.addWord("byte",       primitive);
	wordRule.addWord("uint",       primitive);
	wordRule.addWord("int",        primitive);
	wordRule.addWord("uintptr",    primitive);
	
	wordRule.addWord("string", primitive);
	wordRule.addWord("bool",   primitive);
	wordRule.addWord("error",  primitive);
	
	rules.add(wordRule);
	
	rules.add(new LexingRule_RuleAdapter(new GoSubLexer(getToken(GoUIPreferenceConstants.NUMBER))));
	
	rules.add(new GoOperatorRule(getToken(GoUIPreferenceConstants.OPERATOR)));
	rules.add(new GoControlCharactersRule(getToken(GoUIPreferenceConstants.STRUCTURAL_SYMBOLS)));
}