View Javadoc

1   /*
2    * $Id: WordBeginRule.java,v 1.4 2005/06/01 17:38:33 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.ICharacterScanner;
12  import org.eclipse.jface.text.rules.IToken;
13  import org.eclipse.jface.text.rules.IWordDetector;
14  import org.eclipse.jface.text.rules.WordPatternRule;
15  
16  /***
17   * A specialized pattern rule that matches words that begin with a pattern.
18   */
19  public class WordBeginRule extends WordPatternRule
20  {
21     /***
22      * Creates a new WordBeginRule to match words that begin with specific text.
23      * @param detector The detector the rule will use to locate words
24      * @param startSequence The pattern to match at the beginning of words
25      * @param token The token to return when a word matches <code>startSequence</code>
26      */
27     public WordBeginRule(IWordDetector detector, String startSequence, IToken token)
28     {
29        super(detector, startSequence, "", token);
30     }
31  
32     /* (non-Javadoc)
33      * @see org.eclipse.jface.text.rules.PatternRule#endSequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner)
34      */
35     protected boolean endSequenceDetected(ICharacterScanner scanner)
36     {
37        int c;
38        while ((c = scanner.read()) != ICharacterScanner.EOF)
39        {
40           if (!fDetector.isWordPart((char)c))
41           {
42              scanner.unread();
43              return true;
44           }
45        }
46        return false;
47     }
48  }