Java Code Examples for org.eclipse.jface.text.rules.Token#UNDEFINED

The following examples show how to use org.eclipse.jface.text.rules.Token#UNDEFINED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PatternRule_Fixed.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {
	if (resume) {

		if (endSequenceDetected(scanner))
			return fToken;

	} else {

		int c= scanner.read();
		if (c == fStartSequence[0]) {
			if (sequenceDetected(scanner, fStartSequence, false)) {
				if (endSequenceDetected(scanner))
					return fToken;
			}
		}
	}

	scanner.unread();
	return Token.UNDEFINED;
}
 
Example 2
Source File: CSSCodeScannerRuleBased.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * createScannerSpecificRules
 * 
 * @return
 */
protected Collection<? extends IRule> createScannerSpecificRules()
{
	List<IRule> rules = new ArrayList<IRule>();
	WordRule wordRule = new WordRule(new KeywordIdentifierDetector(), Token.UNDEFINED);
	wordRule.addWord("em", createToken(CSSTokenType.EMS));
	wordRule.addWord("ex", createToken(CSSTokenType.EXS));
	wordRule.addWord("px", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("cm", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("mm", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("in", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("pt", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("pc", createToken(CSSTokenType.LENGTH));
	wordRule.addWord("deg", createToken(CSSTokenType.ANGLE));
	wordRule.addWord("rad", createToken(CSSTokenType.ANGLE));
	wordRule.addWord("grad", createToken(CSSTokenType.ANGLE));
	wordRule.addWord("ms", createToken(CSSTokenType.TIME));
	wordRule.addWord("s", createToken(CSSTokenType.TIME));
	wordRule.addWord("hz", createToken(CSSTokenType.FREQUENCY));
	wordRule.addWord("khz", createToken(CSSTokenType.FREQUENCY));
	wordRule.addWord("Hz", createToken(CSSTokenType.FREQUENCY));
	wordRule.addWord("kHz", createToken(CSSTokenType.FREQUENCY));
	addWordsToRule(wordRule, FUNCTIONS, CSSTokenType.FUNCTION);
	rules.add(wordRule);
	return rules;
}
 
Example 3
Source File: SuffixedWordRule.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner) {
    int c = scanner.read();
    if ((c != ICharacterScanner.EOF) && wordDetector.isWordStart((char)c)) {
        readLength = 1;
        
        do {
            c = scanner.read();
            readLength++;
        } while ((c != ICharacterScanner.EOF) && wordDetector.isWordPart((char)c));
        if (c == endCharacter) {
            return successToken;
        }
        
        while (readLength > 1) {
            readLength--;
            scanner.unread();
        }
    }
    scanner.unread();
    return Token.UNDEFINED;
}
 
Example 4
Source File: TagWordRule.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IToken evaluate(ICharacterScanner scanner)
{
	if (scanner.getColumn() > 0)
	{
		scanner.unread();
		int c = scanner.read();
		if (c == '<')
		{
			return super.evaluate(scanner);
		}
		else if ((c == '!' || c == '/') && scanner.getColumn() > 1)
		{
			scanner.unread();
			scanner.unread();
			c = scanner.read();
			scanner.read();
			if (c == '<')
			{
				return super.evaluate(scanner);
			}
		}
	}
	return Token.UNDEFINED;
}
 
Example 5
Source File: BibBraceRule.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
    if (resume) {
        boolean inString = false;
        do {
            int c = scanner.read();
            if (((char) c) == ',' && !inString)
                break;
            else if (((char) c) == '@') {
                scanner.unread();
                return Token.UNDEFINED;
            } else if (((char) c) == '"' && !inString)
                inString = true;
            else if (((char) c) == '"' && inString)
                inString = false;
            else if (c == ICharacterScanner.EOF)
                return Token.UNDEFINED;
        } while (true);
    }
    return doEvaluate(scanner, 1);
}
 
Example 6
Source File: BibStringRule.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner) {
    int count = 0;
    int charsRead = 0;
    int c = scanner.read();
    if (((char) c) == '"') {
            do {
                c = scanner.read();
                charsRead++;
                if (c == ICharacterScanner.EOF) {
                    unwind(scanner, charsRead);
                    return Token.UNDEFINED;
                } else if (((char) c) == '{') {
                    count++;
                } else if (((char) c) == '}') {
                    if (count == 0) {
                        unwind(scanner, charsRead);
                        return Token.UNDEFINED;
                    }
                    count--;
                }
            } while (((char) c) != '"');
            return fToken;
    }
    scanner.unread();
    return Token.UNDEFINED;
}
 
Example 7
Source File: BibEntryScanner.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner) {
    int c = scanner.read();
    if (((char) c) == '=' || ((char) c) == '#' || ((char) c) == ','
        || ((char) c) == '{' || ((char) c) == '}') {
        return fToken;
    } else if (((char) c) == '\\') {
        c = scanner.read();
        if (((char) c) == '"')
            return fToken;
        scanner.unread();
    }
    scanner.unread();
    return Token.UNDEFINED;
}
 
Example 8
Source File: RealNumberRule.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner) {
    int c = scanner.read();
    if ((c != ICharacterScanner.EOF) && Character.isDigit((char)c)) {
        readLength = 1;
        
        do {
            c = scanner.read();
            readLength++;
        } while ((c != ICharacterScanner.EOF) && Character.isDigit((char)c));
        if (c == '.') {
            do {
                c = scanner.read();
            } while ((c != ICharacterScanner.EOF) && Character.isDigit((char)c));
            if (c == 'E') {
                c = scanner.read();
                if ((c == '+') || (c == '-')) {
                    c = scanner.read();
                }
                while ((c != ICharacterScanner.EOF) && Character.isDigit((char)c)) {
                    c = scanner.read();
                }
            }
            scanner.unread();
            return successToken;
        }
        
        while (readLength > 1) {
            readLength--;
            scanner.unread();
        }
    }
    scanner.unread();
    return Token.UNDEFINED;
}
 
Example 9
Source File: BrokenStringRule.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner)
{
	int readCount = 1;
	int c;
	while ((c = scanner.read()) != ICharacterScanner.EOF)
	{
		if (c == '\'')
		{
			return singleQuoteToken;
		}
		else if (c == '"')
		{
			return doubleQuoteToken;
		}
		else if (c == '=')
		{
			break;
		}
		else if (c == '<' && readCount == 1)
		{
			break;
		}
		++readCount;
	}
	while (0 < readCount--)
	{
		scanner.unread();
	}
	return Token.UNDEFINED;
}
 
Example 10
Source File: CharacterMapRule.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner, boolean resume)
{
	successToken = characterTokenMap.get((char) scanner.read());

	if (successToken == null)
	{
		scanner.unread();
		successToken = Token.UNDEFINED;
	}

	return successToken;
}
 
Example 11
Source File: TypeScriptCodeScanner.java    From typescript.java with MIT License 5 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner) {

			int character= scanner.read();
			if (isBracket((char) character)) {
				do {
					character= scanner.read();
				} while (isBracket((char) character));
				scanner.unread();
				return fToken;
			} else {
				scanner.unread();
				return Token.UNDEFINED;
			}
		}
 
Example 12
Source File: TexSpecialCharRule.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tests if the current character is '\' character. If it is
 * calls test for next character.  
 * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(org.eclipse.jface.text.rules.ICharacterScanner, boolean)
 * @param scanner 	the scanner to read characters
 * @param resume	shall method start from next character
 * @return 			the success token if "\X" (X is one of the predefined 
 * 					characters) matches, Token.UNDEFINED otherwise
 */
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
	
	if(resume){
		if (evaluateNext(scanner)){
			return successToken;
		}else{
			return Token.UNDEFINED;				
		}				
	}else{
		return evaluate(scanner);
	}
}
 
Example 13
Source File: PresentationRepairer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
	if (fScanner == null) {
		// will be removed if deprecated constructor will be removed
		addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle);
		return;
	}

	int lastStart = region.getOffset();
	int length = 0;
	boolean firstToken = true;
	IToken lastToken = Token.UNDEFINED;
	TextStyle lastTextStyle = getTokenTextStyle(lastToken);

	fScanner.setRange(fDocument, lastStart, region.getLength());

	while (true) {
		IToken token = fScanner.nextToken();
		if (token.isEOF())
			break;

		TextStyle textStyle = getTokenTextStyle(token);
		if (lastTextStyle != null && lastTextStyle.equals(textStyle)) {
			length += fScanner.getTokenLength();
			firstToken = false;
		} else {
			if (!firstToken)
				addRange(presentation, lastStart, length, lastTextStyle);
			firstToken = false;
			lastToken = token;
			lastTextStyle = textStyle;
			lastStart = fScanner.getTokenOffset();
			length = fScanner.getTokenLength();
		}
	}

	addRange(presentation, lastStart, length, lastTextStyle);
}
 
Example 14
Source File: JavaDocScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected List<WordMatcher> createMatchers() {
	List<WordMatcher> list= super.createMatchers();

	// Add word rule for keywords.
	final IToken token= getToken(IJavaColorConstants.JAVADOC_KEYWORD);
	WordMatcher matcher= new CombinedWordRule.WordMatcher() {
		@Override
		public IToken evaluate(ICharacterScanner scanner, CharacterBuffer word) {
			int length= word.length();
			if (length > 1 && word.charAt(0) == '@') {
				int i= 0;
				try {
					for (; i <= length; i++)
						scanner.unread();
					int c= scanner.read();
					i--;
					if (c == '*' || Character.isWhitespace((char)c)) {
						scanner.unread();
						i++;
						return token;
					}
				} finally {
					for (; i > 0; i--)
						scanner.read();
				}
			}
			return Token.UNDEFINED;
		}
	};
	list.add(matcher);

	return list;
}
 
Example 15
Source File: JakartaRegExpRule.java    From LogViewer with Eclipse Public License 2.0 5 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
	String line = returnNextCompleteLine(scanner);
	if(line != null) {
		if(regexp.match(line)) {
			return successToken;
		}
	}
	return Token.UNDEFINED;
}
 
Example 16
Source File: PresentationRepairer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
	if (fScanner == null) {
		// will be removed if deprecated constructor will be removed
		addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle);
		return;
	}

	int lastStart = region.getOffset();
	int length = 0;
	boolean firstToken = true;
	IToken lastToken = Token.UNDEFINED;
	TextStyle lastTextStyle = getTokenTextStyle(lastToken);

	fScanner.setRange(fDocument, lastStart, region.getLength());

	while (true) {
		IToken token = fScanner.nextToken();
		if (token.isEOF())
			break;

		TextStyle textStyle = getTokenTextStyle(token);
		if (lastTextStyle != null && lastTextStyle.equals(textStyle)) {
			length += fScanner.getTokenLength();
			firstToken = false;
		} else {
			if (!firstToken)
				addRange(presentation, lastStart, length, lastTextStyle);
			firstToken = false;
			lastToken = token;
			lastTextStyle = textStyle;
			lastStart = fScanner.getTokenOffset();
			length = fScanner.getTokenLength();
		}
	}

	addRange(presentation, lastStart, length, lastTextStyle);
}
 
Example 17
Source File: AbstractLangScanner.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IToken evaluate(ICharacterScanner scanner) {
	AbstractLangScanner langScanner = AbstractLangScanner.this;
	assertTrue(scanner == langScanner);
	
	CharacterScanner_ReaderHelper readerHelper = new CharacterScanner_ReaderHelper(langScanner);
	IToken token = codeLexerRule.evaluateToken(readerHelper);
	if(token == null) {
		return Token.UNDEFINED;
	}
	return token;
}
 
Example 18
Source File: GoScanner.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IToken evaluate(ICharacterScanner scanner) {
	int read = scanner.read();
	
	if(read == ICharacterScanner.EOF) {
		return Token.UNDEFINED;
	}
	
	switch (read) {
	case '+': return currentOr('=', '+', scanner);
	case '-': return currentOr('=', '-', scanner);
	case '*': return currentOr('=', scanner);
	case '/': return currentOr('=', scanner);
	case '^': return currentOr('=', scanner);
	case '!': return currentOr('=', scanner);
	case '=': return currentOr('=', scanner);
	case '%': return currentOr('=', scanner);
	case '|': return currentOr('=', '|', scanner);
	case '&': 
		if(consume('^', scanner)) {
			return currentOr('=', scanner);
		}
		return currentOr('=', '&', scanner);
	
	case '<': 
		if(consume('<', scanner)) {
			return currentOr('=', scanner);
		}
		return currentOr('=', '-', scanner);
	case '>': 
		if(consume('>', scanner)) {
			return currentOr('=', scanner); // ">>" , ">>="
		}
		return currentOr('=', scanner);
		
	case ':':
		if(consume('=', scanner)) {
			return getSuccessToken(); // ":="
		}
		
		// fall-through
	default:
		scanner.unread(); return Token.UNDEFINED;
	}
	
}
 
Example 19
Source File: NonMatchingRule.java    From http4e with Apache License 2.0 4 votes vote down vote up
public IToken evaluate( ICharacterScanner scanner){
   return Token.UNDEFINED;
}
 
Example 20
Source File: CombinedWordRule.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns the token associated to the given word and the scanner state.
 *
 * @param scanner the scanner
 * @param word the word
 * @return the token or <code>null</code> if none is associated by this matcher
 */
public IToken evaluate(ICharacterScanner scanner, CharacterBuffer word) {
	IToken token= fWords.get(word);
	if (token != null)
		return token;
	return Token.UNDEFINED;
}