Search in sources :

Example 1 with RuleBasedScanner

use of org.eclipse.jface.text.rules.RuleBasedScanner in project eclipse.platform.text by eclipse.

the class WordRuleTest method testBug144355.

/*
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=144355
	 */
@Test
public void testBug144355() throws Exception {
    IWordDetector detector = new SimpleWordDetector();
    String defaultTokenString = "defaultToken";
    Token defaultToken = new Token(defaultTokenString);
    String testTokenStringNormal = "TestTokenString";
    String testTokenStringDifferentCapitalization = "TestTOKENString";
    String testTokenStringCompletelyDifferent = "XXX";
    Token normalToken = new Token(testTokenStringNormal);
    WordRule rule = new WordRule(detector, defaultToken, true);
    rule.addWord(testTokenStringNormal, normalToken);
    // scenario 1
    // pre: pass in a normal string ("TestTokenString")
    // post: expect the normal token to be returned
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(new IRule[] { rule });
    scanner.setRange(new Document(testTokenStringNormal), 0, testTokenStringNormal.length());
    assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
    // scenario 2
    // pre: pass in a normal string but different capitalization ("TestTOKENString")
    // post: expect the normal token to be returned
    scanner = new RuleBasedScanner();
    scanner.setRules(new IRule[] { rule });
    scanner.setRange(new Document(testTokenStringDifferentCapitalization), 0, testTokenStringDifferentCapitalization.length());
    assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
    // scenario 3
    // pre: pass in a completely different string ("XXX")
    // post: expect the default token to be returned because the string can't be matched
    scanner = new RuleBasedScanner();
    scanner.setRules(new IRule[] { rule });
    scanner.setRange(new Document(testTokenStringCompletelyDifferent), 0, testTokenStringCompletelyDifferent.length());
    assertTrue(scanner.nextToken().getData().equals(defaultTokenString));
    WordRule ruleWithoutIgnoreCase = new WordRule(detector, defaultToken);
    ruleWithoutIgnoreCase.addWord(testTokenStringNormal, normalToken);
    // scenario 4
    // pre: pass in a normal string ("TestTokenString")
    // post: expect the normal token to be returned
    scanner = new RuleBasedScanner();
    scanner.setRules(new IRule[] { ruleWithoutIgnoreCase });
    scanner.setRange(new Document(testTokenStringNormal), 0, testTokenStringNormal.length());
    assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
    // scenario 5
    // pre: pass in a normal string but different capitalization ("TestTOKENString")
    // post: expect the default token to be returned
    scanner = new RuleBasedScanner();
    scanner.setRules(new IRule[] { ruleWithoutIgnoreCase });
    scanner.setRange(new Document(testTokenStringDifferentCapitalization), 0, testTokenStringDifferentCapitalization.length());
    assertTrue(scanner.nextToken().getData().equals(defaultTokenString));
}
Also used : IWordDetector(org.eclipse.jface.text.rules.IWordDetector) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) WordRule(org.eclipse.jface.text.rules.WordRule) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) RuleBasedScanner(org.eclipse.jface.text.rules.RuleBasedScanner) Test(org.junit.Test)

Example 2 with RuleBasedScanner

use of org.eclipse.jface.text.rules.RuleBasedScanner in project eclipse.platform.text by eclipse.

the class WordRuleTest method testBug175712_2.

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
@Test
public void testBug175712_2() throws Exception {
    IRule[] rules = new IRule[2];
    IToken stepToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    PatternRule stepRule = new PatternRule("(((", ")", stepToken, (char) 0, false);
    stepRule.setColumnConstraint(-1);
    rules[1] = stepRule;
    IToken titleToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    WordRule wordRule = new WordRule(new SimpleWordDetector());
    wordRule.addWord("((", titleToken);
    rules[0] = wordRule;
    IDocument document = new Document("((\n((\n- Cheese\n- Wine");
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(rules);
    scanner.setRange(document, 0, document.getLength());
    IToken defaultToken = new Token(this);
    scanner.setDefaultReturnToken(defaultToken);
    IToken token = scanner.nextToken();
    assertSame(titleToken, token);
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) PatternRule(org.eclipse.jface.text.rules.PatternRule) TextAttribute(org.eclipse.jface.text.TextAttribute) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) WordRule(org.eclipse.jface.text.rules.WordRule) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) RuleBasedScanner(org.eclipse.jface.text.rules.RuleBasedScanner) IRule(org.eclipse.jface.text.rules.IRule) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 3 with RuleBasedScanner

use of org.eclipse.jface.text.rules.RuleBasedScanner in project eclipse.platform.text by eclipse.

the class WordRuleTest method testBug175712_1.

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
@Test
public void testBug175712_1() throws Exception {
    IRule[] rules = new IRule[2];
    IToken stepToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    PatternRule stepRule = new PatternRule("(((", ")", stepToken, (char) 0, false);
    stepRule.setColumnConstraint(-1);
    rules[1] = stepRule;
    IToken titleToken = new Token(new TextAttribute(null, null, SWT.BOLD));
    WordRule wordRule = new WordRule(new SimpleWordDetector());
    wordRule.addWord("((", titleToken);
    rules[0] = wordRule;
    IDocument document = new Document("((( \n((\n- Cheese\n- Wine");
    RuleBasedScanner scanner = new RuleBasedScanner();
    scanner.setRules(rules);
    scanner.setRange(document, 0, document.getLength());
    IToken defaultToken = new Token(this);
    scanner.setDefaultReturnToken(defaultToken);
    IToken token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(defaultToken, token);
    token = scanner.nextToken();
    assertSame(titleToken, token);
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) PatternRule(org.eclipse.jface.text.rules.PatternRule) TextAttribute(org.eclipse.jface.text.TextAttribute) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) WordRule(org.eclipse.jface.text.rules.WordRule) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) RuleBasedScanner(org.eclipse.jface.text.rules.RuleBasedScanner) IRule(org.eclipse.jface.text.rules.IRule) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 4 with RuleBasedScanner

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

the class HTMLSourceConfiguration method getDoctypeScanner.

protected RuleBasedScanner getDoctypeScanner() {
    if (doctypeScanner == null) {
        doctypeScanner = new RuleBasedScanner();
        RGB rgb = IHTMLColorConstants.PROC_INSTR;
        Color color = new Color(Display.getCurrent(), rgb);
        doctypeScanner.setDefaultReturnToken(new Token(new TextAttribute(color)));
    }
    return doctypeScanner;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color) Token(org.eclipse.jface.text.rules.Token) RGB(org.eclipse.swt.graphics.RGB) RuleBasedScanner(org.eclipse.jface.text.rules.RuleBasedScanner)

Example 5 with RuleBasedScanner

use of org.eclipse.jface.text.rules.RuleBasedScanner in project usbdm-eclipse-plugins by podonoghue.

the class ViewConfiguration method getDummyScanner.

protected RuleBasedScanner getDummyScanner(Color color) {
    // if (ruleScanner == null) {
    ruleScanner = new RuleBasedScanner();
    ruleScanner.setDefaultReturnToken(new Token(new TextAttribute(color)));
    // }
    return ruleScanner;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) Token(org.eclipse.jface.text.rules.Token) RuleBasedScanner(org.eclipse.jface.text.rules.RuleBasedScanner)

Aggregations

RuleBasedScanner (org.eclipse.jface.text.rules.RuleBasedScanner)17 Token (org.eclipse.jface.text.rules.Token)13 TextAttribute (org.eclipse.jface.text.TextAttribute)9 Document (org.eclipse.jface.text.Document)8 IDocument (org.eclipse.jface.text.IDocument)8 IToken (org.eclipse.jface.text.rules.IToken)8 WordRule (org.eclipse.jface.text.rules.WordRule)8 PatternRule (org.eclipse.jface.text.rules.PatternRule)6 IRule (org.eclipse.jface.text.rules.IRule)4 IWordDetector (org.eclipse.jface.text.rules.IWordDetector)4 Color (org.eclipse.swt.graphics.Color)4 RGB (org.eclipse.swt.graphics.RGB)4 Test (org.junit.Test)4 IPresentationReconciler (org.eclipse.jface.text.presentation.IPresentationReconciler)3 PresentationReconciler (org.eclipse.jface.text.presentation.PresentationReconciler)3 DefaultDamagerRepairer (org.eclipse.jface.text.rules.DefaultDamagerRepairer)3