package net.sourceforge.phpeclipse.phpeditor.php;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
import net.sourceforge.phpdt.ui.text.IColorManager;
import net.sourceforge.phpeclipse.phpeditor.util.PHPWordDetector;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
/**
* Rule to detect java operators.
- *
+ *
* @since 3.0
*/
protected class OperatorRule implements IRule {
/**
* Creates a new operator rule.
- *
+ *
* @param token
* Token to use for this rule
*/
/**
* Is this character an operator character?
- *
+ *
* @param character
* Character to determine whether it is an operator character
* @return <code>true</code> iff the character is an operator, <code>false</code> otherwise.
/**
* Check if lastCharacter/character are a PHP start or end token ( <? ... ?> )
- *
+ *
* @param scanner
* @param lastCharacter
* @param character
private class PHPWordRule extends WordRule {
private StringBuffer fBuffer = new StringBuffer();
+ protected Map fWordsIgnoreCase = new HashMap();
public PHPWordRule(IWordDetector detector) {
super(detector, Token.UNDEFINED);
super(detector, defaultToken);
}
+ /**
+ * Adds a word and the token to be returned if it is detected.
+ *
+ * @param word the word this rule will search for, may not be <code>null</code>
+ * @param token the token to be returned if the word has been found, may not be <code>null</code>
+ */
+ public void addWordIgnoreCase(String word, IToken token) {
+ Assert.isNotNull(word);
+ Assert.isNotNull(token);
+
+ fWordsIgnoreCase.put(word, token);
+ }
+
public IToken evaluate(ICharacterScanner scanner) {
int c = scanner.read();
boolean isVariable = false;
boolean isUnderscore = false;
+ String word;
if (c == '<') {
c = scanner.read();
if (c != '?') {
}
return getToken(IPreferenceConstants.PHP_VARIABLE);
}
- IToken token = (IToken) fWords.get(fBuffer.toString());
+ word = fBuffer.toString();
+ IToken token = (IToken) fWords.get(word);
+ if (token != null)
+ return token;
+
+ token = (IToken) fWordsIgnoreCase.get(word.toLowerCase());
if (token != null)
return token;
wordRule.addWord(name, keyword);
}
} else if (elbuffer instanceof PHPFunction) {
- wordRule.addWord(((PHPFunction) elbuffer).getName(), functionName);
+ wordRule.addWordIgnoreCase(((PHPFunction) elbuffer).getName(), functionName);
} else if (elbuffer instanceof PHPType) {
wordRule.addWord(elbuffer.getName(), type);
} else if (elbuffer instanceof PHPConstant) {