Search in sources :

Example 1 with EndOfLineRule

use of org.eclipse.jface.text.rules.EndOfLineRule in project titan.EclipsePlug-ins by eclipse.

the class CodeScanner method getTTCNRules.

public static List<IRule> getTTCNRules(final ColorManager colorManager) {
    IToken singleLineComment = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_COMMENTS);
    IToken multiLineComment = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_COMMENTS);
    IToken keyword = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TTCN3_KEYWORDS);
    IToken templateMatch = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TEMPLATE_MATCH);
    IToken types = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TYPE);
    IToken timerOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TIMER_OP);
    IToken portOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_PORT_OP);
    IToken configOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_CONFIG_OP);
    IToken verdictOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_VERDICT_OP);
    IToken sutOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_SUT_OP);
    IToken functionOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_FUNCTION_OP);
    IToken predefinedOp = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_PREDEFINED_OP);
    IToken booleanConst = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_BOOLEAN_CONST);
    IToken verdictConst = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_TTCN3_VERDICT_CONST);
    IToken otherConst = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_OTHER_CONST);
    IToken macro = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_PREPROCESSOR);
    IToken visibility = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_VISIBILITY_OP);
    IToken string = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_STRINGS);
    IToken other = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_NORMAL_TEXT);
    List<IRule> rules = new ArrayList<IRule>();
    rules.add(new EndOfLineRule("//", singleLineComment));
    rules.add(new MultiLineRule("/*", "*/", multiLineComment, '\0', true));
    rules.add(new WhitespaceRule(new WhiteSpaceDetector()));
    rules.add(new TTCN3StringDetectionPatternRule(string));
    rules.add(new StringDetectionPatternRule("'", new char[][] { { '\'', 'B' }, { '\'', 'H' }, { '\'', 'O' } }, string));
    WordRule wordRule = new WordRule(new WordDetector(), other);
    for (String element : CodeScanner.KEYWORDS) {
        wordRule.addWord(element, keyword);
    }
    for (String element : CodeScanner.TEMPLATE_MATCH) {
        wordRule.addWord(element, templateMatch);
    }
    for (String element : CodeScanner.TYPES) {
        wordRule.addWord(element, types);
    }
    for (String element : CodeScanner.TIMER_OPERATIONS) {
        wordRule.addWord(element, timerOp);
    }
    for (String element : CodeScanner.PORT_OPERATIONS) {
        wordRule.addWord(element, portOp);
    }
    for (String element : CodeScanner.CONFIGURATION_OPERATIONS) {
        wordRule.addWord(element, configOp);
    }
    for (String element : CodeScanner.VERDICT_OPERATIONS) {
        wordRule.addWord(element, verdictOp);
    }
    for (String element : CodeScanner.SUT_OPERATION) {
        wordRule.addWord(element, sutOp);
    }
    for (String element : CodeScanner.FUNCTION_OPERATIONS) {
        wordRule.addWord(element, functionOp);
    }
    for (String element : CodeScanner.PREDEFINED_OPERATIONS) {
        wordRule.addWord(element, predefinedOp);
    }
    for (String element : CodeScanner.BOOLEAN_CONSTANTS) {
        wordRule.addWord(element, booleanConst);
    }
    for (String element : CodeScanner.VERDICT_CONSTANT) {
        wordRule.addWord(element, verdictConst);
    }
    for (String element : CodeScanner.OTHER_CONSTANT) {
        wordRule.addWord(element, otherConst);
    }
    for (String element : CodeScanner.VISIBILITY_MODIFIERS) {
        wordRule.addWord(element, visibility);
    }
    rules.add(wordRule);
    WordRule macroRule = new WordRule(new MacroDetector(), other);
    for (String element : CodeScanner.MACROS) {
        macroRule.addWord(element, macro);
    }
    rules.add(macroRule);
    WordRule titanSpecificKeywordsRule = new WordRule(new TitanSpecificKeywordDetector(), other);
    for (String element : CodeScanner.TITANSPECIFICKEYWORDS) {
        // looks like a standard keyword
        titanSpecificKeywordsRule.addWord(element, keyword);
    }
    rules.add(titanSpecificKeywordsRule);
    return rules;
}
Also used : ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) StringDetectionPatternRule(org.eclipse.titan.designer.editors.StringDetectionPatternRule) WhitespaceRule(org.eclipse.jface.text.rules.WhitespaceRule) WordRule(org.eclipse.jface.text.rules.WordRule) IRule(org.eclipse.jface.text.rules.IRule) WhiteSpaceDetector(org.eclipse.titan.designer.editors.WhiteSpaceDetector) IToken(org.eclipse.jface.text.rules.IToken) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule)

Example 2 with EndOfLineRule

use of org.eclipse.jface.text.rules.EndOfLineRule in project webtools.sourceediting by eclipse.

the class JavaCodeScanner method initializeRules.

public void initializeRules() {
    List rules = new ArrayList();
    // Add rule for multiple line comments.
    // $NON-NLS-1$ //$NON-NLS-2$
    rules.add(new MultiLineRule("/*", "*/", fSingleLineCommentToken));
    // Add rule for single line comments.
    // $NON-NLS-1$
    rules.add(new EndOfLineRule("//", fSingleLineCommentToken));
    // Add rule for strings and character constants.
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("\"", "\"", fStringToken, '\\'));
    // $NON-NLS-2$//$NON-NLS-1$
    rules.add(new SingleLineRule("'", "'", fStringToken, '\\'));
    // Add generic whitespace rule.
    // rules.add(new WhitespaceRule(new JavaWhitespaceDetector()));
    // Add word rule for keywords, types, and constants.
    WordRule wordRule = new WordRule(new JavaWordDetector(), fDefaultToken);
    for (int i = 0; i < fgKeywords.length; i++) wordRule.addWord(fgKeywords[i], fKeywordToken);
    for (int i = 0; i < fgTypes.length; i++) wordRule.addWord(fgTypes[i], fTypeToken);
    for (int i = 0; i < fgConstants.length; i++) wordRule.addWord(fgConstants[i], fTypeToken);
    rules.add(wordRule);
    // Add the double-quoted string rule
    rules.add(new DoubleQuotedStringRule(fStringToken));
    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
Also used : SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) List(java.util.List) ArrayList(java.util.ArrayList) WordRule(org.eclipse.jface.text.rules.WordRule) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule) IRule(org.eclipse.jface.text.rules.IRule)

Example 3 with EndOfLineRule

use of org.eclipse.jface.text.rules.EndOfLineRule in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonScanner method init.

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 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 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);
}
Also used : WordPatternRule(org.eclipse.jface.text.rules.WordPatternRule) AnchorWordDetector(org.dadacoalition.yedit.editor.scanner.AnchorWordDetector) ScalarRule(org.dadacoalition.yedit.editor.scanner.ScalarRule) TextAttribute(org.eclipse.jface.text.TextAttribute) KeyRule(org.dadacoalition.yedit.editor.scanner.KeyRule) DoubleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.DoubleQuotedKeyRule) SingleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.SingleQuotedKeyRule) TagWordDetector(org.dadacoalition.yedit.editor.scanner.TagWordDetector) YAMLToken(org.dadacoalition.yedit.editor.scanner.YAMLToken) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) PredefinedValueRule(org.dadacoalition.yedit.editor.scanner.PredefinedValueRule) WhitespaceRule(org.dadacoalition.yedit.editor.scanner.WhitespaceRule) IRule(org.eclipse.jface.text.rules.IRule) DocumentStartAndEndRule(org.dadacoalition.yedit.editor.scanner.DocumentStartAndEndRule) SingleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.SingleQuotedKeyRule) DoubleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.DoubleQuotedKeyRule) IToken(org.eclipse.jface.text.rules.IToken) IndicatorCharacterRule(org.dadacoalition.yedit.editor.scanner.IndicatorCharacterRule) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule)

Example 4 with EndOfLineRule

use of org.eclipse.jface.text.rules.EndOfLineRule in project syncope by apache.

the class JavaScriptScanner method createRules.

/**
 * Creates the list of <code>IRule</code>.
 * If you have to customize rules, override this method.
 *
 * @return the list of <code>IRule</code>
 */
protected List<IRule> createRules() {
    IToken normal = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.FOREGROUND)));
    IToken string = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JAVA_STRING)));
    IToken comment = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JAVA_COMMENT)));
    IToken keyword = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JAVA_KEYWORD)));
    List<IRule> rules = new ArrayList<IRule>();
    rules.add(new SingleLineRule("\"", "\"", string, '\\'));
    rules.add(new SingleLineRule("'", "'", string, '\\'));
    rules.add(new SingleLineRule("\\//", null, normal));
    rules.add(new EndOfLineRule("//", comment));
    WordRule wordRule = new WordRule(new JavaWordDetector(), normal);
    for (int i = 0; i < KEYWORDS.length; i++) {
        wordRule.addWord(KEYWORDS[i], keyword);
    }
    rules.add(wordRule);
    return rules;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) WordRule(org.eclipse.jface.text.rules.WordRule) IRule(org.eclipse.jface.text.rules.IRule) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule)

Example 5 with EndOfLineRule

use of org.eclipse.jface.text.rules.EndOfLineRule in project hale by halestudio.

the class GroovyPartitionScanner method createRules.

public static List<IRule> createRules(boolean withColor) {
    IPreferenceStore store = GroovyUIPlugin.getDefault().getPreferenceStore();
    Object objComment;
    Object objdComment;
    Object objmString;
    Object objsString;
    Object objsComment;
    if (withColor) {
        RGB rgb = PreferenceConverter.getColor(store, PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_STRINGS_COLOR);
        objComment = objmString = objsString = objsComment = objdComment = new TextAttribute(new Color(null, rgb), null, SWT.ITALIC);
    } else {
        objComment = JAVA_MULTI_LINE_COMMENT;
        objmString = GROOVY_MULTILINE_STRINGS;
        objsString = JAVA_STRING;
        objsComment = JAVA_SINGLE_LINE_COMMENT;
        objdComment = JAVA_DOC;
    }
    IToken comment = new Token(objComment);
    IToken mString = new Token(objmString);
    IToken sString = new Token(objsString);
    IToken sComment = new Token(objsComment);
    IToken jdoc = new Token(objdComment);
    List<IRule> rules = new ArrayList<IRule>();
    // Add rule for single line comments.
    rules.add(new EndOfLineRule("//", sComment));
    // Add rule for strings and character constants.
    rules.add(new MultiLineRule("'''", "'''", mString));
    rules.add(new MultiLineRule("\"\"\"", "\"\"\"", mString));
    // GRECLIPSE-1111 do not eagerly match these kinds of multiline strings
    rules.add(new SingleLineRule("\"", "\"", sString, '\\'));
    rules.add(new SingleLineRule("'", "'", sString, '\\'));
    // GRECLIPSE-1203 make dollar slashies optionally highlighted
    if (store.getBoolean(PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_SLASHY_STRINGS)) {
        rules.add(new MultiLineRule("$/", "/$", mString, '\0', false));
    }
    // Add special case word rule.
    rules.add(new WordPredicateRule(comment));
    // Add rule for JavaDoc
    // $NON-NLS-1$ //$NON-NLS-2$
    rules.add(new MultiLineRule("/**", "*/", jdoc, (char) 0, true));
    // Add rules for multi-line comments
    // $NON-NLS-1$ //$NON-NLS-2$
    rules.add(new MultiLineRule("/*", "*/", comment, (char) 0, true));
    return rules;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) RGB(org.eclipse.swt.graphics.RGB) IRule(org.eclipse.jface.text.rules.IRule) IToken(org.eclipse.jface.text.rules.IToken) SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule)

Aggregations

ArrayList (java.util.ArrayList)5 EndOfLineRule (org.eclipse.jface.text.rules.EndOfLineRule)5 IRule (org.eclipse.jface.text.rules.IRule)5 IToken (org.eclipse.jface.text.rules.IToken)4 MultiLineRule (org.eclipse.jface.text.rules.MultiLineRule)4 TextAttribute (org.eclipse.jface.text.TextAttribute)3 SingleLineRule (org.eclipse.jface.text.rules.SingleLineRule)3 WordRule (org.eclipse.jface.text.rules.WordRule)3 Token (org.eclipse.jface.text.rules.Token)2 Color (org.eclipse.swt.graphics.Color)2 List (java.util.List)1 AnchorWordDetector (org.dadacoalition.yedit.editor.scanner.AnchorWordDetector)1 DocumentStartAndEndRule (org.dadacoalition.yedit.editor.scanner.DocumentStartAndEndRule)1 DoubleQuotedKeyRule (org.dadacoalition.yedit.editor.scanner.DoubleQuotedKeyRule)1 IndicatorCharacterRule (org.dadacoalition.yedit.editor.scanner.IndicatorCharacterRule)1 KeyRule (org.dadacoalition.yedit.editor.scanner.KeyRule)1 PredefinedValueRule (org.dadacoalition.yedit.editor.scanner.PredefinedValueRule)1 ScalarRule (org.dadacoalition.yedit.editor.scanner.ScalarRule)1 SingleQuotedKeyRule (org.dadacoalition.yedit.editor.scanner.SingleQuotedKeyRule)1 TagWordDetector (org.dadacoalition.yedit.editor.scanner.TagWordDetector)1