use of org.eclipse.jface.text.rules.PatternRule 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);
}
use of org.eclipse.jface.text.rules.PatternRule 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);
}
use of org.eclipse.jface.text.rules.PatternRule in project netxms by netxms.
the class NXSLSourceViewerConfiguration method getPresentationReconciler.
/* (non-Javadoc)
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer)
*/
@Override
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
RuleBasedScanner scanner = new RuleBasedScanner();
scanner.setRules(codeRules);
scanner.setDefaultReturnToken(NXSLTextAttributeProvider.getTextAttributeToken(NXSLTextAttributeProvider.DEFAULT));
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
dr = new DefaultDamagerRepairer(new SingleTokenScanner(NXSLTextAttributeProvider.getTextAttribute(NXSLTextAttributeProvider.COMMENT)));
reconciler.setDamager(dr, NXSLDocument.CONTENT_COMMENTS);
reconciler.setRepairer(dr, NXSLDocument.CONTENT_COMMENTS);
scanner = new RuleBasedScanner();
scanner.setRules(new IRule[] { new PatternRule("\"", "\n", NXSLTextAttributeProvider.getTextAttributeToken(NXSLTextAttributeProvider.ERROR), (char) 0, false) });
scanner.setDefaultReturnToken(NXSLTextAttributeProvider.getTextAttributeToken(NXSLTextAttributeProvider.STRING));
dr = new DefaultDamagerRepairer(scanner);
reconciler.setDamager(dr, NXSLDocument.CONTENT_STRING);
reconciler.setRepairer(dr, NXSLDocument.CONTENT_STRING);
return reconciler;
}
use of org.eclipse.jface.text.rules.PatternRule in project webtools.sourceediting by eclipse.
the class WordRuleTest method testBug175712_1.
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
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);
}
use of org.eclipse.jface.text.rules.PatternRule in project webtools.sourceediting by eclipse.
the class WordRuleTest method testBug175712_2.
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712
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);
}
Aggregations