01: package org.drools.eclipse.editors.scanners;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import org.eclipse.jface.text.IDocument;
07: import org.eclipse.jface.text.rules.IPredicateRule;
08: import org.eclipse.jface.text.rules.IToken;
09: import org.eclipse.jface.text.rules.MultiLineRule;
10: import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
11: import org.eclipse.jface.text.rules.Token;
12:
13: /**
14: * Break apart the rule source, very very simply.
15: *
16: * The job of the partitioner is to identify if the cursor position
17: * is in a rule block, or not. Comments are also generated as a
18: * separate partition.
19: * TODO: add support for dialect based partitioning for correct syntaxhighlighting
20: * @author Michael Neale
21: */
22: public class DRLPartionScanner extends RuleBasedPartitionScanner {
23:
24: public static final String RULE_PART_CONTENT = "__partition_rule_content";
25: public static final String RULE_COMMENT = "__partition_multiline_comment";
26:
27: public static final String[] LEGAL_CONTENT_TYPES = {
28: IDocument.DEFAULT_CONTENT_TYPE, RULE_PART_CONTENT,
29: RULE_COMMENT };
30:
31: public DRLPartionScanner() {
32: initialise();
33: }
34:
35: private void initialise() {
36: List rules = new ArrayList();
37:
38: // rules
39: IToken rulePartition = new Token(RULE_PART_CONTENT);
40: rules.add(new MultiLineRule("\nrule", "\nend", rulePartition));
41: //a query is really just a rule for most purposes.
42: rules.add(new MultiLineRule("\nquery", "\nend", rulePartition));
43:
44: // comments
45: IToken comment = new Token(RULE_COMMENT);
46: rules
47: .add(new MultiLineRule("/*", "*/", comment, (char) 0,
48: true));
49:
50: setPredicateRules((IPredicateRule[]) rules
51: .toArray(new IPredicateRule[rules.size()]));
52: }
53: }
|