Example #1
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;
  }
Example #2
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;
  }
  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;
  }
  public IToken evaluate(ICharacterScanner scanner) {
    // We need to back up to be able to detect the ' on the rule's label
    scanner.unread();
    int c = scanner.read();

    // We need to check for the start of the file.
    boolean bStartFile = false;
    if (c == -1) {
      bStartFile = true;
    }
    if (bStartFile == true || c != ICharacterScanner.EOF && fDetector.isWordStart((char) c)) {
      c = scanner.read();
      if ((fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1))
          && fDetector.isWordPart((char) c)) {

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

        // Changed to not have the substring because it doesn't
        // allow for single character agent names
        _fBuffer = new StringBuffer(_fBuffer); // .substring(1));
        String buffer = _fBuffer.toString().trim();
        int intPos = buffer.indexOf('\\');
        if (intPos != -1) {
          buffer = buffer.substring(intPos + 1);
        }
        IToken token = (IToken) fWords.get(buffer);

        if (buffer.length() != 0 && (char) c == '(') {
          // This is an agent.
          if (token == null) {
            Iterator iter = fWords.keySet().iterator();
            while (iter.hasNext()) {
              String key = (String) iter.next();
              if (buffer.equalsIgnoreCase(key)) {
                token = (IToken) fWords.get(key);
                break;
              }
            }
          }

          if (token != null) {
            return token;
          }
          if (fDefaultToken.isUndefined()) {
            unreadBuffer(scanner);
          }
          return fDefaultToken;
        }
      }
    } else {
      c = scanner.read();
    }
    scanner.unread();

    return Token.UNDEFINED;
  }
 private void scanToBeginOfLine(ICharacterScanner scanner) {
   while (scanner.getColumn() != 0) {
     scanner.unread();
   }
 }