Commit e2676155 authored by Jay Herron's avatar Jay Herron

Fixed issues with matchiing word portions. Added try to keywords

parent c4a914b1
package org.jayherron.trioeditor.editors;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.text.rules.*;
/**
* An extension of WordRule that defines word rules
*/
public class KeywordRule extends WordRule {
/**
* Creates a rule which will return the token associated with the detected word.
* If no token has been associated, the scanner will be rolled back and an undefined
* token will be returned in order to allow any subsequent rules to analyze the characters.
*
* @see #addWord(String, IToken)
*/
public KeywordRule() {
super(new IWordDetector() { // This "word detector" is basically any acceptable java identifier.
this(Token.UNDEFINED, false);
}
/**
* Creates a rule which will return the token associated with the detected word.
* If no token has been associated, the specified default token will be returned.
*
* @param defaultToken the default token to be returned on success
* if nothing else is specified, may not be <code>null</code>
* @see #addWord(String, IToken)
*/
public KeywordRule(IToken defaultToken) {
this(defaultToken, false);
}
/**
* Creates a rule which will return the token associated with the detected word.
* If no token has been associated, the specified default token will be returned.
*
* @param defaultToken the default token to be returned on success
* if nothing else is specified, may not be <code>null</code>
* @param ignoreCase the case sensitivity associated with this rule
* @see #addWord(String, IToken)
* @since 3.3
*/
public KeywordRule(IToken defaultToken, boolean ignoreCase){
super(new IWordDetector() {
@Override
public boolean isWordStart(char c) {
return c != ' ' && Character.isJavaIdentifierStart(c);
......@@ -15,6 +57,21 @@ public class KeywordRule extends WordRule {
public boolean isWordPart(char c) {
return Character.isJavaIdentifierPart(c);
}
});
}, defaultToken, false);
}
}
/**
* This overridden function requires that the previous character is not a letter, digit, or underscore
*
*/
@Override
public IToken evaluate(ICharacterScanner scanner) {
scanner.unread();
int p = scanner.read();
if(!Character.isLetterOrDigit(p) && p != '_'){
return super.evaluate(scanner);
}
return Token.UNDEFINED;
}
}
\ No newline at end of file
......@@ -55,8 +55,9 @@ public class TrioScanner extends RuleBasedScanner {
keywords.addWord("return", keyword);
keywords.addWord("do", keyword);
keywords.addWord("end", keyword);
keywords.addWord("throw", keyword);
keywords.addWord("try", keyword);
keywords.addWord("catch", keyword);
keywords.addWord("throw", keyword);
keywords.addWord("null", keyword);
keywords.addWord("true", keyword);
keywords.addWord("false", keyword);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment