nsXFormsXPathScanner::XPATHTOKEN
nsXFormsXPathScanner::NextToken()
{
  if (mState != WHITESPACE)
    mLast = mState;
  mOffset = mOffset + mLength;
  mLength = 0;

  PRUnichar c = PeekChar();
  if (c == '\0') {
    mState = XPATHEOF;
  } else if (nsXFormsXPathXMLUtil::IsDigit(c)) {
    mState = ScanNumber();
  } else if (c == '_' || nsXFormsXPathXMLUtil::IsLetter(c)) {
    mState = ScanQName();
  } else if (c == '"' || c == '\'') {
    mState = ScanLiteral();
  } else {
    switch (c) {
    case '(':
      mState = LPARAN;
      PopChar();
      break;
      
    case ')':
      mState = RPARAN;
      PopChar();
      break;
      
    case '[':
      mState = LBRACK;
      PopChar();
      break;
      
    case ']':
      mState = RBRACK;
      PopChar();
      break;
      
    case '@':
      mState = AT;
      PopChar();
      break;
      
    case ',':
      mState = COMMA;
      PopChar();
      break;
      
    case ':':
      PopChar();
      if (PeekChar() == ':') {
        mState = COLONCOLON;
        PopChar();
      } else
        mState = ERRORXPATHTOKEN;
      break;
      
    case '.':
      PopChar();
      if (PeekChar() == '.') {
        mState = DOTDOT;
        PopChar();
      } else if (nsXFormsXPathXMLUtil::IsDigit(PeekChar()))
        mState = ScanNumber();
      else
        mState = DOT;
      break;
      
    case '$':
      mState = ScanVariable();
      break;
      
    case '/':
      PopChar();
      if (PeekChar() == '/') {
        mState = SLASHSLASH;
        PopChar();
      } else
        mState = SLASH;
      break;
      
    case '|':
      PopChar();
      mState = UNION;
      break;
      
    case '+':
      PopChar();
      mState = PLUS;
      break;
      
    case '-':
      PopChar();
      mState = MINUS;
      break;
      
    case '=':
      PopChar();
      mState = EQUAL;
      break;
      
    case '!':
      PopChar();
      if (PeekChar() == '=') {
        mState = NOTEQUAL;
        PopChar();
      } else
        mState = ERRORXPATHTOKEN;
      break;
      
    case '<':
      PopChar();
      if (PeekChar() == '=') {
        mState = LEQUAL;
        PopChar();
      } else
        mState = LESS;
      break;
      
    case '>':
      PopChar();
      if (PeekChar() == '=') {
        mState = GEQUAL;
        PopChar();
      } else
        mState = GREATER;
      break;
      
    case '*':
      PopChar();
      mState = SolveStar();
      break;
      
    case '\r':
    case '\n':
    case '\t':
    case ' ':
      mState = ScanWhitespace();
      break;
      
    default:
      PopChar();
      mState = ERRORXPATHTOKEN;
    }
  }

  return mState;
}
Beispiel #2
0
Lexer::TokenType Lexer::NextToken()
{
	m_lastTokenRange = m_thisTokenRange;
	NextChar();

	// Skip blanks and comments
	SkipBlanks();
	SkipComments();

	// Start remembering this token
	int start = CharPosition();
	m_thisTokenRange.m_start = start;

	tp = m_token;
	char ch = m_cc;

	*tp++ = ch;

	if (!ch)
	{
		// Hit EOF straightaway - so be careful not to write another Null term into the token
		// as this would involve writing off the end of the token buffer
		m_tokenType = Eof;
		m_thisTokenRange.m_stop = start;
		m_thisTokenRange.m_start = start + 1;
	}
	else
	{
		if (isIdentifierFirst(ch))
		{
			ScanIdentifierOrKeyword();
		}

		else if (isdigit(ch))
		{
			ScanNumber();
		}

		else if (ch == '-' && isdigit(PeekAtChar()))
		{
			Step();
			ScanNumber();
			if (m_tokenType == SmallIntegerConst)
				m_integer *= -1;
		}
		else if (ch == LITERAL)
		{
			ScanLiteral();
		}

		else if (ch == STRINGDELIM)
		{
			int stringStart = CharPosition();
			// String constant; remove quote
			tp--;
			ScanString(stringStart);

			m_tokenType = StringConst;
		}

		else if (ch == CHARLITERAL)
		{
			ScanLiteralCharacter();
		}

		else if (ch == '^')
		{
			m_tokenType = Return;
		}

		else if (ch == ':')
		{
			if (PeekAtChar() == '=')
			{
				m_tokenType = Assignment;
				*tp++ = NextChar();
			}
			else
				m_tokenType = Special;
		}

		else if (ch == ')')
		{
			m_tokenType = CloseParen;
		}

		else if (ch == '.')
		{
			m_tokenType = CloseStatement;
		}

		else if (ch == ']')
		{
			m_tokenType = CloseSquare;
		}

		else if (ch == ';')
		{
			m_tokenType = Cascade;
		}

		else if (IsASingleBinaryChar(ch))
		{
			// Single binary expressions
			m_tokenType = Binary;
		}

		else if (isAnsiBinaryChar(ch))
		{
			m_tokenType = Binary;
		}
		else
		{
			int pos = CharPosition();
			CompileError(TEXTRANGE(pos, pos), LErrBadChar);
		}

		*tp = '\0';
	}

	m_thisTokenRange.m_stop = CharPosition();
	return m_tokenType;
}