Java 类org.eclipse.jface.text.rules.WordPatternRule 实例源码

项目:velocity-edit    文件:VelocityStringScanner.java   
public VelocityStringScanner(VelocityColorProvider manager)
{
    List rules = new ArrayList();
    // Add generic whitespace rule
    rules.add(new WhitespaceRule(new WhitespaceDetector()));
    // Add pattern rule for formal references
    Token token = (Token) manager.getToken(IColorConstants.STRING_REFERENCE);
    rules.add(new PatternRule("$!{", "}", token, (char) 0, true));
    rules.add(new PatternRule("${", "}", token, (char) 0, true));
    // Add pattern rule for shorthand references
    token = (Token) manager.getToken(IColorConstants.STRING_REFERENCE);
    rules.add(new WordPatternRule(new IdentifierDetector(), "$!", null, token));
    rules.add(new WordPatternRule(new IdentifierDetector(), "$", null, token));
    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
    setDefaultReturnToken(manager.getToken(IColorConstants.STRING));
}
项目:strutsclipse    文件:AbstractXmlParser.java   
private IDocumentPartitioner createAttrPartitioner(IDocument document,
        String[] attrs) {
    IPredicateRule[] attrRules = new IPredicateRule[attrs.length + 2];
    attrRules[0] = new SingleLineRule("\"", "\"", new Token(
            DOUBLE_QUOTES_TOKEN));
    attrRules[1] = new SingleLineRule("'", "'", new Token(
            SINGLE_QUOTES_TOKEN));

    String[] types = new String[attrs.length + 2];
    types[0] = DOUBLE_QUOTES_TOKEN;
    types[1] = SINGLE_QUOTES_TOKEN;

    for (int i = 0; i < attrs.length; i++) {
        attrRules[i + 2] = new WordPatternRule(new AttributeDetector(),
                attrs[i], "=", new Token(attrs[i]));

        types[i + 2] = attrs[i];
    }

    return createConnectPartitioner(document, attrRules, types);
}
项目:velocity-edit    文件:VelocityCodeScanner.java   
public VelocityCodeScanner(VelocityColorProvider manager)
{
    List rules = new ArrayList();
    // Add generic whitespace rule
    rules.add(new WhitespaceRule(new WhitespaceDetector()));
    // Add word rule for directives
    Token token = (Token) manager.getToken(IColorConstants.DIRECTIVE);
    WordRule wordRule = new WordRule(new DirectiveDetector(), token);
    token = (Token) manager.getToken(IColorConstants.DIRECTIVE);
    // System directives
    String[] directives = Directive.DIRECTIVES;
    for (int i = directives.length - 1; i >= 0; i--)
    {
        wordRule.addWord(directives[i], token);
    }
    // User directives
    Iterator userDirectives = VelocityEditorEnvironment.getParser().getUserDirectives().iterator();
    while (userDirectives.hasNext())
    {
        wordRule.addWord((String) userDirectives.next(), token);
    }
    rules.add(wordRule);
    // Add pattern rule for formal references
    token = (Token) manager.getToken(IColorConstants.REFERENCE);
    rules.add(new PatternRule("$!{", "}", token, (char) 0, true));
    rules.add(new PatternRule("${", "}", token, (char) 0, true));
    // Add pattern rule for shorthand references
    token = (Token) manager.getToken(IColorConstants.REFERENCE);
    rules.add(new WordPatternRule(new IdentifierDetector(), "$!", null, token));
    rules.add(new WordPatternRule(new IdentifierDetector(), "$", null, token));
    // token = new Token(new
    // TextAttribute(aProvider.getColor(IColorConstants.TAG), null,
    // SWT.BOLD));
    // rules.add(new TagRule(token));
    // token = new Token(new
    // TextAttribute(aProvider.getColor(IColorConstants.COMMENT)));
    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    setRules(result);
}
项目:velocity-edit    文件:HTMLTagScanner.java   
public HTMLTagScanner(VelocityColorProvider manager)
{
    fDefaultToken = manager.getToken(IColorConstants.HTML_ATTRIBUTE);
    fElementToken = manager.getToken(IColorConstants.HTML_TAG);
    fEndElementToken = manager.getToken(IColorConstants.HTML_ENDTAG);
    IToken string = manager.getToken(IColorConstants.HTML_String);
    Vector rules = new Vector();
    setDefaultReturnToken(fDefaultToken);
    fElementRule = new WordRule(new HTMLElementDetector(), fDefaultToken);
    Token token = (Token) manager.getToken(IColorConstants.DIRECTIVE);
    WordRule wordRule = new WordRule(new DirectiveDetector(), token);
    token = (Token) manager.getToken(IColorConstants.DIRECTIVE);
    // System directives
    String[] directives = Directive.DIRECTIVES;
    for (int i = directives.length - 1; i >= 0; i--)
    {
        wordRule.addWord(directives[i], token);
    }
    rules.add(wordRule);

    rules.add(new PatternRule("\"", "\"", string, '\0', true));
    rules.add(new PatternRule("'", "'", string, '\0', true));
    rules.add(new WhitespaceRule(new WhitespaceDetector()));
    token = (Token) manager.getToken(IColorConstants.REFERENCE);
    rules.add(new PatternRule("$!{", "}", token, (char) 0, true));
    rules.add(new PatternRule("${", "}", token, (char) 0, true));
    // Add pattern rule for shorthand references
    token = (Token) manager.getToken(IColorConstants.REFERENCE);
    rules.add(new WordPatternRule(new IdentifierDetector(), "$!", null, token));
    rules.add(new WordPatternRule(new IdentifierDetector(), "$", null, token));
    IRule[] result = new IRule[rules.size()];
    rules.copyInto(result);
    setRules(result);
}
项目:velocity-edit    文件:VelocityPartitionScanner.java   
/**
     * Creates the partitioner and sets up the appropriate rules.
     */
    public VelocityPartitionScanner()
    {
        cp = new VelocityColorProvider();
        List rules = new ArrayList();
        org.eclipse.jface.text.rules.IToken comment = cp.getToken(MULTI_LINE_COMMENT, true);
        org.eclipse.jface.text.rules.IToken proc_inst = cp.getToken(PROC_PARTITION, true);
        org.eclipse.jface.text.rules.IToken script = cp.getToken(SCRIPT_PARTITION, true);
        org.eclipse.jface.text.rules.IToken cdata = cp.getToken(CDATA_PARTITION, true);
        org.eclipse.jface.text.rules.IToken tag = cp.getToken(TAG_PARTITION, true);
        // org.eclipse.jface.text.rules.IToken text = cp.getToken(TEXT, true);
        rules.add(new MultiLineRule("<!--", "-->", comment));
//        rules.add(new MultiLineRule("<?", "?>", proc_inst));
//        rules.add(new MultiLineRule("<%", "%>", proc_inst));
//        rules.add(new MultiLineRule("<#", "#>", proc_inst));
        rules.add(new MultiLineRule("<![CDATA[", "]]>", proc_inst));
        rules.add(new MultiLineRule("<![", "]>", proc_inst));
        rules.add(new IgnoreCasePatternRule("<script", "</script>", script, '\0', false, false));
        rules.add(new IgnoreCasePatternRule("<pre>", "</pre>", cdata, '\0', false, false));
        rules.add(new HTMLTagRule("<", ">", tag, '\0', true));
        // Add rule for single line comments
        rules.add(new EndOfLineRule("##", cp.getToken(SINGLE_LINE_COMMENT, true)));
        // Add rule for strings
        rules.add(new SingleLineRule("\"", "\"", cp.getToken(PARSED_STRING, true), '\\'));
        // Add rule for character constants.
        rules.add(new SingleLineRule("'", "'", cp.getToken(UNPARSED_STRING, true), '\\'));
        // Add rules for multi-line comments and doc comments
        rules.add(new MultiLineRule("#**", "*#", cp.getToken(DOC_COMMENT, true)));
        rules.add(new MultiLineRule("#*", "*#", cp.getToken(MULTI_LINE_COMMENT, true)));
        // Add special empty comment word rules
        rules.add(new WordPatternRule(new EmptyCommentDetector(), "#***#", null, cp.getToken(DOC_COMMENT, true)));
        rules.add(new WordPatternRule(new EmptyCommentDetector(), "#**#", null, cp.getToken(MULTI_LINE_COMMENT, true)));
        IPredicateRule[] result = new IPredicateRule[rules.size()];
        rules.toArray(result);
        setPredicateRules(result);
    }
项目:velocity-edit    文件:PartitionScanner.java   
public PartitionScanner() {
    IPredicateRule[] predicateRules = new IPredicateRule[] {
        new MultiLineRule("#*", "*#", new Token(COMMENT_PARTITION)),
        new SingleLineRule("##", "\n", new Token(COMMENT_PARTITION)),
        new DirectiveRule(new Token(FOREACH_PARTITION), "foreach"),
        new DirectiveRule(new Token(SET_PARTITION), "set"),
        new DirectiveRule(new Token(TEXT_PARTITION), "txt"),
        new DirectiveRule(new Token(IF_PARTITION), "if"),
        new DirectiveRule(new Token(MACRO_PARTITION), "macro"),
        new DirectiveRule(new Token(INCLUDE_PARTITION), "include"),
        new DirectiveRule(new Token(PARSE_PARTITION), "parse"),
        new EndRule(new Token(FOREACH_END_PARTITION), "foreach"),
        new EndRule(new Token(IF_END_PARTITION), "if"),
        new EndRule(new Token(MACRO_END_PARTITION), "macro"),
        new WordPatternRule(new DirectiveDetector(), "#end", "", new Token(END_PARTITION)),
        new DirectiveRule(new Token(ELSE_IF_PARTITION), "elseif"),
        new WordPatternRule(new DirectiveDetector(), "#else", "", new Token(ELSE_PARTITION)),
        new VariableRule(new Token(VARIABLE_PARTITION), "!$"),
        new VariableRule(new Token(VARIABLE_PARTITION), "$"),
        new SingleLineRule("#stop", null, new Token(STOP_PARTITION)),
        new MacroInstanceRule(new Token(MACRO_INSTANCE_PARTITION)),

        new MultiLineRule("<!--", "-->", new Token(XML_COMMENT)),
        new TagRule(new Token(XML_TAG))
    };

    setPredicateRules(predicateRules);
}
项目:KaiZen-OpenAPI-Editor    文件:JsonScanner.java   
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);

}
项目:strutsclipse    文件:PropertiesParser.java   
public IRegion getKeyRegion(IDocument document, final String searchKey) {
    IPredicateRule[] rules = new IPredicateRule[4];
    rules[0] = new EndOfLineRule("#", Token.UNDEFINED);
    rules[1] = new EndOfLineRule("!", Token.UNDEFINED);
    rules[2] = new WordPatternRule(new PropertyKeyDetector(), "\n", "=",
            KEY_TOKEN);
    rules[3] = new WordPatternRule(new PropertyKeyDetector(), "\n", ":",
            KEY_TOKEN);

    RuleBasedPartitionScanner scanner = new RuleBasedPartitionScanner();
    scanner.setPredicateRules(rules);

    IDocumentPartitioner partitioner = new FastPartitioner(scanner,
            new String[] { KEY });

    IRegion region = null;
    try {
        partitioner.connect(document);

        ITypedRegion[] tagRegions = partitioner.computePartitioning(0,
                document.getLength());

        boolean firstRegion = true;
        for (ITypedRegion tagRegion : tagRegions) {
            if (KEY.equals(tagRegion.getType()) || firstRegion) {
                String key = null;
                try {
                    // -1 remove =
                    key = document.get(tagRegion.getOffset(),
                            tagRegion.getLength() - 1);
                    key = key.trim();
                } catch (BadLocationException e) {
                    e.printStackTrace();
                }
                // first line isn't caught by the key_token rule
                if (firstRegion && key != null) {
                    int indx = key.indexOf('=');
                    if (indx != -1) {
                        key = key.substring(0, indx).trim();
                    }
                }

                if (key != null) {
                    key = key.replace("\\ ", " ");
                    if (key.equals(searchKey)) {
                        region = tagRegion;
                        break;
                    }
                }
            }
            firstRegion = false;
        }
    } finally {
        if (partitioner != null) {
            partitioner.disconnect();
        }
    }
    return region;
}
项目:egradle    文件:AbstractGroovyBasedDocumentPartitionScanner.java   
private void buildAnnotationRules(List<IPredicateRule> rules, IToken token, IWordDetector wordDetector) {
    rules.add(new WordPatternRule(wordDetector, "@", "", token));

}