1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.ui.text;
13 import java.util.ArrayList;
14 import java.util.List;
16 import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
17 import net.sourceforge.phpeclipse.IPreferenceConstants;
18 import net.sourceforge.phpeclipse.phpeditor.util.PHPVariableDetector;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.text.IDocument;
22 import org.eclipse.jface.text.rules.ICharacterScanner;
23 import org.eclipse.jface.text.rules.IToken;
24 import org.eclipse.jface.text.rules.IWordDetector;
25 import org.eclipse.jface.text.rules.Token;
26 import org.eclipse.jface.text.rules.WordRule;
29 * A rule based PHPDoc scanner.
31 public final class PHPStringDQCodeScanner extends AbstractJavaScanner {
33 private static String[] fgTokenProperties = {
34 IPreferenceConstants.PHP_STRING_DQ,
35 IPreferenceConstants.PHP_VARIABLE,
36 IPreferenceConstants.PHP_VARIABLE_DOLLAR };
38 private class PHPWordRule extends WordRule {
39 private StringBuffer fBuffer = new StringBuffer();
41 public PHPWordRule(IWordDetector detector) {
42 super(detector, Token.UNDEFINED);
45 public PHPWordRule(IWordDetector detector, IToken defaultToken) {
46 super(detector, defaultToken);
49 public IToken evaluate(ICharacterScanner scanner) {
50 int c = scanner.read();
51 boolean isUnderscore = false;
52 if (fDetector.isWordStart((char) c)) {
53 if (fColumn == UNDEFINED
54 || (fColumn == scanner.getColumn() - 1)) {
57 fBuffer.append((char) c);
62 while (c != ICharacterScanner.EOF
63 && fDetector.isWordPart((char) c)) {
64 fBuffer.append((char) c);
66 // hack for coloring object elements with variable color
67 // instead of string color
69 int c2 = scanner.read();
82 return getToken(IPreferenceConstants.PHP_VARIABLE_DOLLAR);
84 return getToken(IPreferenceConstants.PHP_VARIABLE);
89 return Token.UNDEFINED;
93 public PHPStringDQCodeScanner(IColorManager manager, IPreferenceStore store) {
94 super(manager, store);
98 public IDocument getDocument() {
103 * @see AbstractJavaScanner#getTokenProperties()
105 protected String[] getTokenProperties() {
106 return fgTokenProperties;
110 * @see AbstractJavaScanner#createRules()
112 protected List createRules() {
114 List list = new ArrayList();
116 // Add rule for tags.
117 Token token = getToken(IPreferenceConstants.PHP_STRING_DQ);
118 PHPWordRule wordRule = new PHPWordRule(new PHPVariableDetector(), token);
122 setDefaultReturnToken(getToken(IPreferenceConstants.PHP_STRING_DQ));