org.eclipse.jface.text.rules.EndOfLineRule Java Examples

The following examples show how to use org.eclipse.jface.text.rules.EndOfLineRule. 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: SamplePartitionScanner.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the partitioner and sets up the appropriate rules.
 */
public SamplePartitionScanner() {
	IToken tkString = new Token(LANG_STRING);
	IToken tkRawString = new Token(LANG_RAW_STRING);
	IToken tkCharacter = new Token(LANG_CHARACTER);
	IToken tkSingleComment = new Token(LANG_SINGLE_COMMENT);
	IToken tkMultiComment = new Token(LANG_MULTI_COMMENT);
	
	List<IPredicateRule> rules = new ArrayList<IPredicateRule>();
	
	rules.add(new MultiLineRule("`", "`", tkRawString, NO_ESCAPE, true));
	rules.add(new MultiLineRule("\"", "\"", tkString, '\\', true));
	rules.add(new SingleLineRule("'", "'", tkCharacter, '\\', true));
	
	rules.add(new EndOfLineRule("//", tkSingleComment, NO_ESCAPE));
	
	rules.add(new MultiLineRule("/*", "*/", tkMultiComment, NO_ESCAPE, true));
	
	
	setPredicateRules(rules.toArray(new IPredicateRule[rules.size()]));
}
 
Example #2
Source File: SQLPartitionScanner.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 *  
 */
public SQLPartitionScanner( )
{
	super( );
	IToken sqlComment = new Token( COMMENT );
	IToken sqlQuoteString = new Token( QUOTE_STRING );

	
	ArrayList rules = new ArrayList( );
	rules.add( new MultiLineRule( "\"", "\"", sqlQuoteString, '\\' ) ); //$NON-NLS-1$ //$NON-NLS-2$
	rules.add( new MultiLineRule( "\'", "\'", sqlQuoteString, '\\' ) ); //$NON-NLS-1$ //$NON-NLS-2$
	rules.add( new EndOfLineRule( "//", sqlComment ) ); //$NON-NLS-1$
	rules.add( new EndOfLineRule( "--", sqlComment ) ); //$NON-NLS-1$
	rules.add( new MultiLineRule( "/*", "*/", sqlComment ) ); //$NON-NLS-1$ //$NON-NLS-2$
	
	setPredicateRules( (IPredicateRule[]) rules.toArray( new IPredicateRule[rules.size( )] ) );

}
 
Example #3
Source File: TexArgScanner.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * A default constructor.
 * @param manager
 */
public TexArgScanner(ColorManager manager) {
    IToken commentToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.COMMENT),
            null,
            manager.getStyle(ColorManager.COMMENT_STYLE)));

    //Commands are colored in argument color with command styles 
    IToken commandToken = new Token(
            new TextAttribute(
                    manager.getColor(ColorManager.CURLY_BRACKETS),
                    null,
                    manager.getStyle(ColorManager.COMMAND_STYLE)));

    List<IRule> rules = new ArrayList<IRule>();
    rules.add(new EndOfLineRule("%", commentToken, '\\'));
    rules.add(new WhitespaceRule(new WhitespaceDetector()));
    rules.add(new WordRule(new TexWord(), commandToken));

    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
 
Example #4
Source File: TexOptArgScanner.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * A default constructor.
 * @param manager
 */
public TexOptArgScanner(ColorManager manager) {
    IToken commentToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.COMMENT),
            null,
            manager.getStyle(ColorManager.COMMENT_STYLE)));

    //Commands are colored in argument color with command styles 
    IToken commandToken = new Token(
            new TextAttribute(
                    manager.getColor(ColorManager.SQUARE_BRACKETS),
                    null,
                    manager.getStyle(ColorManager.COMMAND_STYLE)));

    List<IRule> rules = new ArrayList<IRule>();
    rules.add(new EndOfLineRule("%", commentToken, '\\'));
    rules.add(new WhitespaceRule(new WhitespaceDetector()));
    rules.add(new WordRule(new TexWord(), commandToken));

    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
 
Example #5
Source File: ModulaRuleBasedPartitionScanner.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public ModulaRuleBasedPartitionScanner() {
	super();
	
       // Create the list of rules that produce tokens
	inactiveCodeRule = new InactiveCodeRule();
	IPredicateRule[] rules = new IPredicateRule[] {
		inactiveCodeRule,
	    new EndOfLineRule("--", END_OF_LINE_COMMENT_TOKEN), //$NON-NLS-1$
	    new ModulaCommentRule(BLOCK_COMMENT_TOKEN),
                            
           new SingleLineRule("\"", "\"", DOUBLE_QUOTE_STRING_TOKEN), //$NON-NLS-1$ //$NON-NLS-2$
           new SingleLineRule("'", "'",   SINGLE_QUOTE_STRING_TOKEN), //$NON-NLS-1$ //$NON-NLS-2$

	    new MultiLineRule("<*", "*>", PRAGMA_TOKEN, (char)0, true) //$NON-NLS-1$ //$NON-NLS-2$
	};

	setPredicateRules(rules);
       setDefaultReturnToken(DEFAULT_TOKEN);
}
 
Example #6
Source File: TexScanner.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A default constructor.
 * @param manager
 */
public TexScanner(ColorManager manager) {
    // A token that defines how to color numbers
    IToken numberToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.TEX_NUMBER),
            null,
            manager.getStyle(ColorManager.TEX_NUMBER_STYLE)));

    // A token that defines how to color command words (\command_word)
    IToken commandToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.COMMAND),
            null,
            manager.getStyle(ColorManager.COMMAND_STYLE)));

    IToken commentToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.COMMENT),
            null,
            manager.getStyle(ColorManager.COMMENT_STYLE)));

    // A token that defines how to color special characters (\_, \&, \~ ...)
    IToken specialCharToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.TEX_SPECIAL),
            null,
            manager.getStyle(ColorManager.TEX_SPECIAL_STYLE)));
    
    List<IRule> rules = new ArrayList<IRule>();
    rules.add(new TexSpecialCharRule(specialCharToken));
    rules.add(new WordRule(new TexWord(), commandToken));
    rules.add(new NumberRule(numberToken));
    rules.add(new EndOfLineRule("%", commentToken, '\\'));
    rules.add(new WhitespaceRule(new WhitespaceDetector()));
    
    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
 
Example #7
Source File: CommentScanner.java    From mat-calcite-plugin with Apache License 2.0 5 votes vote down vote up
public CommentScanner() {
	List<IRule> rules = new ArrayList<IRule>();

	Token commentToken = new Token(new TextAttribute(new Color(
			Display.getCurrent(), new RGB(63, 127, 95))));
	rules.add(new EndOfLineRule("--", commentToken));
	rules.add(new EndOfLineRule("//", commentToken));
	rules.add(new MultiLineRule("/*", "*/", commentToken));

	setRules(rules.toArray(new IRule[rules.size()]));
}
 
Example #8
Source File: CalcitePartitionScanner.java    From mat-calcite-plugin with Apache License 2.0 5 votes vote down vote up
public CalcitePartitionScanner() {
	IToken comment = new Token(SQL_COMMENT);
	IToken string = new Token(SQL_STRING);
	IToken quotedIdentifier = new Token(SQL_QUOTED_IDENTIFIER);

	setPredicateRules(new IPredicateRule[] {
			new EndOfLineRule("//", comment),
			new EndOfLineRule("--", comment),
			new MultiLineRule("/*", "*/", comment),
			new SingleLineRule("\"", "\"", quotedIdentifier),
			new MultiLineRule("'", "'", string),
	});
}
 
Example #9
Source File: EditorConfigPartitionScanner.java    From editorconfig-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the partitioner and sets up the appropriate rules.
 */
public EditorConfigPartitionScanner() {
	super();

	IToken comment = new Token(COMMENT);
	IToken sectionName = new Token(SECTION);
	IToken propertyValue = new Token(PROPERTY_VALUE);
	IToken key = new Token(IDocument.DEFAULT_CONTENT_TYPE);

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

	// Add rule for leading white space.
	rules.add(new LeadingWhitespacePredicateRule(key, "\t")); //$NON-NLS-1$
	rules.add(new LeadingWhitespacePredicateRule(key, " ")); //$NON-NLS-1$

	// Add rules for comments.
	rules.add(new EndOfLineRule("#", comment, (char) 0, true)); //$NON-NLS-1$
	// rules.add(new EndOfLineRule("!", comment, (char) 0, true));
	// //$NON-NLS-1$

	// Add rules for sections.
	rules.add(new SingleLineRule("[", "]", sectionName, '\\', true, true)); //$NON-NLS-1$

	// Add rules for property values.
	rules.add(new SingleLineRule("=", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule(":", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule(" ", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule("\t", null, propertyValue, '\\', true, true)); //$NON-NLS-1$

	// Add special case word rule.
	EmptyCommentRule wordRule = new EmptyCommentRule(comment);
	rules.add(wordRule);

	IPredicateRule[] result = new IPredicateRule[rules.size()];
	rules.toArray(result);
	setPredicateRules(result);
}
 
Example #10
Source File: JavaPartitionScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the partitioner and sets up the appropriate rules.
 */
public JavaPartitionScanner() {
	super();

	IToken string= new Token(JAVA_STRING);
	IToken character= new Token(JAVA_CHARACTER);
	IToken javaDoc= new Token(JAVA_DOC);
	IToken multiLineComment= new Token(JAVA_MULTI_LINE_COMMENT);
	IToken singleLineComment= new Token(JAVA_SINGLE_LINE_COMMENT);

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

	// Add rule for single line comments.
	rules.add(new EndOfLineRule("//", singleLineComment)); //$NON-NLS-1$

	// Add rule for strings.
	rules.add(new SingleLineRule("\"", "\"", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$

	// Add rule for character constants.
	rules.add(new SingleLineRule("'", "'", character, '\\')); //$NON-NLS-2$ //$NON-NLS-1$

	// Add special case word rule.
	EmptyCommentRule wordRule= new EmptyCommentRule(multiLineComment);
	rules.add(wordRule);

	// Add rules for multi-line comments and javadoc.
	rules.add(new MultiLineRule("/**", "*/", javaDoc)); //$NON-NLS-1$ //$NON-NLS-2$
	rules.add(new MultiLineRule("/*", "*/", multiLineComment)); //$NON-NLS-1$ //$NON-NLS-2$

	IPredicateRule[] result= new IPredicateRule[rules.size()];
	rules.toArray(result);
	setPredicateRules(result);
}
 
Example #11
Source File: PropertiesFilePartitionScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the partitioner and sets up the appropriate rules.
 */
public PropertiesFilePartitionScanner() {
	super();

	IToken comment= new Token(COMMENT);
	IToken propertyValue= new Token(PROPERTY_VALUE);
	IToken key= new Token(IDocument.DEFAULT_CONTENT_TYPE);

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

	// Add rule for leading white space.
	rules.add(new LeadingWhitespacePredicateRule(key, "\t")); //$NON-NLS-1$
	rules.add(new LeadingWhitespacePredicateRule(key, " ")); //$NON-NLS-1$

	// Add rules for comments.
	rules.add(new EndOfLineRule("#", comment, (char) 0, true)); //$NON-NLS-1$
	rules.add(new EndOfLineRule("!", comment, (char) 0, true)); //$NON-NLS-1$

	// Add rules for property values.
	rules.add(new SingleLineRule("=", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule(":", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule(" ", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule("\t", null, propertyValue, '\\', true, true)); //$NON-NLS-1$

	// Add special case word rule.
	EmptyCommentRule wordRule= new EmptyCommentRule(comment);
	rules.add(wordRule);

	IPredicateRule[] result= new IPredicateRule[rules.size()];
	rules.toArray(result);
	setPredicateRules(result);
}
 
Example #12
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 #13
Source File: BibCodeScanner.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a BibTeX document scanner
 * 
 * @param provider The color provider for syntax highlighting
 */
public BibCodeScanner(BibColorProvider provider) {

    IToken keyword = new Token(new TextAttribute(provider
            .getColor(BibColorProvider.KEYWORD)));
    IToken comment = new Token(new TextAttribute(provider
            .getColor(BibColorProvider.SINGLE_LINE_COMMENT)));
    IToken other = new Token(new TextAttribute(provider
            .getColor(BibColorProvider.DEFAULT)));

    List rules = new ArrayList();

    // Add rule for single line comments.
    rules.add(new EndOfLineRule("%", comment));

    rules.add(new BibCommandRule(keyword));

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

    // Add word rule for keywords, types, and constants.
    WordRule wordRule = new WordRule(new BibWordDetector(), other);
    rules.add(wordRule);

    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
 
Example #14
Source File: JsonScanner.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 4 votes vote down vote up
protected void init() {
    TextAttribute keyAttr = tokenAttribute(PreferenceConstants.COLOR_KEY, PreferenceConstants.BOLD_KEY,
            PreferenceConstants.ITALIC_KEY, PreferenceConstants.UNDERLINE_KEY);
    IToken keyToken = new YAMLToken(keyAttr, YAMLToken.KEY);

    TextAttribute pathKeyAttr = tokenAttribute(PreferenceConstants.COLOR_KEY, PreferenceConstants.BOLD_KEY,
            PreferenceConstants.ITALIC_KEY, PreferenceConstants.UNDERLINE_KEY);
    IToken pathKeyToken = new YAMLToken(pathKeyAttr, YAMLToken.KEY);

    TextAttribute scalarAttr = tokenAttribute(PreferenceConstants.COLOR_SCALAR, PreferenceConstants.BOLD_SCALAR,
            PreferenceConstants.ITALIC_SCALAR, PreferenceConstants.UNDERLINE_SCALAR);
    IToken scalarToken = new YAMLToken(scalarAttr, YAMLToken.SCALAR);

    TextAttribute commentAttr = tokenAttribute(PreferenceConstants.COLOR_COMMENT, PreferenceConstants.BOLD_COMMENT,
            PreferenceConstants.ITALIC_COMMENT, PreferenceConstants.UNDERLINE_COMMENT);
    IToken commentToken = new YAMLToken(commentAttr, YAMLToken.COMMENT);

    TextAttribute documentAttr = tokenAttribute(PreferenceConstants.COLOR_DOCUMENT,
            PreferenceConstants.BOLD_DOCUMENT, PreferenceConstants.ITALIC_DOCUMENT,
            PreferenceConstants.UNDERLINE_DOCUMENT);

    IToken documentStartToken = new YAMLToken(documentAttr, YAMLToken.DOCUMENT_START);
    IToken documentEndToken = new YAMLToken(documentAttr, YAMLToken.DOCUMENT_END);

    TextAttribute anchorAttr = tokenAttribute(PreferenceConstants.COLOR_ANCHOR, PreferenceConstants.BOLD_ANCHOR,
            PreferenceConstants.ITALIC_ANCHOR, PreferenceConstants.UNDERLINE_ANCHOR);
    IToken anchorToken = new YAMLToken(anchorAttr, YAMLToken.ANCHOR);

    TextAttribute aliasAttr = tokenAttribute(PreferenceConstants.COLOR_ALIAS, PreferenceConstants.BOLD_ALIAS,
            PreferenceConstants.ITALIC_ALIAS, PreferenceConstants.UNDERLINE_ALIAS);
    IToken aliasToken = new YAMLToken(aliasAttr, YAMLToken.ALIAS);

    IToken indicatorCharToken = new YAMLToken(new TextAttribute(null), YAMLToken.INDICATOR_CHARACTER);

    TextAttribute tagAttr = tokenAttribute(PreferenceConstants.COLOR_TAG_PROPERTY,
            PreferenceConstants.BOLD_TAG_PROPERTY, PreferenceConstants.ITALIC_TAG_PROPERTY,
            PreferenceConstants.UNDERLINE_TAG_PROPERTY);
    IToken tagPropToken = new YAMLToken(tagAttr, YAMLToken.TAG_PROPERTY);

    TextAttribute constantAttr = tokenAttribute(PreferenceConstants.COLOR_CONSTANT,
            PreferenceConstants.BOLD_CONSTANT, PreferenceConstants.ITALIC_CONSTANT,
            PreferenceConstants.UNDERLINE_CONSTANT);
    IToken predefinedValToken = new YAMLToken(constantAttr, YAMLToken.CONSTANT);

    IToken whitespaceToken = new YAMLToken(new TextAttribute(null), YAMLToken.WHITESPACE);

    IToken directiveToken = new YAMLToken(new TextAttribute(null), YAMLToken.DIRECTIVE);

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

    rules.add(new KeyRule(keyToken));
    rules.add(new SingleQuotedKeyRule(keyToken));
    rules.add(new DoubleQuotedKeyRule(keyToken));
    rules.add(new PathRule(pathKeyToken));
    rules.add(new MultiLineRule("\"", "\"", scalarToken, '\\'));
    rules.add(new MultiLineRule("'", "'", scalarToken));
    rules.add(new EndOfLineRule("#", commentToken));
    rules.add(new EndOfLineRule("%TAG", directiveToken));
    rules.add(new EndOfLineRule("%YAML", directiveToken));
    rules.add(new DocumentStartAndEndRule("---", documentStartToken));
    rules.add(new DocumentStartAndEndRule("...", documentEndToken));
    rules.add(new IndicatorCharacterRule(indicatorCharToken));
    rules.add(new WhitespaceRule(whitespaceToken));
    rules.add(new WordPatternRule(new AnchorWordDetector(), "&", "", anchorToken));
    rules.add(new WordPatternRule(new AnchorWordDetector(), "*", "", aliasToken));
    rules.add(new WordPatternRule(new TagWordDetector(), "!", "", tagPropToken));

    rules.add(new PredefinedValueRule(predefinedValToken));

    rules.add(new ScalarRule(scalarToken));

    IRule[] rulesArray = new IRule[rules.size()];
    rules.toArray(rulesArray);
    setRules(rulesArray);
    setDefaultReturnToken(scalarToken);

}
 
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: 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 #17
Source File: TexMathScanner.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * A default constructor. 
 * @param manager
 */
public TexMathScanner(ColorManager manager) {
    IToken defaultToken = new Token(
            new TextAttribute(
                    manager.getColor(ColorManager.EQUATION),
                    null,
                    manager.getStyle(ColorManager.EQUATION_STYLE)));

    IToken commentToken = new Token(
            new TextAttribute(
                    manager.getColor(ColorManager.COMMENT),
                    null,
                    manager.getStyle(ColorManager.COMMENT_STYLE)));

    //Commands are colored in math color with command styles 
    IToken commandToken = new Token(
            new TextAttribute(
                    manager.getColor(ColorManager.EQUATION),
                    null,
                    manager.getStyle(ColorManager.COMMAND_STYLE)));
    // A token that defines how to color special characters (\_, \&, \~ ...)
    IToken specialCharToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.TEX_SPECIAL),
            null,
            manager.getStyle(ColorManager.TEX_SPECIAL_STYLE)));
    
    List<IRule> rules = new ArrayList<IRule>();
    
    rules.add(new WhitespaceRule(new WhitespaceDetector()));
    rules.add(new TexSpecialCharRule(specialCharToken));
    //rules.add(new SingleLineRule("\\%", " ", specialCharToken));
    rules.add(new EndOfLineRule("%", commentToken));
    /*rules.add(new TexEnvironmentRule("comment", commentToken));
    rules.add(new SingleLineRule("\\[", " ", defaultToken));
    rules.add(new SingleLineRule("\\]", " ", defaultToken));
    rules.add(new SingleLineRule("\\(", " ", defaultToken));
    rules.add(new SingleLineRule("\\)", " ", defaultToken));*/
    rules.add(new WordRule(new TexWord(), commandToken));
    
    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);		
}
 
Example #18
Source File: TexTikzScanner.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * A default constructor.
 * @param manager
 */
public TexTikzScanner(ColorManager manager) {
    IToken commandToken = new Token(
            new TextAttribute(
                    manager.getColor(ColorManager.COMMAND),
                    null,
                    manager.getStyle(ColorManager.COMMAND_STYLE)));

    IToken specialCharToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.TEX_SPECIAL),
            null,
            manager.getStyle(ColorManager.TEX_SPECIAL_STYLE)));

    IToken numberToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.TEX_NUMBER),
            null,
            manager.getStyle(ColorManager.TEX_NUMBER_STYLE)));

    IToken commentToken = new Token(new TextAttribute(manager
            .getColor(ColorManager.COMMENT),
            null,
            manager.getStyle(ColorManager.COMMENT_STYLE)));

    IToken argToken = new Token(
            new TextAttribute(
                    manager.getColor(ColorManager.CURLY_BRACKETS),
                    null,
                    manager.getStyle(ColorManager.CURLY_BRACKETS_STYLE)));

    IToken optArgToken = new Token(
            new TextAttribute(
                    manager.getColor(ColorManager.SQUARE_BRACKETS),
                    null,
                    manager.getStyle(ColorManager.SQUARE_BRACKETS_STYLE)));

    List<IRule> rules = new ArrayList<IRule>();
    rules.add(new TexSpecialCharRule(specialCharToken));
    rules.add(new WordRule(new TexWord(), commandToken));
    rules.add(new NumberRule(numberToken));
    rules.add(new EndOfLineRule("%", commentToken, '\\'));
    rules.add(new WhitespaceRule(new WhitespaceDetector()));
    rules.add(new MultiLineRule("{", "}", argToken, '\\'));
    rules.add(new MultiLineRule("[", "]", optArgToken, '\\'));

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