View Javadoc

1   /*
2    * $Id: OWLPartitionScanner.java,v 1.4 2004/09/20 03:51:39 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8    
9   package com.bbn.swede.editor;
10  
11  import org.eclipse.jface.text.rules.IPredicateRule;
12  import org.eclipse.jface.text.rules.IToken;
13  import org.eclipse.jface.text.rules.MultiLineRule;
14  import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
15  import org.eclipse.jface.text.rules.Token;
16  
17  import com.bbn.swede.editor.rules.NestedConstructRule;
18  
19  import java.util.List;
20  import java.util.ArrayList;
21  
22  /***
23   * Rules-based scanner for OWLDocumentPartitioner.
24   * Documents are broken into three basic partition types: begin tag, end tag, 
25   * and everything else.
26   * @author jlerner
27   */
28  public class OWLPartitionScanner extends RuleBasedPartitionScanner
29  {
30     /***
31      * Partition type string for begin tags.  For partitioning purposes,
32      * singletons are considered begin tags.
33      */
34     public static final String BEGIN_TAG = "BEGIN_TAG";
35     /***
36      * Partition type string for end tags.
37      */
38     public static final String END_TAG = "END_TAG";
39     
40     /***
41      * Allowed content types.
42      */
43     public static final String[] AS_CONTENT_TYPES = 
44     {
45        BEGIN_TAG,
46        END_TAG,
47        OWLColorProvider.COMMENT,
48        OWLColorProvider.PROCESSING_INSTRUCTION,
49        OWLColorProvider.DOCTYPE,
50        OWLColorProvider.CDATA,
51     };
52     
53     /***
54      * Creates an OWLPartitionScanner with basic rules for identifying
55      * begin vs. end tags, comments, processing instructions, and DOCTYPEs
56      */
57     public OWLPartitionScanner()
58     {
59        super();
60        //BEGIN_TAG and END_TAG shouldn't ever appear as actual content types
61        //at syntax coloring time
62        IToken beginTag = new Token(BEGIN_TAG);
63        IToken endTag = new Token(END_TAG);
64        IToken comment = new Token(OWLColorProvider.COMMENT);
65        IToken doctype = new Token(OWLColorProvider.DOCTYPE);
66        IToken procInstr = new Token(OWLColorProvider.PROCESSING_INSTRUCTION);
67        IToken cdata = new Token(OWLColorProvider.CDATA);
68        
69        List rules = new ArrayList();
70        rules.add(new MultiLineRule("<!--", "-->", comment));
71  
72        rules.add(new MultiLineRule("<?", "?>", procInstr));
73        rules.add(new NestedConstructRule("<!DOCTYPE", ">", doctype, "<!", ">"));
74        
75        rules.add(new MultiLineRule("</", ">", endTag));
76        rules.add(new MultiLineRule("<", ">", beginTag));
77        
78        this.setDefaultReturnToken(cdata);
79        
80        IPredicateRule[] result = new IPredicateRule[rules.size()];
81        rules.toArray(result);
82        setPredicateRules(result);
83     }
84  
85  }