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 = { IPreferenceConstants.PHP_STRING_DQ, IPreferenceConstants.PHP_VARIABLE, IPreferenceConstants.PHP_VARIABLE_DOLLAR};
35 private class PHPWordRule extends WordRule {
36 private StringBuffer fBuffer = new StringBuffer();
38 public PHPWordRule(IWordDetector detector) {
39 super(detector, Token.UNDEFINED);
42 public PHPWordRule(IWordDetector detector, IToken defaultToken) {
43 super(detector, defaultToken);
46 public IToken evaluate(ICharacterScanner scanner) {
47 int c = scanner.read();
48 boolean isUnderscore = false;
49 if (fDetector.isWordStart((char) c)) {
50 if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
53 fBuffer.append((char) c);
58 while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)) {
59 fBuffer.append((char) c);
61 // hack for coloring object elements with variable color instead of string color
63 int c2=scanner.read();
77 return getToken(IPreferenceConstants.PHP_VARIABLE_DOLLAR);
79 return getToken(IPreferenceConstants.PHP_VARIABLE);
84 return Token.UNDEFINED;
88 public PHPStringDQCodeScanner(IColorManager manager, IPreferenceStore store) {
89 super(manager, store);
93 public IDocument getDocument() {
98 * @see AbstractJavaScanner#getTokenProperties()
100 protected String[] getTokenProperties() {
101 return fgTokenProperties;
105 * @see AbstractJavaScanner#createRules()
107 protected List createRules() {
109 List list = new ArrayList();
111 // Add rule for tags.
112 Token token = getToken(IPreferenceConstants.PHP_STRING_DQ);
113 PHPWordRule wordRule = new PHPWordRule(new PHPVariableDetector(), token);
117 setDefaultReturnToken(getToken(IPreferenceConstants.PHP_STRING_DQ));