Java 类org.eclipse.jface.text.rules.ICharacterScanner 实例源码

项目:eclipse-batch-editor    文件:Counter.java   
boolean cleanupAndReturn(ICharacterScanner scanner, boolean result){
    if (result){
        return true; // do not clean up - pos is as wanted
    }
    if (count==0){
        return result;
    }
    if (count>0){
        while(count!=0){
            scanner.unread();
            count--;
        }
    }else{
        while(count!=0){
            scanner.read();
            count++;
        }
    }
    return false;
}
项目:eclipse-batch-editor    文件:AfterEchoDocumentRule.java   
@Override
public IToken evaluate(ICharacterScanner scanner1, boolean resume) {
    if (!(scanner1 instanceof BatchDocumentPartitionScanner)){
        return Token.UNDEFINED;
    }
    BatchDocumentPartitionScanner scanner = (BatchDocumentPartitionScanner)scanner1;
    if (scanner.getOffset()<ECHO.length()){
        /* would be a problem on start on going back...*/
        return Token.UNDEFINED;
    }
    scanner.unread(); // go to character before
    int charBeforeAsInt = scanner.read(); // get character, moves to origin pos again
    /* fast guard closing:*/
    if (charBeforeAsInt!='o' && charBeforeAsInt!='O'){ // echo ECHO <- last character must be an o other wise guard close...
        return Token.UNDEFINED;
    }
    ICharacterScannerCodePosSupport codePosSupport = new ICharacterScannerCodePosSupport(scanner);
    if (parserSupport.isAfterEchoHandled(codePosSupport)){
        return getSuccessToken();
    }
    codePosSupport.resetToStartPos();
    return Token.UNDEFINED;
}
项目:eclipse-bash-editor    文件:Counter.java   
boolean cleanupAndReturn(ICharacterScanner scanner, boolean result){
    if (result){
        return true; // do not clean up - pos is as wanted
    }
    if (count==0){
        return result;
    }
    if (count>0){
        while(count!=0){
            scanner.unread();
            count--;
        }
    }else{
        while(count!=0){
            scanner.read();
            count++;
        }
    }
    return false;
}
项目:eclipse-bash-editor    文件:HereStringRule.java   
@Override
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
    int r = scanner.read();
    scanner.unread();
    /* fast guard closing:*/
    if (ICharacterScanner.EOF==r || r!='<'){
        return Token.UNDEFINED;
    }

    ICharacterScannerCodePosSupport codePosSupport = new ICharacterScannerCodePosSupport(scanner);
    if (hereStringSupport.isHereStringStateHandled(codePosSupport)){
        return getSuccessToken();
    }
    codePosSupport.resetToStartPos();
    return Token.UNDEFINED;
}
项目:eclipse-bash-editor    文件:HereDocumentRule.java   
@Override
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
    int r = scanner.read();
    scanner.unread();
    /* fast guard closing:*/
    if (ICharacterScanner.EOF==r || r!='<'){
        return Token.UNDEFINED;
    }

    ICharacterScannerCodePosSupport codePosSupport = new ICharacterScannerCodePosSupport(scanner);
    if (hereDocSupport.isHereDocStateHandled(codePosSupport)){
        return getSuccessToken();
    }
    codePosSupport.resetToStartPos();
    return Token.UNDEFINED;
}
项目:Tarski    文件:RelationBoundsRule.java   
@Override
protected IToken doEvaluate(final ICharacterScanner scanner, final boolean resume) {

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

  scanner.unread();
  return Token.UNDEFINED;
}
项目:fluentmark    文件:IndentedCodeRule.java   
private boolean isList(ICharacterScanner scanner) {
    int n = scanner.read();
    if (isEol(n)) return false;                 // blank line

    if (n == '-' || n == '+' || n == '*') {
        // Log.error("List mark at " + getOffset(scanner));
        if (spaceFollows(scanner)) {            // skip unordered lists
            // Log.error("List item at " + getOffset(scanner));
            gotoBOL(scanner);                   // align, then consume the list
            gotoEOB(scanner);
            return true;
        }
        return false;
    }
    if (Character.isDigit(n)) {
        // Log.error("Digit mark at " + getOffset(scanner));
        if (isDigitSeq(scanner)) {      // skip ordered lists
            // Log.error("Digit item at " + getOffset(scanner));
            gotoBOL(scanner);           // align, then consume the list
            gotoEOB(scanner);
            return true;
        }
    }
    return false;
}
项目:egradle    文件:ExactWordPatternRule.java   
private boolean cleanupAndReturn(ICharacterScanner scanner, boolean result){
    if (result){
        return true; // do not clean up - pos is as wanted
    }
    if (count==0){
        return result;
    }
    if (count>0){
        while(count!=0){
            scanner.unread();
            count--;
        }
    }else{
        while(count!=0){
            scanner.read();
            count++;
        }
    }
    return false;
}
项目:http4e    文件:EscapedCharRule.java   
public IToken evaluate( ICharacterScanner scanner){

      buffer.setLength(0);

      int c = read(scanner);
      if (c == '&') {

         int i = 0;
         do {
            c = read(scanner);
            i++;

            if (c == '<' || c == ']') {
               for (int j = i - 1; j > 0; j--)
                  scanner.unread();
               return Token.UNDEFINED;
            }
         } while (c != ';');
         return fToken;
      }

      scanner.unread();
      return Token.UNDEFINED;
   }
项目:http4e    文件:CDataRule.java   
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;
   }
项目:http4e    文件:StartTagRule.java   
protected boolean sequenceDetected( ICharacterScanner scanner, char[] sequence, boolean eofAllowed){
   int c = scanner.read();
   if (sequence[0] == '<') {
      if (c == '?') {
         // processing instruction - abort
         scanner.unread();
         return false;
      }
      if (c == '!') {
         scanner.unread();
         // comment - abort
         return false;
      }
   } else if (sequence[0] == '>') {
      scanner.unread();
   }
   return super.sequenceDetected(scanner, sequence, eofAllowed);
}
项目:texlipse    文件:BibBraceRule.java   
/**
 * 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;
}
项目:ncl30-eclipse    文件:EscapedCharRule.java   
public IToken evaluate(ICharacterScanner scanner) {

        buffer.setLength(0);

        int c = read(scanner);
        if (c == '&') {

            int i = 0;
            do {
                c = read(scanner);
                i++;

                if (c == '<' || c == ']') {
                    for (int j = i - 1; j > 0; j--)
                        scanner.unread();
                    return Token.UNDEFINED;
                }
            } while (c != ';');
            return fToken;
        }

        scanner.unread();
        return Token.UNDEFINED;
    }
项目:ncl30-eclipse    文件:CDataRule.java   
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;
    }
项目:fluentmark    文件:IndentedCodeRule.java   
@Override
public IToken evaluate(ICharacterScanner scanner) {
    found = false;

    int c = scanner.read();
    scanner.unread();
    if (isHws(c)) {
        int col = scanner.getColumn();
        if (col == 1) {
            scanner.unread();
            int p = scanner.read();
            if (p == '\n') col = 0;
        }
        if (col == 0) {
            tabWidth = FluentMkUI.getDefault().getPreferenceStore().getInt(Prefs.EDITOR_TAB_WIDTH);
            if (tabWidth < 2) tabWidth = 4;
            line = 0;
            while (evaluateLine(scanner)) {
                found = true;
                line++;
            }
        }
    }
    if (found) return token;
    return Token.UNDEFINED;
}
项目:ncl30-eclipse    文件:StartTagRule.java   
protected boolean sequenceDetected(ICharacterScanner scanner,
        char[] sequence, boolean eofAllowed) {
    int c = scanner.read();
    if (sequence[0] == '<') {
        if (c == '?') {
            // processing instruction - abort
            scanner.unread();
            return false;
        }
        if (c == '!') {
            scanner.unread();
            // comment - abort
            return false;
        }
        if (c == '/') {
            // end tag
            scanner.unread();
            return false;
        }
    } else if (sequence[0] == '>') {
        scanner.unread();
    }
    return super.sequenceDetected(scanner, sequence, eofAllowed);
}
项目:fluentmark    文件:IndentedCodeRule.java   
private boolean gotoEOL(ICharacterScanner scanner, boolean consumeEOL) {
    boolean blank = true;
    int b = scanner.read();
    while (!isEol(b)) {
        blank = blank && Character.isWhitespace(b);
        b = scanner.read();
    }
    if (b == ICharacterScanner.EOF) scanner.unread();
    if (consumeEOL) {
        b = scanner.read();
        if (b == '\r') {
            b = scanner.read();
        }
        if (b == ICharacterScanner.EOF) scanner.unread();
    }
    return blank;
}
项目:fluentmark    文件:DotCodeRule.java   
@Override
public IToken evaluate(ICharacterScanner scanner) {
    int c = scanner.read();
    if (c != ICharacterScanner.EOF && 0 == scanner.getColumn() - 1) {
        try {
            if (dotStarts(scanner, c)) {
                gotoEOB(scanner, c);
                return getSuccessToken();
            }
        } catch (BadLocationException e) {
            Log.error("DotCodeRule", e);
        }
    }

    scanner.unread();
    return Token.UNDEFINED;
}
项目:fluentmark    文件:DotCodeRule.java   
private boolean gotoEOL(ICharacterScanner scanner, boolean consumeEOL) {
    int b = scanner.read();
    scanner.unread();
    while (!isEol(b)) {
        b = scanner.read();
    }
    if (b == ICharacterScanner.EOF) {
        scanner.unread();
        return false;
    }
    if (consumeEOL) {
        b = scanner.read();
        if (b == '\r') {
            b = scanner.read();
        }
        if (b == ICharacterScanner.EOF) {
            scanner.unread();
            return false;
        }
    }
    return true;
}
项目:fluentmark    文件:HtmlCodeRule.java   
@Override
public IToken evaluate(ICharacterScanner scanner) {
    int col = scanner.getColumn();
    if (col == 1) {
        scanner.unread();
        int p = scanner.read();
        if (p == '\n') col = 0;
    }

    try {
        if (col == 0) {
            String text = getScanText(scanner);
            if (tagStarts(text)) {
                gotoEOB(scanner);
                return getSuccessToken();
            }
        }
    } catch (BadLocationException e) {
        Log.error("HtmlCodeRule", e);
    }
    return Token.UNDEFINED;
}
项目:fluentmark    文件:HtmlCodeRule.java   
private boolean gotoEOL(ICharacterScanner scanner, boolean consumeEOL) {
    boolean blank = true;
    int b = scanner.read();
    while (!isEol(b)) {
        blank = blank && Character.isWhitespace(b);
        b = scanner.read();
    }
    if (b == ICharacterScanner.EOF) scanner.unread();
    if (consumeEOL) {
        b = scanner.read();
        if (b == '\r') {
            b = scanner.read();
        }
        if (b == ICharacterScanner.EOF) scanner.unread();
    }
    return blank;
}
项目:fluentmark    文件:FirstColumnRule.java   
@Override
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
    if (fColumn == UNDEFINED) return doEvaluate(scanner, resume);

    int c = scanner.read();
    scanner.unread();
    if (c == fStartSequence[0]) {
        int col = scanner.getColumn();
        if (col == 1) {
            scanner.unread();
            int p = scanner.read();
            if (p == '\n') col = 0;
        }
        return (fColumn == col ? doEvaluate(scanner, resume) : Token.UNDEFINED);
    }
    return Token.UNDEFINED;
}
项目:fluentmark    文件:MatchRule.java   
private boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean forward, boolean eofAllowed) {
    int c = scanner.read();
    if (c == ICharacterScanner.EOF) {
        if (forward) return false;
        return eofAllowed ? true : false;
    }
    scanner.unread();

    try {
        String txt = getScanText(scanner, 6, forward);
        String regex = String.valueOf(sequence);
        if (forward && txt.matches(regex + ".*")) {
            return true;
        }
        if (!forward && txt.matches(".*" + regex)) {
            return true;
        }
    } catch (BadLocationException e) {}
    return false;
}
项目:fluentmark    文件:MatchRule.java   
private String getScanText(ICharacterScanner scanner, int max, boolean forward) throws BadLocationException {
    IScannerExt scan = ((IScannerExt) scanner);
    IDocument doc = scan.getDocument();
    int beg;
    int end;
    int len;
    if (forward) {
        beg = scan.getOffset();
        end = scan.getRangeEnd();
        len = Math.min(max, end - beg);
    } else {
        end = scan.getOffset() + 1;
        beg = Math.max(0, end - max);
        len = end - beg;
    }
    return doc.get(beg, len);
}
项目:eclipse-batch-editor    文件:ExactWordPatternRule.java   
private int scannerRead(ICharacterScanner scanner, Counter counter) {
    int c = scanner.read();
    if (c==ICharacterScanner.EOF){
        return c;
    }
    counter.count++;
    if (trace){
        traceSb.append((char)c);
    }
    return c;

}
项目:eclipse-batch-editor    文件:ExactWordPatternRule.java   
private void scannerUnread(ICharacterScanner scanner, Counter counter) {
    scanner.unread();
    counter.count--;
    if (trace){
        int length = traceSb.length();
        if (length<1){
            traceSb.append("[(-1)]");
        }else{
            length=length-1;
            traceSb.setLength(length);
        }
    }
}
项目:eclipse-batch-editor    文件:ICharacterScannerCodePosSupport.java   
public ICharacterScannerCodePosSupport(ICharacterScanner scanner){
    this.scanner=scanner;
    this.counter=new Counter();
    // startPos start will always be 0. this is okay, here, because no tokens will be created so the information can start from 0 and
    // is okay. also an ICharacterScanner does not support real startPos handling but only forward and backward
    this.startPos=0;
    this.pos=-1;
}
项目:eclipse-batch-editor    文件:ICharacterScannerCodePosSupport.java   
@Override
public Character getCharacterAtPosOrNull(int pos) {
    moveToPos(pos);
    if (lastReadValue == ICharacterScanner.EOF){
        return null;
    }
    char lastCharacter = (char)lastReadValue;
    return Character.valueOf(lastCharacter);
}
项目:eclipse-batch-editor    文件:BatchStringRule.java   
protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {

        if (resume) {

            if (endSequenceDetected(scanner))
                return fToken;

        } else {
            int c= scanner.read();
            if (c == fStartSequence[0]) {
                scanner.unread();
                scanner.unread();
                int before = scanner.read();

                if (before=='\\'){
                    return Token.UNDEFINED;
                }
                scanner.read();

                if (sequenceDetected(scanner, fStartSequence, false)) {
                    if (endSequenceDetected(scanner))
                        return fToken;
                }
            }
        }

        scanner.unread();
        return Token.UNDEFINED;
    }
项目:eclipse-batch-editor    文件:VariableDefKeyWordPatternRule.java   
private int scannerRead(ICharacterScanner scanner, Counter counter) {
    int c = scanner.read();
    if (c==ICharacterScanner.EOF){
        return c;
    }
    counter.count++;
    if (trace){
        traceSb.append((char)c);
    }
    return c;

}
项目:eclipse-batch-editor    文件:VariableDefKeyWordPatternRule.java   
private void scannerUnread(ICharacterScanner scanner, Counter counter) {
    scanner.unread();
    counter.count--;
    if (trace){
        int length = traceSb.length();
        if (length<1){
            traceSb.append("[(-1)]");
        }else{
            length=length-1;
            traceSb.setLength(length);
        }
    }
}
项目:eclipse-batch-editor    文件:CommandParameterRule.java   
@Override
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
    char start = (char) scanner.read();
    if ('-' !=start) {
        scanner.unread();
        return Token.UNDEFINED;
    }

    /* check if the former character is a space - if not this is not an argument */
    scanner.unread();
    scanner.unread();
    char beforeStart = (char) scanner.read();
    if (' ' !=beforeStart){
        /* no unread necessary, scanner is at start start*/
        return Token.UNDEFINED;
    }
    /* go after start again*/
    scanner.read();

    /* okay could be a parameter*/
    do {
        char c = (char) scanner.read();
        if (! isPartOfParameter(c)) {
            scanner.unread();
            break;
        }
    } while (true);
    return getSuccessToken();
}
项目:eclipse-bash-editor    文件:ExactWordPatternRule.java   
private int scannerRead(ICharacterScanner scanner, Counter counter) {
    int c = scanner.read();
    if (c==ICharacterScanner.EOF){
        return c;
    }
    counter.count++;
    if (trace){
        traceSb.append((char)c);
    }
    return c;

}
项目:eclipse-bash-editor    文件:ExactWordPatternRule.java   
private void scannerUnread(ICharacterScanner scanner, Counter counter) {
    scanner.unread();
    counter.count--;
    if (trace){
        int length = traceSb.length();
        if (length<1){
            traceSb.append("[(-1)]");
        }else{
            length=length-1;
            traceSb.setLength(length);
        }
    }
}
项目:eclipse-bash-editor    文件:ICharacterScannerCodePosSupport.java   
public ICharacterScannerCodePosSupport(ICharacterScanner scanner){
    this.scanner=scanner;
    this.counter=new Counter();
    // startPos start will always be 0. this is okay, here, because no tokens will be created so the information can start from 0 and
    // is okay. also an ICharacterScanner does not support real startPos handling but only forward and backward
    this.startPos=0;
    this.pos=-1;
}
项目:eclipse-bash-editor    文件:ICharacterScannerCodePosSupport.java   
@Override
public Character getCharacterAtPosOrNull(int pos) {
    moveToPos(pos);
    if (lastReadValue == ICharacterScanner.EOF){
        return null;
    }
    char lastCharacter = (char)lastReadValue;
    return Character.valueOf(lastCharacter);
}
项目:eclipse-bash-editor    文件:VariableDefKeyWordPatternRule.java   
private int scannerRead(ICharacterScanner scanner, Counter counter) {
    int c = scanner.read();
    if (c==ICharacterScanner.EOF){
        return c;
    }
    counter.count++;
    if (trace){
        traceSb.append((char)c);
    }
    return c;

}
项目:eclipse-bash-editor    文件:VariableDefKeyWordPatternRule.java   
private void scannerUnread(ICharacterScanner scanner, Counter counter) {
    scanner.unread();
    counter.count--;
    if (trace){
        int length = traceSb.length();
        if (length<1){
            traceSb.append("[(-1)]");
        }else{
            length=length-1;
            traceSb.setLength(length);
        }
    }
}
项目:eclipse-bash-editor    文件:BashStringRule.java   
protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {

        if (resume) {

            if (endSequenceDetected(scanner))
                return fToken;

        } else {
            int c= scanner.read();
            if (c == fStartSequence[0]) {
                scanner.unread();
                scanner.unread();
                int before = scanner.read();

                if (before=='\\'){
                    return Token.UNDEFINED;
                }
                scanner.read();

                if (sequenceDetected(scanner, fStartSequence, false)) {
                    if (endSequenceDetected(scanner))
                        return fToken;
                }
            }
        }

        scanner.unread();
        return Token.UNDEFINED;
    }
项目:eclipse-bash-editor    文件:CommandParameterRule.java   
@Override
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
    char start = (char) scanner.read();
    if ('-' !=start) {
        scanner.unread();
        return Token.UNDEFINED;
    }

    /* check if the former character is a space - if not this is not an argument */
    scanner.unread();
    scanner.unread();
    char beforeStart = (char) scanner.read();
    if (' ' !=beforeStart){
        /* no unread necessary, scanner is at start start*/
        return Token.UNDEFINED;
    }
    /* go after start again*/
    scanner.read();

    /* okay could be a parameter*/
    do {
        char c = (char) scanner.read();
        if (! isPartOfParameter(c)) {
            scanner.unread();
            break;
        }
    } while (true);
    return getSuccessToken();
}