View Javadoc

1   /*
2    * $Id: OWLTagScanner.java,v 1.5 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.rules;
10  
11  import org.eclipse.jface.text.rules.IRule;
12  import org.eclipse.jface.text.rules.IToken;
13  import org.eclipse.jface.text.rules.MultiLineRule;
14  import org.eclipse.jface.text.rules.RuleBasedScanner;
15  import org.eclipse.jface.text.rules.Token;
16  
17  import com.bbn.swede.editor.OWLColorProvider;
18  
19  /***
20   * A rules-based scanner responsible for identifying tokens inside begin and
21   * end tag partitions.  It is able to identify language elements, XML attributes
22   * (namespaces and xml:base), attribute values, and generics tag and attribute 
23   * names.
24   * @author jlerner
25   */
26  public class OWLTagScanner extends RuleBasedScanner
27  {
28     private IToken _tokenEnd;
29  
30     /***
31      * Creates a token to represent a content type.  The color is based on the
32      * values stored in OWLColorProvider and the text style is determined by
33      * the style parameter.
34      * @param sType One of the content type strings specified as public static
35      *              fields in OWLColorProvider
36      * @param style One of the SWT text style constants 
37      * @return The created token
38      */
39     private static IToken makeToken(String sType, int style)
40     {
41        return new Token(OWLColorProvider.getColorProvider().createTextAttribute(sType, style));
42     }
43     
44     private OWLNameRule _tagRule = new OWLNameRule();
45     /***
46      * Creates a new OWLTagScanner.
47      */
48     public OWLTagScanner()
49     {
50        OWLColorProvider ocp = OWLColorProvider.getColorProvider();
51        IToken string = new Token(ocp.createTextAttribute(OWLColorProvider.ATTRIBUTE_VALUE));
52        _tokenEnd = new Token("");
53        IRule[] rules = new IRule[4];
54        // Rules for attribute values
55        rules[0] = new MultiLineRule("\"", "\"", string); //$NON-NLS-1$ //$NON-NLS-2$
56        rules[1] = new MultiLineRule("'", "'", string); //$NON-NLS-1$ //$NON-NLS-2$
57        
58        //Rule for identifying namespaces and the xml:base attribute
59        rules[2] = new XMLNameRule();
60  
61        //Rule for identifying language vs. nonlanguage tags
62        rules[3] = _tagRule;
63        setRules(rules);
64     }
65  
66  }