1 package org.simantics.scl.ui.editor;
3 import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
4 import org.eclipse.jface.text.IDocument;
5 import org.eclipse.jface.text.IDocumentExtension3;
6 import org.eclipse.jface.text.IDocumentPartitioner;
7 import org.eclipse.jface.text.rules.EndOfLineRule;
8 import org.eclipse.jface.text.rules.FastPartitioner;
9 import org.eclipse.jface.text.rules.IPredicateRule;
10 import org.eclipse.jface.text.rules.MultiLineRule;
11 import org.eclipse.jface.text.rules.PatternRule;
12 import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
13 import org.eclipse.jface.text.rules.Token;
15 public class SCLDocumentSetup implements IDocumentSetupParticipant {
17 public static final String COMMENT = "COMMENT";
18 public static final String STRING = "STRING";
20 public static final String[] PARTITION_TYPES = new String[] {
24 public static final String SCL_PARTIONING = "SCL_PARTIONING";
28 public void setup(final IDocument document) {
29 if(document instanceof IDocumentExtension3) {
30 RuleBasedPartitionScanner scanner = new RuleBasedPartitionScanner();
31 scanner.setPredicateRules(new IPredicateRule[] {
32 new MultiLineRule("/*", "*/", new Token(COMMENT)),
33 new EndOfLineRule("//", new Token(COMMENT)),
34 new MultiLineRule("\"\"\"", "\"\"\"", new Token(STRING), '\\'),
35 new PatternRule("\"", "\"", new Token(STRING), '\\', true),
37 IDocumentPartitioner partitioner = new FastPartitioner(scanner, PARTITION_TYPES);
38 ((IDocumentExtension3)document).setDocumentPartitioner(SCL_PARTIONING, partitioner);
39 partitioner.connect(document);