Java Code Examples for org.eclipse.jface.text.rules.ICharacterScanner#getColumn()

The following examples show how to use org.eclipse.jface.text.rules.ICharacterScanner#getColumn() . 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: 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 2
Source File: EntityRule.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected IToken doEvaluate(ICharacterScanner scanner, boolean resume)
{
	int column = scanner.getColumn();
	IToken token = super.doEvaluate(scanner, resume);
	if (token.isUndefined())
		return token;

	// Make sure whole thing matches pattern
	int read = scanner.getColumn() - column;
	for (int i = 0; i < read; i++)
	{
		scanner.unread();
	}
	StringBuilder builder = new StringBuilder();
	for (int i = 0; i < read; i++)
	{
		builder.append((char) scanner.read());
	}
	String word = builder.toString();
	if (word.length() > 2 && ENTITY_PATTERN.matcher(word).find())
	{
		return token;
	}
	for (int i = 0; i < read; i++)
	{
		scanner.unread();
	}
	return Token.UNDEFINED;
}
 
Example 3
Source File: CombinedWordRule.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner) {
	int c= scanner.read();
	if (fDetector.isWordStart((char) c)) {
		if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {

			fBuffer.clear();
			do {
				fBuffer.append((char) c);
				c= scanner.read();
			} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
			scanner.unread();

			for (int i= 0, n= fMatchers.size(); i < n; i++) {
				IToken token= fMatchers.get(i).evaluate(scanner, fBuffer);
				if (!token.isUndefined())
					return token;
			}

			if (fDefaultToken.isUndefined())
				unreadBuffer(scanner);

			return fDefaultToken;
		}
	}

	scanner.unread();
	return Token.UNDEFINED;
}
 
Example 4
Source File: SQLKeywordRule.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public IToken evaluate( ICharacterScanner scanner, boolean resume )
{
	int column = scanner.getColumn( );
	int iCh = ' ';//Default it to space. This will be checked if the column
	// is zero
	//First check whether we are at the first column
	if ( column > 0 )
	{
		//if not unread and read the character
		scanner.unread( );
		iCh = scanner.read( );
	}
	IToken tokenToReturn = Token.UNDEFINED;
	buf.setLength( 0 );
	//We should only apply this rule if we have a valid preceding character
	if ( isValidPrecedingCharacter( iCh ) )
	{
		do
		{
			//Read the character
			iCh = scanner.read( );
			//append it to the buffer
			buf.append( Character.toLowerCase( (char) iCh ) );
		} while ( isKeywordStart( buf.toString( ) )
				&& iCh != ICharacterScanner.EOF );
	}

	//Check whether there is anything in the buffer
	if ( buf.length( ) > 0 )
	{
		//System.out.println("buffer contains " + buf.toString());
		//Check whether the last character read was the EOF character
		//or a space character
		if ( isValidTerminatingCharacter( iCh ) )
		{
			//If the length of the buffer is greater than 1
			if ( buf.length( ) > 1 )
			{
				//Strip out the last character
				String sToCompare = buf.substring( 0, buf.length( ) - 1 );
				//System.out.println("String is " + sToCompare);

				//Now check whether it is a keyword
				if ( isKeyword( sToCompare ) )
				{
					scanner.unread( );
					tokenToReturn = token;
				}
			}
		}

		if ( tokenToReturn.isUndefined( ) )
		{
			//if the token is undefined
			//then just unread the buffer
			unreadBuffer( scanner );
		}
	}

	return tokenToReturn;
}