/**
   * @see
   *     org.eclipse.jface.text.rules.IRule#evaluate(org.eclipse.jface.text.rules.ICharacterScanner)
   */
  @Override
  public IToken evaluate(ICharacterScanner scanner) {

    IToken token = super.evaluate(scanner);
    if (token == Token.UNDEFINED) {
      return token;
    }

    // check if the following character is a ( - which is an argument list
    // for a
    // function. if so then this is a function call name

    int cnt = 0;
    int ch;
    do {
      ch = scanner.read();
      cnt += 1;
    } while (fWhiteSpaceDetector.isWhitespace((char) ch));

    if (ch == '(') {

      // bingo !
      while (cnt > 0) {
        scanner.unread();
        cnt -= 1;
      }

      return token;
    }

    // not a function call, so this is not a valid presentation
    unreadBuffer(scanner);

    return Token.UNDEFINED;
  }
示例#2
0
  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] == '>') {
      //			if (c == '<')
      //			{
      //				scanner.unread();
      //				// comment - abort
      //				return false;
      //			}
      scanner.unread();
    }
    return super.sequenceDetected(scanner, sequence, eofAllowed);
  }
  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)) {
          char c1 = (char) scanner.read();
          if (c1 != ' ' && c1 != '\n') {
            if (c1 == fEndSequence[0]) {
              if (sequenceDetected(scanner, fStartSequence, false)) {
                scanner.unread();
                return Token.UNDEFINED;
              }
            }

            if (endSequenceDetected(scanner)) return fToken;
          }
          scanner.unread();
        }
      }
    }

    scanner.unread();
    return Token.UNDEFINED;
  }
示例#4
0
  protected boolean endSequenceDetected(ICharacterScanner scanner) {
    PartitionScanner partitionScanner = (PartitionScanner) scanner;
    int offset = partitionScanner.getTokenOffset();
    try {
      IDocument document = partitionScanner.getDocument();
      if ('\\' == document.getChar(offset - 1)) return false;
    } catch (BadLocationException e) {
    }

    int stack = 0;
    int readChars = 1;
    char c = (char) scanner.read();
    while (c != '\n') {
      if (c == '(') stack++;
      else if (c == ')') {
        if (stack <= 1) {
          return true;
        } else stack--;
      } else if (((int) c) == 65535) {
        break;
      }
      c = (char) scanner.read();
      readChars++;
    }
    for (int i = 0; i < readChars; i++) scanner.unread();
    return false;
  }
示例#5
0
  /**
   * Used to iterate over the " in the scanner as groovy can have """ for multi-line GString. If its
   * looking for the starting " then need to check for an empty string like "" or """""" in which
   * case just return a " indicatign the end of the scanning.
   *
   * @param scanner
   * @param checkForEmpty
   * @return
   */
  private char iterateBeginningForDoubleQuotes(ICharacterScanner scanner, char lastChar) {

    if (lastChar != '"') {
      lastChar = (char) scanner.read();
      buffer.append(lastChar);
      return lastChar;
    }

    int countQuotes = 1; // The last char is a " so start at 1
    while (lastChar == '"') {

      lastChar = (char) scanner.read();
      buffer.append(lastChar);

      if (lastChar == '"') {
        ++countQuotes;
      }
    }

    if ((countQuotes == 2 || countQuotes == 6)) {
      return '"'; // Signifies the end of the scanning
    }

    return lastChar;
  }
示例#6
0
  public IToken evaluate(ICharacterScanner scanner) {
    StringBuffer sb = new StringBuffer();
    int c = -1;

    int readCount = 0;
    while (true) {
      c = scanner.read();
      if (c == EOF) {
        scanner.unread();
        return Token.EOF;
      }
      sb.append((char) c);
      readCount++;
      if (!Character.isJavaIdentifierStart(c) && c != '<' && c != '>') {

        for (int j = 0; j < readCount; j++) {
          scanner.unread();
        }

        return Token.UNDEFINED;

      } else if (c == '>') {
        return fToken;
      }
    }
  }
  /**
   * @see
   *     org.eclipse.jface.text.rules.IRule#evaluate(org.eclipse.jface.text.rules.ICharacterScanner)
   */
  public IToken evaluate(ICharacterScanner scanner) {
    int ch = scanner.read();
    if (fChars.indexOf(ch) >= 0) {
      return fToken;
    }
    scanner.unread();

    return Token.UNDEFINED;
  }
 @SuppressWarnings("unused")
 private void scanToEndOfLine(ICharacterScanner scanner) {
   int c;
   char[][] delimiters = scanner.getLegalLineDelimiters();
   while ((c = scanner.read()) != ICharacterScanner.EOF) {
     // Check for end of line since it can be used to terminate the pattern.
     for (int i = 0; i < delimiters.length; i++) {
       if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i])) {
         return;
       }
     }
   }
 }
示例#9
0
 /* Copied from my superclass and modified to support case sensitivity. */
 protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {
   if (!ignoreCase) return super.doEvaluate(scanner, resume);
   if (resume) {
     if (endSequenceDetected(scanner)) return fToken;
   } else {
     int c = scanner.read();
     if (c == fStartSequence[0] || Character.toLowerCase((char) c) == fStartSequence[0]) {
       if (sequenceDetected(scanner, fStartSequence, false)) {
         if (endSequenceDetected(scanner)) return fToken;
       }
     }
   }
   scanner.unread();
   return Token.UNDEFINED;
 }
示例#10
0
 /*
  * @see org.eclipse.jface.text.rules.IRule#evaluate(org.eclipse.jface.text.rules.ICharacterScanner)
  */
 public IToken evaluate(ICharacterScanner scanner) {
   int character = scanner.read();
   if (character == '@') {
     while ((character = scanner.read()) != ICharacterScanner.EOF) {
       if (!Character.isJavaIdentifierPart(character)) {
         scanner.unread();
         break;
       }
     }
     return fToken;
   } else {
     scanner.unread();
     return Token.UNDEFINED;
   }
 }
示例#11
0
    @Override
    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;
      }
    }
示例#12
0
 public IToken evaluate(ICharacterScanner scanner) {
   Arrays.fill(candidates, true);
   int candidateCount = todoTags.length;
   int count = 0;
   int c;
   while ((c = scanner.read()) != ICharacterScanner.EOF) {
     for (int i = 0; i < todoTags.length; i++) {
       if (candidates[i]) {
         final char[] tag = todoTags[i];
         if (count < tag.length) {
           final boolean eq =
               caseSensitive ? c == tag[count] : Character.toUpperCase((char) c) == tag[count];
           if (!eq) {
             candidates[i] = false;
             --candidateCount;
             if (candidateCount == 0) {
               unreadScanner(scanner, count + 1);
               return Token.UNDEFINED;
             }
           }
         } else if (count == tag.length) {
           if (!Character.isJavaIdentifierPart((char) c)) {
             scanner.unread();
             return getSuccessToken();
           }
         }
       }
     }
     ++count;
     if (count == maxLength) {
       c = scanner.read();
       if (c != ICharacterScanner.EOF && !Character.isJavaIdentifierPart((char) c)) {
         c = ICharacterScanner.EOF;
       }
       scanner.unread();
       break;
     }
   }
   if (c == ICharacterScanner.EOF) {
     for (int i = 0; i < todoTags.length; i++) {
       if (candidates[i] && count == todoTags[i].length) {
         return getSuccessToken();
       }
     }
   }
   unreadScanner(scanner, count);
   return Token.UNDEFINED;
 }
示例#13
0
  public IToken evaluate(ICharacterScanner scanner) {
    if (scanner.getColumn() != 0) {
      return Token.UNDEFINED;
    }

    // Consume all leading spaces.
    StringBuffer spaces = readLeadingSpaces(scanner);

    // Consume the first two words.
    StringBuffer text = readWord(scanner);
    text.append(readWord(scanner));

    Iterator<Pattern> patterns = tokenLookup.keySet().iterator();
    while (patterns.hasNext()) {
      Pattern pattern = patterns.next();
      if (pattern == null) {
        continue;
      }

      // Is there a headline?
      Matcher matcher = pattern.matcher(text);
      if (matcher.lookingAt()) {
        // Yes. Consume the rest of the line.
        readLine(scanner);
        return tokenLookup.get(pattern);
      }
    }

    // There is no headline. Rewind the scanner.
    unread(scanner, spaces.length() + text.length());
    return Token.UNDEFINED;
  }
  private boolean sequenceDetected(ICharacterScanner scanner, char[] sequence) {
    for (int i = 1; i < sequence.length; i++) {
      int c = scanner.read();
      if (c == ICharacterScanner.EOF) {
        return true;
      } else if (c != sequence[i]) {
        // Non-matching character detected, rewind the scanner back to the start.
        for (; i > 0; i--) {
          scanner.unread();
        }
        return false;
      }
    }

    return true;
  }
示例#15
0
  public IToken evaluateKeyword(ICharacterScanner scanner, String[] m_parts) {

    int pos = 0;
    int partNo = 0;
    StringBuilder buffer = new StringBuilder();

    char c = (char) scanner.read();
    if (m_parts[partNo].charAt(pos) == c) {
      pos++;
      boolean cleanBuffer = false;
      boolean canContinue = true;
      boolean allowWhiteSpaces = false;
      do {
        buffer.append(c);
        c = (char) scanner.read();
        if (pos > m_parts[partNo].length() - 1) {
          // goto next partition
          partNo++;
          pos = 0;
          allowWhiteSpaces = true;
          if (partNo > m_parts.length - 1) {
            // everything is OK - time to exit
            canContinue = false;
            break;
          }
        }
        if (m_parts[partNo].charAt(pos) == c) {
          allowWhiteSpaces = false;
          pos++;
        } else if (!allowWhiteSpaces || !Character.isWhitespace(c)) {
          canContinue = false;
          cleanBuffer = true;
        }
      } while (canContinue);
      scanner.unread();
      if (cleanBuffer) {
        unreadBuffer(scanner, buffer.length());
      } else {
        preExit(scanner);
        return m_token;
      }
    } else {
      scanner.unread();
    }

    return Token.UNDEFINED;
  }
示例#16
0
 /* Copied from my superclass and modified to support case sensitivity. */
 protected boolean sequenceDetected(
     ICharacterScanner scanner, char[] sequence, boolean eofAllowed) {
   if (!ignoreCase) return super.sequenceDetected(scanner, sequence, eofAllowed);
   for (int i = 1; i < sequence.length; i++) {
     int c = scanner.read();
     if (c == ICharacterScanner.EOF && eofAllowed) {
       return true;
     } else if (c != sequence[i] || c != Character.toLowerCase((char) c)) {
       // 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;
 }
示例#17
0
  private char iterateEndForDoubleQuotes(ICharacterScanner scanner, char lastChar) {

    if (lastChar != '"') {
      return lastChar;
    }

    while (lastChar == '"') {

      lastChar = (char) scanner.read();
      if (lastChar == '"') {
        buffer.append(lastChar);
      } else {
        scanner.unread();
      }
    }

    return lastChar;
  }
  protected boolean endSequenceDetected(ICharacterScanner scanner) {

    char[][] originalDelimiters = scanner.getLegalLineDelimiters();
    int count = originalDelimiters.length;
    if (fLineDelimiters == null || originalDelimiters.length != count) {
      fSortedLineDelimiters = new char[count][];
    } else {
      while (count > 0 && fLineDelimiters[count - 1] == originalDelimiters[count - 1]) count--;
    }
    if (count != 0) {
      fLineDelimiters = originalDelimiters;
      System.arraycopy(fLineDelimiters, 0, fSortedLineDelimiters, 0, fLineDelimiters.length);
      Arrays.sort(fSortedLineDelimiters, fLineDelimiterComparator);
    }

    int readCount = 1;
    char c;
    char test;
    while ((c = (char) scanner.read()) != ICharacterScanner.EOF) {
      if (c == fEscapeCharacter) {
        // Skip escaped character(s)
        if (fEscapeContinuesLine) {
          c = (char) scanner.read();
          for (int i = 0; i < fSortedLineDelimiters.length; i++) {
            if (c == fSortedLineDelimiters[i][0]
                && sequenceDetected(scanner, fSortedLineDelimiters[i], true)) break;
          }
        } else scanner.read();

      } else if (fEndSequence.length > 0 && c == fEndSequence[0]) {
        // Check if the specified end sequence has been found.
        scanner.unread();
        scanner.unread();
        test = (char) scanner.read();
        scanner.read();
        if (sequenceDetected(scanner, fEndSequence, true)) {
          if (test != ' ') return true;
        }
      } else if (fBreaksOnEOL) {
        // Check for end of line since it can be used to terminate the pattern.
        for (int i = 0; i < fSortedLineDelimiters.length; i++) {
          if (c == fSortedLineDelimiters[i][0]
              && sequenceDetected(scanner, fSortedLineDelimiters[i], true)) return false;
        }
      }
      readCount++;
    }

    if (fBreaksOnEOF) return true;

    for (; readCount > 0; readCount--) scanner.unread();

    return false;
  }
示例#19
0
  public IToken evaluate(ICharacterScanner scanner) {

    String pattern = "[-@&#+]";

    int c = scanner.read();
    if (String.valueOf((char) c).matches(pattern)) {
      if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
        do {
          c = scanner.read();
        } while (String.valueOf((char) c).matches(pattern));

        scanner.unread();
        return fToken;
      }
    }

    scanner.unread();
    return Token.UNDEFINED;
  }
  protected boolean sequenceDetected(
      ICharacterScanner scanner, char[] sequence, boolean eofAllowed) {

    if (sequence[0] == '<') {
      CharacterScannerDeco decoScanner = new CharacterScannerDeco(scanner);
      if (decoScanner.firstMatch(new int[] {'<', '>'}) == '>') {
        int c = scanner.read();
        if (c == '!') {
          c = scanner.read();
          if (!Character.isUpperCase((char) c)) {
            scanner.unread();
            scanner.unread();
            return false;
          }
        }
      }
    }
    return super.sequenceDetected(scanner, sequence, eofAllowed);
  }
  public IToken evaluate(ICharacterScanner scanner, boolean resume) {
    boolean inExpression = false;
    int curlyDepth = 0;
    int c = scanner.read();
    int p = -1;
    int p2;

    if (c == '"') {
      if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
        IToken curToken = null;
        int count = 0;
        while (curToken == null && c != ICharacterScanner.EOF) {
          p2 = p;
          p = c;
          c = scanner.read();
          count++;

          if (p != '\\' || p2 == '\\') {
            if (c == '{') {
              if (p == '#') inExpression = true;
              if (inExpression) curlyDepth++;
            } else if (c == '}') {
              if (inExpression) {
                curlyDepth--;
                if (curlyDepth == 0) inExpression = false;
              }
            } else if (c == '"' && !inExpression) curToken = fToken;
          }
        }
        if (curToken != null) {
          return curToken;
        } else {
          while (count > 0) {
            scanner.unread();
            count--;
          }
        }
      }
    }
    scanner.unread();
    return Token.UNDEFINED;
  }
示例#22
0
  @Override
  public IToken evaluate(ICharacterScanner scanner) {
    int readNum = scanner.read();
    char c = (char) readNum;
    if (c != firstChar) {
      scanner.unread();
      return Token.UNDEFINED;
    }

    buffer.setLength(0);
    buffer.append(c);
    boolean stringStart = false;
    do {
      if (!stringStart && isStringIdentifier(c)) {

        // Could be a groovy GString formatted as """blah blah """
        // So iterate over them if necessary
        c = iterateBeginningForDoubleQuotes(scanner, c);
        stringStart = true;
      } else {
        readNum = scanner.read();
        c = (char) readNum;
        buffer.append(c);
      }

      // Must of located an end string so try and match
      // against the regex
      if (stringStart && isStringIdentifier(c)) {
        iterateEndForDoubleQuotes(
            scanner, c); // Get the full string including trailing " for GStrings
        Matcher matcher = regexPattern.matcher(buffer.toString());
        if (matcher.find()) {
          return token;
        } else {
          break;
        }
      }

    } while (readNum != ICharacterScanner.EOF);
    unread(scanner);
    return Token.UNDEFINED;
  }
 /**
  * @see
  *     org.jboss.ide.eclipse.freemarker.target.TargetMultiLineRule#sequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner,
  *     char[], boolean)
  */
 @Override
 protected boolean sequenceDetected(
     ICharacterScanner scanner, char[] sequence, boolean eofAllowed) {
   int c = scanner.read();
   if (sequence[0] == XmlLexicalConstants.LEFT_ANGLE_BRACKET) {
     if (c == XmlLexicalConstants.QUESTION_MARK) {
       // processing instruction - abort
       scanner.unread();
       return false;
     }
     if (c == XmlLexicalConstants.EXCLAMATION_MARK) {
       scanner.unread();
       // comment - abort
       return false;
     }
   } else if (sequence[0] == XmlLexicalConstants.RIGHT_ANGLE_BRACKET) {
     scanner.unread();
   }
   return super.sequenceDetected(scanner, sequence, eofAllowed);
 }
示例#24
0
  protected boolean sequenceDetected(
      ICharacterScanner scanner, char[] sequence, boolean eofAllowed) {
    if (sequence[0] == '<') {
      int c = scanner.read();
      if (c == '?' || c == '!' || c == '%') {
        scanner.unread();
        return false;
      }
    } else if (sequence[0] == '>') {
      // 前の1文字を読む
      scanner.unread();
      scanner.unread();
      int c = scanner.read();
      // 元に戻しておく
      scanner.read();

      if (c == '%') {
        return false;
      }
    }
    return super.sequenceDetected(scanner, sequence, eofAllowed);
  }
示例#25
0
  public static boolean isTag(final ICharacterScanner scanner, final String tag) {
    final int length = tag.length();

    int i = 0;
    for (; i < length; i++) {
      if (tag.charAt(i) != scanner.read()) {
        unwind(scanner, i + 1);
        return false;
      }
    }
    unwind(scanner, length);
    return true;
  }
示例#26
0
 /* Copied from my superclass and modified to support case sensitivity. */
 protected boolean endSequenceDetected(ICharacterScanner scanner) {
   if (!ignoreCase) return super.endSequenceDetected(scanner);
   int c;
   char[][] delimiters = scanner.getLegalLineDelimiters();
   while ((c = scanner.read()) != ICharacterScanner.EOF) {
     if (c == fEscapeCharacter) {
       // Skip the escaped character.
       scanner.read();
     } else if (fEndSequence.length > 0
         && (c == fEndSequence[0] || Character.toLowerCase((char) c) == fEndSequence[0])) {
       // Check if the specified end sequence has been found.
       if (sequenceDetected(scanner, fEndSequence, true)) return true;
     } else if (fBreaksOnEOL) {
       // Check for end of line since it can be used to terminate the pattern.
       for (int i = 0; i < delimiters.length; i++) {
         if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], false)) return true;
       }
     }
   }
   scanner.unread();
   return true;
 }
示例#27
0
  protected boolean endSequenceDetected(ICharacterScanner scanner) {

    int c;
    boolean doubleQuoted = false;
    boolean singleQuoted = false;

    char[][] delimiters = scanner.getLegalLineDelimiters();
    boolean previousWasEscapeCharacter = false;
    while ((c = scanner.read()) != ICharacterScanner.EOF) {
      if (c == fEscapeCharacter) {
        // Skip the escaped character.
        scanner.read();
      } else if (c == '"') {
        if (singleQuoted == false) {
          doubleQuoted = !doubleQuoted;
        }
      } else if (c == '\'') {
        if (doubleQuoted == false) {
          singleQuoted = !singleQuoted;
        }
      } else if (fEndSequence.length > 0 && c == fEndSequence[0]) {
        // Check if the specified end sequence has been found.
        if (doubleQuoted == false
            && singleQuoted == false
            && sequenceDetected(scanner, fEndSequence, true)) return true;
      } else if (fBreaksOnEOL) {
        // Check for end of line since it can be used to terminate the pattern.
        for (int i = 0; i < delimiters.length; i++) {
          if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], true)) {
            if (!fEscapeContinuesLine || !previousWasEscapeCharacter) return true;
          }
        }
      }
      previousWasEscapeCharacter = (c == fEscapeCharacter);
    }
    if (fBreaksOnEOF) return true;
    scanner.unread();
    return false;
  }
  protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {
    if (resume) {
      scanner.unread();
      int c = scanner.read();
      int f = 0;
      while (c != fStartSequence[0] || f != fStartSequence[1]) {
        scanner.unread();
        scanner.unread();
        f = c;
        c = scanner.read();
      }
      scanner.unread();
      c = scanner.read();
      if (c == fStartSequence[0]) {
        if (sequenceDetected(scanner, fStartSequence, false)) {

          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;
  }
示例#29
0
 @Override
 public IToken evaluate(ICharacterScanner scanner) {
   int c = scanner.read();
   if (c == '#') {
     c = scanner.read();
     int readCount = 2;
     if (c == sequence[0]) {
       for (int i = 1; i < sequence.length; i++) {
         if (sequence[i] != scanner.read()) {
           while (readCount-- > 0) {
             scanner.unread();
           }
           return Token.UNDEFINED;
         }
         readCount += 1;
       }
       return token;
     } else {
       scanner.unread();
     }
   }
   scanner.unread();
   return Token.UNDEFINED;
 }
示例#30
0
 private static void unwind(ICharacterScanner scanner, int i) {
   for (int j = 0; j < i; j++) {
     scanner.unread();
   }
 }