1 20 package org.apache.directory.ldapstudio.schemas.view.views; 21 22 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 import org.eclipse.jface.text.rules.IRule; 27 import org.eclipse.jface.text.rules.IToken; 28 import org.eclipse.jface.text.rules.IWhitespaceDetector; 29 import org.eclipse.jface.text.rules.IWordDetector; 30 import org.eclipse.jface.text.rules.RuleBasedScanner; 31 import org.eclipse.jface.text.rules.SingleLineRule; 32 import org.eclipse.jface.text.rules.Token; 33 import org.eclipse.jface.text.rules.WhitespaceRule; 34 import org.eclipse.jface.text.rules.WordRule; 35 36 37 43 public class SchemaCodeScanner extends RuleBasedScanner 44 { 45 String attributype = "attributetype"; 47 String objectclass = "objectclass"; 49 String [] keywords = new String [] 50 { "NAME", "DESC", "OBSOLETE", "SUP", "EQUALITY", "ORDERING", "MUST", "MAY", "STRUCTURAL", "SUBSTR", "SYNTAX", "SINGLE-VALUE", "COLLECTIVE", "NO-USER-MODIFICATION", "USAGE", "userApplications", "directoryOperation", "distributedOperation", "dSAOperation", "ABSTRACT", "STRUCTURAL", "AUXILIARY", "MUST", "MAY" }; 54 55 public SchemaCodeScanner( SchemaTextAttributeProvider provider ) 56 { 57 List <IRule> rules = new ArrayList <IRule>(); 58 59 IToken keyword = new Token( provider.getAttribute( SchemaTextAttributeProvider.KEYWORD_ATTRIBUTE ) ); 60 IToken string = new Token( provider.getAttribute( SchemaTextAttributeProvider.STRING_ATTRIBUTE ) ); 61 IToken undefined = new Token( provider.getAttribute( SchemaTextAttributeProvider.DEFAULT_ATTRIBUTE ) ); 62 IToken ATToken = new Token( provider.getAttribute( SchemaTextAttributeProvider.ATTRIBUTETYPE_ATTRIBUTE ) ); 63 IToken OCToken = new Token( provider.getAttribute( SchemaTextAttributeProvider.OBJECTCLASS_ATTRIBUTE ) ); 64 IToken oid = new Token( provider.getAttribute( SchemaTextAttributeProvider.OID_ATTRIBUTE ) ); 65 66 rules.add( new SingleLineRule( "\"", "\"", string, '\0', true ) ); rules.add( new SingleLineRule( "'", "'", string, '\0', true ) ); rules.add( new WhitespaceRule( new IWhitespaceDetector() 71 { 72 78 public boolean isWhitespace( char c ) 79 { 80 return Character.isWhitespace( c ); 81 } 82 } ) ); 83 84 WordRule wrOID = new WordRule( new SchemaOIDDetector(), oid ); 85 86 rules.add( wrOID ); 87 88 WordRule wr = new WordRule( new SchemaWordDetector(), undefined ); 90 91 wr.addWord( attributype, ATToken ); 93 94 wr.addWord( objectclass, OCToken ); 96 97 for ( String kw : keywords ) 99 { 100 wr.addWord( kw, keyword ); 101 } 102 103 rules.add( wr ); 104 105 IRule[] param = new IRule[rules.size()]; 106 rules.toArray( param ); 107 setRules( param ); 108 } 109 110 116 static class SchemaWordDetector implements IWordDetector 117 { 118 121 public boolean isWordPart( char c ) 122 { 123 return ( Character.isLetterOrDigit( c ) || c == '_' || c == '-' || c == '$' || c == '#' || c == '@' 124 || c == '~' || c == '.' || c == '?' ); 125 } 126 127 128 131 public boolean isWordStart( char c ) 132 { 133 return ( Character.isLetter( c ) || c == '.' || c == '_' || c == '?' || c == '$' ); 134 } 135 } 136 137 143 static class SchemaOIDDetector implements IWordDetector 144 { 145 148 public boolean isWordPart( char c ) 149 { 150 return ( Character.isDigit( c ) || c == '.' ); 151 } 152 153 154 157 public boolean isWordStart( char c ) 158 { 159 return ( Character.isDigit( c ) ); 160 } 161 } 162 } 163 | Popular Tags |