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

The following examples show how to use org.eclipse.jface.text.rules.ICharacterScanner#unread() . 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: CDataRule.java    From http4e with Apache License 2.0 6 votes vote down vote up
public IToken evaluate( ICharacterScanner scanner){

      buffer.setLength(0);

      charsRead = 0;
      int c = read(scanner);

      if (c == matchString.charAt(0)) {
         do {
            c = read(scanner);
         } while (isOK((char) c));

         if (charsRead == matchString.length()) {
            return fToken;
         } else {
            rewind(scanner);
            return Token.UNDEFINED;
         }

      }

      scanner.unread();
      return Token.UNDEFINED;
   }
 
Example 2
Source File: CaseInsensitiveMultiLineRule.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed)
{
	for (int i= 1; i < sequence.length; i++) {
		int c= scanner.read();
		if (c == ICharacterScanner.EOF && eofAllowed) {
			return true;
		} else if (Character.toLowerCase(c) != Character.toLowerCase(sequence[i])) {
			// Non-matching character detected, rewind the scanner back to the start.
			// Do not unread the first character.
			scanner.unread();
			for (int j= i-1; j > 0; j--)
				scanner.unread();
			return false;
		}
	}

	return true;
}
 
Example 3
Source File: FullPatternRule.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IToken evaluate(ICharacterScanner scanner) {
	int ch = scanner.read();
	for (int i = 0; i < possibleSequences.length; i++) {
		char[] sequence = possibleSequences[i];
		if(matchesSequence(scanner, ch, sequence)) {
			int endCh = scanner.read(); 
			scanner.unread(); // rewind end character
			if(endCh == ICharacterScanner.EOF || !ruleCancelWordDetector.isWordPart((char) endCh)) {
				return token;
			}
			
			// need to rewind scanner until first character
			scannerUnread(scanner, sequence.length-1);
		}
		
	}
	scanner.unread();
	return Token.UNDEFINED;
}
 
Example 4
Source File: JsniScanner.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean endSequenceDetected(ICharacterScanner scanner) {
  int c = 0, readCount = 1;
  while ((c = scanner.read()) != ICharacterScanner.EOF) {
    if (!isValidJavaRefCharacter((char) c)) {
      scanner.unread();
      return true;
    }
    readCount++;
  }

  while (--readCount > 0) {
    scanner.unread();
  }

  return super.endSequenceDetected(scanner);
}
 
Example 5
Source File: BibBraceRule.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Does the actual evaluation of the stream.
 * 
 * @param scanner The scanner
 * @param count The initial count of {
 * @return <code>fToken</code> on success, <code>Token.UNDEFINED</code> if
 * the match doesn't succeed
 */
private IToken doEvaluate(ICharacterScanner scanner, int count) {
    boolean inString = false;
    int c = scanner.read();

    if (((char) c) == '{') {
        do {
            c = scanner.read();
            if (((char) c) == '{' && !inString)
                count++;
            else if (((char) c) == '}' && !inString)
                count--;
            else if (((char) c) == '"' && !inString)
                inString = true;
            else if (((char) c) == '"' && inString)
                inString = false;
            else if (c == ICharacterScanner.EOF)
            	return Token.UNDEFINED;
        } while (count > 0);
        return fToken;
    }
    scanner.unread();
    return Token.UNDEFINED;
}
 
Example 6
Source File: MultiCharacterRule.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
	int index = 0;
	for (char c : sequence) {
		++index;
		if (c != scanner.read()) {
			for (int j = index; j > 0; --j) {
				scanner.unread();
			}
			return Token.UNDEFINED;
		}
	}
	return getSuccessToken();
}
 
Example 7
Source File: SQLKeywordRule.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param scanner
 */
private void unreadBuffer( ICharacterScanner scanner )
{
	for ( int i = buf.length( ) - 1; i >= 0; i-- )
	{
		scanner.unread( );
	}
}
 
Example 8
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.IRule#evaluate(org.eclipse.jface.text.rules.ICharacterScanner)
 * @param scanner 	the scanner to read characters
 * @return 			the success token if "\X" (X is one of the predefined 
 * 					characters) matches, Token.UNDEFINED otherwise
 */
public IToken evaluate(ICharacterScanner scanner) {
	int c= scanner.read();
	if (c == startChar){
		if (evaluateNext(scanner)) return successToken;
	}
	scanner.unread();
	return Token.UNDEFINED;
}
 
Example 9
Source File: SingleCharacterRule.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner, boolean resume)
{
	if (c == (char) scanner.read())
	{
		return getSuccessToken();
	}
	scanner.unread();
	return Token.UNDEFINED;
}
 
Example 10
Source File: JavaCodeScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean skipWhitespace(ICharacterScanner scanner) {
	while (fWhitespaceDetector.isWhitespace((char) scanner.read())) {
		// do nothing
	}

	scanner.unread();
	return true;
}
 
Example 11
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 12
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 (isOperator((char) character)) {
				do {
					character= scanner.read();
				} while (isOperator((char) character));
				scanner.unread();
				return fToken;
			} else {
				scanner.unread();
				return Token.UNDEFINED;
			}
		}
 
Example 13
Source File: DefaultPredicateRule.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected IToken currentOr(char altA, ICharacterScanner scanner) {
	int second = scanner.read();
	if(second == altA) {
		return getSuccessToken();
	}
	
	scanner.unread(); 
	return getSuccessToken();
}
 
Example 14
Source File: JSXScanner.java    From typescript.java with MIT License 4 votes vote down vote up
public IToken evaluate(ICharacterScanner scanner) {
	int offset = JSXScanner.this.fOffset;
	int startOffset = JSXScanner.this.startOffset;
	int localOffset = offset - startOffset;
	int rangeEnd = JSXScanner.this.fRangeEnd;

	// start/end tag
	int ch = scanner.read();
	switch (ch) {
	case '<':
		if (localOffset == 0) {
			// first character
			ch = scanner.read();
			if (ch == '/') {
				return tagBorder;
			}
			scanner.unread();
			return tagBorder;
		}
		break;
	case '>':
		if (offset == rangeEnd - 1) {
			// last character
			return tagBorder;
		}
		break;
	case '/':
		if (offset == rangeEnd - 2) {
			// last-1 character
			ch = scanner.read();
			if (ch == '>') {
				return tagBorder;
			}
			scanner.unread();
		}
		break;
	}

	// Tag name
	if (localOffset <= 2) {
		if (ch == '>') {
			//scanner.unread();
			return tagBorder;
		}
		loop: while (true) {
			switch (ch) {
			case ICharacterScanner.EOF:
			case 0x09:
			case 0x0A:
			case 0x0D:
			case 0x20:
			case '>':
				break loop;
			}

			ch = scanner.read();
			// firstCharIsSup = false;
		}

		if (ch == '>') {
			scanner.unread();
		}
		return tagName;
	}
	scanner.unread();
	return Token.UNDEFINED;
}
 
Example 15
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;
}
 
Example 16
Source File: InnerTagRule.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void unreadBuffer(ICharacterScanner scanner) {
	for (int i = fBuffer.length() - 1; i >= 0; i--)
		scanner.unread();
}
 
Example 17
Source File: FullPatternRule.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
protected static void scannerUnread(ICharacterScanner scanner, int count) {
	while(--count >= 0) {
		scanner.unread();
	}
}
 
Example 18
Source File: TLCCharScanner.java    From tlaplus with MIT License 4 votes vote down vote up
private  static boolean isChar(final ICharacterScanner scanner, int i) {
int c = scanner.read();
scanner.unread();
return c == i;
  }
 
Example 19
Source File: CombinedWordRule.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the characters in the buffer to the scanner.
 *
 * @param scanner the scanner to be used
 */
private void unreadBuffer(ICharacterScanner scanner) {
	for (int i= fBuffer.length() - 1; i >= 0; i--)
		scanner.unread();
}
 
Example 20
Source File: ExtendedWordRule.java    From APICloud-Studio with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the characters in the buffer to the scanner.
 * 
 * @param scanner
 *            the scanner to be used
 */
protected void unreadBuffer(ICharacterScanner scanner) {
	for (int i = buffer.length() - 1; i >= 0; --i) {
		scanner.unread();
	}
}