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

The following examples show how to use org.eclipse.jface.text.rules.ICharacterScanner#read() . 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: 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 2
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 3
Source File: ModulaCommentRule.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Evaluates Modula-2 comment rules. Resumes detection, i.e. look sonly for
 * the end comment required by this rule if the <code>resume</code> flag is set.
 *
 * @param scanner the character scanner to be used
 * @param resume <code>true</code> if detection should be resumed, <code>false</code> otherwise
 * @return the token resulting from this evaluation
 */
protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {
    if (! resume) {
        int c = scanner.read();
        if (c != '(') {
            scanner.unread();
            return Token.UNDEFINED;
        }
        c = scanner.read();
        if (c != '*') {
            scanner.unread();
            scanner.unread();
            return Token.UNDEFINED;
        }
    }
    endCommentDetected(scanner);
    return successToken;
}
 
Example 4
Source File: GoScanner.java    From goclipse with Eclipse Public License 1.0 6 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 ':':
	case ';':
	case '.':
	case '(':
	case ')':
	case '[':
	case ']':
	case '{':
	case '}':
		return getSuccessToken();
	default:
		scanner.unread(); 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: JavaCodeScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean readInterface(ICharacterScanner scanner) {
	int ch= scanner.read();
	int i= 0;
	while (i < INTERFACE.length() && INTERFACE.charAt(i) == ch) {
		i++;
		ch= scanner.read();
	}
	if (i < INTERFACE.length())
		return false;

	if (fWordDetector.isWordPart((char) ch))
		return false;

	if (ch != ICharacterScanner.EOF)
		scanner.unread();

	return true;
}
 
Example 7
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 8
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 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: 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 11
Source File: JavaCodeScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 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 12
Source File: CharSetRule.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 (charSet.contains((char)c)) {
        do {
            c = scanner.read();
        } while ((c != ICharacterScanner.EOF) && charSet.contains((char)c));
        scanner.unread();
        return successToken;
    }

    scanner.unread();
    return Token.UNDEFINED;
}
 
Example 13
Source File: TexEnvironmentRule.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns whether the end sequence was detected. *
 * 
 * @param scanner the character scanner to be used
 * @return <code>true</code> if the end sequence has been detected
 */
protected boolean endSequenceDetected(ICharacterScanner scanner) {
    int c;
    int readChar = 1;
    while ((c = scanner.read()) != ICharacterScanner.EOF) {
        readChar++;
        if (fEndSequence.length > 0 && c == fEndSequence[0]) {
            // Check if the specified end sequence has been found.
            if (sequenceDetected(scanner, fEndSequence))
                return true;
        }
    }
    unReadScanner(scanner, readChar);
    return false;
}
 
Example 14
Source File: DefaultPredicateRule.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean consume(char ch, ICharacterScanner scanner) {
	int next = scanner.read();
	if(next == ch) {
		return true;
	}
	scanner.unread();
	return false;
}
 
Example 15
Source File: TLCSingleLineRule.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
protected boolean endSequenceDetected(ICharacterScanner scanner) {
	while(true) {
		scanner.read();
		if(TLCCharScanner.isEOF(scanner)) {
			break;
		} else if (TLCCharScanner.isEOL(scanner)) {
			// EOL has to be consumed
			scanner.read();
			break;
		}
	}
	return true;
}
 
Example 16
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 17
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 18
Source File: XMLAttributeRule.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean wordOK(String word, ICharacterScanner scanner)
{
	char c = (char) scanner.read();
	
	// rewind since we're only performing lookahead
	scanner.unread();
	
	return c == '=';
}
 
Example 19
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 20
Source File: XMLTextPredicateRule.java    From http4e with Apache License 2.0 4 votes vote down vote up
private int read( ICharacterScanner scanner){
   int c = scanner.read();
   charsRead++;
   return c;
}