Example #1
0
        private double ScanNumber()
        {
            Debug.Assert(this.CurerntChar == '.' || XmlCharType.IsDigit(this.CurerntChar));
            int start = xpathExprIndex - 1;
            int len   = 0;

            while (XmlCharType.IsDigit(this.CurerntChar))
            {
                NextChar(); len++;
            }
            if (this.CurerntChar == '.')
            {
                NextChar(); len++;
                while (XmlCharType.IsDigit(this.CurerntChar))
                {
                    NextChar(); len++;
                }
            }
            return(ToXPathDouble(this.xpathExpr.Substring(start, len)));
        }
Example #2
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);
                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 '\'':
                this.kind        = LexKind.String;
                this.stringValue = ScanString();
                break;

            default:
                if (XmlCharType.IsDigit(this.CurerntChar))
                {
                    kind        = LexKind.Number;
                    numberValue = ScanNumber();
                }
                else if (XmlCharType.IsStartNCNameChar(this.CurerntChar))
                {
                    kind        = LexKind.Name;
                    this.name   = ScanName();
                    this.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: "
                        {
                            this.prefix = this.name;
                            if (this.CurerntChar == '*')
                            {
                                NextChar();
                                this.name = "*";
                            }
                            else if (XmlCharType.IsStartNCNameChar(this.CurerntChar))
                            {
                                this.name = ScanName();
                            }
                            else
                            {
                                throw new XPathException(String.Format("'{0}' has an invalid qualified name.", SourceText));
                            }
                        }
                    }
                    else
                    {
                        SkipSpace();
                        if (this.CurerntChar == ':')
                        {
                            NextChar();
                            // it can be "foo ::" or just "foo :"
                            if (this.CurerntChar == ':')
                            {
                                NextChar();
                                kind = LexKind.Axe;
                            }
                            else
                            {
                                throw new XPathException(String.Format("'{0}' has an invalid qualified name.", SourceText));
                            }
                        }
                    }
                    SkipSpace();
                    this.canBeFunction = (this.CurerntChar == '(');
                }
                else
                {
                    throw new XPathException(String.Format("'{0}' has an invalid token.", SourceText));
                }
                break;
            }
            return(true);
        }