Esempio n. 1
0
        public bool NextLex()
        {
            SkipSpace();
            switch (this.CurerntChar)
            {
            case '\0':
                _kind = LexKind.Eof;
                return(false);

            case ',':
            case '@':
            case '(':
            case ')':
            case '|':
            case '*':
            case '[':
            case ']':
            case '+':
            case '-':
            case '=':
            case '#':
            case '$':
                _kind = (LexKind)Convert.ToInt32(this.CurerntChar, CultureInfo.InvariantCulture);
                NextChar();
                break;

            case '<':
                _kind = LexKind.Lt;
                NextChar();
                if (this.CurerntChar == '=')
                {
                    _kind = LexKind.Le;
                    NextChar();
                }
                break;

            case '>':
                _kind = LexKind.Gt;
                NextChar();
                if (this.CurerntChar == '=')
                {
                    _kind = LexKind.Ge;
                    NextChar();
                }
                break;

            case '!':
                _kind = LexKind.Bang;
                NextChar();
                if (this.CurerntChar == '=')
                {
                    _kind = LexKind.Ne;
                    NextChar();
                }
                break;

            case '.':
                _kind = LexKind.Dot;
                NextChar();
                if (this.CurerntChar == '.')
                {
                    _kind = LexKind.DotDot;
                    NextChar();
                }
                else if (XmlCharType.IsDigit(this.CurerntChar))
                {
                    _kind        = LexKind.Number;
                    _numberValue = ScanFraction();
                }
                break;

            case '/':
                _kind = LexKind.Slash;
                NextChar();
                if (this.CurerntChar == '/')
                {
                    _kind = LexKind.SlashSlash;
                    NextChar();
                }
                break;

            case '"':
            case '\'':
                _kind        = LexKind.String;
                _stringValue = ScanString();
                break;

            default:
                if (XmlCharType.IsDigit(this.CurerntChar))
                {
                    _kind        = LexKind.Number;
                    _numberValue = ScanNumber();
                }
                else if (_xmlCharType.IsStartNCNameSingleChar(this.CurerntChar)
#if XML10_FIFTH_EDITION
                         || xmlCharType.IsNCNameHighSurrogateChar(this.CurerntChar)
#endif
                         )
                {
                    _kind   = LexKind.Name;
                    _name   = ScanName();
                    _prefix = string.Empty;
                    // "foo:bar" is one lexem not three because it doesn't allow spaces in between
                    // We should distinct it from "foo::" and need process "foo ::" as well
                    if (this.CurerntChar == ':')
                    {
                        NextChar();
                        // can be "foo:bar" or "foo::"
                        if (this.CurerntChar == ':')
                        {       // "foo::"
                            NextChar();
                            _kind = LexKind.Axe;
                        }
                        else
                        {                              // "foo:*", "foo:bar" or "foo: "
                            _prefix = _name;
                            if (this.CurerntChar == '*')
                            {
                                NextChar();
                                _name = "*";
                            }
                            else if (_xmlCharType.IsStartNCNameSingleChar(this.CurerntChar)
#if XML10_FIFTH_EDITION
                                     || xmlCharType.IsNCNameHighSurrogateChar(this.CurerntChar)
#endif
                                     )
                            {
                                _name = ScanName();
                            }
                            else
                            {
                                throw XPathException.Create(ResXml.Xp_InvalidName, SourceText);
                            }
                        }
                    }
                    else
                    {
                        SkipSpace();
                        if (this.CurerntChar == ':')
                        {
                            NextChar();
                            // it can be "foo ::" or just "foo :"
                            if (this.CurerntChar == ':')
                            {
                                NextChar();
                                _kind = LexKind.Axe;
                            }
                            else
                            {
                                throw XPathException.Create(ResXml.Xp_InvalidName, SourceText);
                            }
                        }
                    }
                    SkipSpace();
                    _canBeFunction = (this.CurerntChar == '(');
                }
                else
                {
                    throw XPathException.Create(ResXml.Xp_InvalidToken, SourceText);
                }
                break;
            }
            return(true);
        }
        public void NextLex()
        {
            _prevLexEnd = _curIndex;
            _prevKind   = _kind;
            SkipSpace();
            _lexStart = _curIndex;

            switch (_curChar)
            {
            case '\0':
                _kind = LexKind.Eof;
                return;

            case '(':
            case ')':
            case '[':
            case ']':
            case '@':
            case ',':
            case '$':
            case '}':
                _kind = (LexKind)_curChar;
                NextChar();
                break;

            case '.':
                NextChar();
                if (_curChar == '.')
                {
                    _kind = LexKind.DotDot;
                    NextChar();
                }
                else if (IsAsciiDigit(_curChar))
                {
                    SetSourceIndex(_lexStart);
                    goto case '0';
                }
                else
                {
                    _kind = LexKind.Dot;
                }
                break;

            case ':':
                NextChar();
                if (_curChar == ':')
                {
                    _kind = LexKind.ColonColon;
                    NextChar();
                }
                else
                {
                    _kind = LexKind.Unknown;
                }
                break;

            case '*':
                _kind = LexKind.Star;
                NextChar();
                CheckOperator(true);
                break;

            case '/':
                NextChar();
                if (_curChar == '/')
                {
                    _kind = LexKind.SlashSlash;
                    NextChar();
                }
                else
                {
                    _kind = LexKind.Slash;
                }
                break;

            case '|':
                _kind = LexKind.Union;
                NextChar();
                break;

            case '+':
                _kind = LexKind.Plus;
                NextChar();
                break;

            case '-':
                _kind = LexKind.Minus;
                NextChar();
                break;

            case '=':
                _kind = LexKind.Eq;
                NextChar();
                break;

            case '!':
                NextChar();
                if (_curChar == '=')
                {
                    _kind = LexKind.Ne;
                    NextChar();
                }
                else
                {
                    _kind = LexKind.Unknown;
                }
                break;

            case '<':
                NextChar();
                if (_curChar == '=')
                {
                    _kind = LexKind.Le;
                    NextChar();
                }
                else
                {
                    _kind = LexKind.Lt;
                }
                break;

            case '>':
                NextChar();
                if (_curChar == '=')
                {
                    _kind = LexKind.Ge;
                    NextChar();
                }
                else
                {
                    _kind = LexKind.Gt;
                }
                break;

            case '"':
            case '\'':
                _kind = LexKind.String;
                ScanString();
                break;

            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                _kind = LexKind.Number;
                ScanNumber();
                break;

            default:
                if (_xmlCharType.IsStartNCNameSingleChar(_curChar)
#if XML10_FIFTH_EDITION
                    || xmlCharType.IsNCNameHighSurrogateChar(curChar)
#endif
                    )
                {
                    _kind          = LexKind.Name;
                    _name          = ScanNCName();
                    _prefix        = string.Empty;
                    _canBeFunction = false;
                    _axis          = XPathAxis.Unknown;
                    bool colonColon      = false;
                    int  saveSourceIndex = _curIndex;

                    // "foo:bar" or "foo:*" -- one lexeme (no spaces allowed)
                    // "foo::" or "foo ::"  -- two lexemes, reported as one (AxisName)
                    // "foo:?" or "foo :?"  -- lexeme "foo" reported
                    if (_curChar == ':')
                    {
                        NextChar();
                        if (_curChar == ':')
                        {       // "foo::" -> OperatorName, AxisName
                            NextChar();
                            colonColon = true;
                            SetSourceIndex(saveSourceIndex);
                        }
                        else
                        {                    // "foo:bar", "foo:*" or "foo:?"
                            if (_curChar == '*')
                            {
                                NextChar();
                                _prefix = _name;
                                _name   = "*";
                            }
                            else if (_xmlCharType.IsStartNCNameSingleChar(_curChar)
#if XML10_FIFTH_EDITION
                                     || xmlCharType.IsNCNameHighSurrogateChar(curChar)
#endif
                                     )
                            {
                                _prefix = _name;
                                _name   = ScanNCName();
                                // Look ahead for '(' to determine whether QName can be a FunctionName
                                saveSourceIndex = _curIndex;
                                SkipSpace();
                                _canBeFunction = (_curChar == '(');
                                SetSourceIndex(saveSourceIndex);
                            }
                            else
                            {                // "foo:?" -> OperatorName, NameTest
                                // Return "foo" and leave ":" to be reported later as an unknown lexeme
                                SetSourceIndex(saveSourceIndex);
                            }
                        }
                    }
                    else
                    {
                        SkipSpace();
                        if (_curChar == ':')
                        {       // "foo ::" or "foo :?"
                            NextChar();
                            if (_curChar == ':')
                            {
                                NextChar();
                                colonColon = true;
                            }
                            SetSourceIndex(saveSourceIndex);
                        }
                        else
                        {
                            _canBeFunction = (_curChar == '(');
                        }
                    }
                    if (!CheckOperator(false) && colonColon)
                    {
                        _axis = CheckAxis();
                    }
                }
                else
                {
                    _kind = LexKind.Unknown;
                    NextChar();
                }
                break;
            }
        }