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);
64 return getToken(IPreferenceConstants.PHP_VARIABLE_DOLLAR);
66 return getToken(IPreferenceConstants.PHP_VARIABLE);
71 return Token.UNDEFINED;
75 public PHPStringDQCodeScanner(IColorManager manager, IPreferenceStore store) {
76 super(manager, store);
80 public IDocument getDocument() {
85 * @see AbstractJavaScanner#getTokenProperties()
87 protected String[] getTokenProperties() {
88 return fgTokenProperties;
92 * @see AbstractJavaScanner#createRules()
94 protected List createRules() {
96 List list = new ArrayList();
99 Token token = getToken(IPreferenceConstants.PHP_STRING_DQ);
100 PHPWordRule wordRule = new PHPWordRule(new PHPVariableDetector(), token);
104 setDefaultReturnToken(getToken(IPreferenceConstants.PHP_STRING_DQ));