private double ScanFraction() { int startIndex = this.xpathExprIndex - 2; int length = 1; while (XmlCharType.IsDigit(this.CurerntChar)) { this.NextChar(); length++; } return(XmlConvert.ToXPathDouble(this.xpathExpr.Substring(startIndex, length))); }
private double ScanFraction() { Debug.Assert(XmlCharType.IsDigit(CurrentChar)); int start = _xpathExprIndex - 2; Debug.Assert(0 <= start && _xpathExpr[start] == '.'); int len = 1; // '.' while (XmlCharType.IsDigit(CurrentChar)) { NextChar(); len++; } return(XmlConvert.ToXPathDouble(_xpathExpr.Substring(start, len))); }
private double ScanNumber() { Debug.Assert(CurrentChar == '.' || XmlCharType.IsDigit(CurrentChar)); int start = _xpathExprIndex - 1; int len = 0; while (XmlCharType.IsDigit(CurrentChar)) { NextChar(); len++; } if (CurrentChar == '.') { NextChar(); len++; while (XmlCharType.IsDigit(CurrentChar)) { NextChar(); len++; } } return(XmlConvert.ToXPathDouble(_xpathExpr.Substring(start, len))); }
private double ScanNumber() { int startIndex = this.xpathExprIndex - 1; int length = 0; while (XmlCharType.IsDigit(this.CurerntChar)) { this.NextChar(); length++; } if (this.CurerntChar == '.') { this.NextChar(); length++; while (XmlCharType.IsDigit(this.CurerntChar)) { this.NextChar(); length++; } } return(XmlConvert.ToXPathDouble(this.xpathExpr.Substring(startIndex, length))); }
public bool NextLex() { SkipSpace(); switch (CurrentChar) { case '\0': _kind = LexKind.Eof; return(false); case ',': case '@': case '(': case ')': case '|': case '*': case '[': case ']': case '+': case '-': case '=': case '#': case '$': _kind = (LexKind)Convert.ToInt32(CurrentChar, CultureInfo.InvariantCulture); NextChar(); break; case '<': _kind = LexKind.Lt; NextChar(); if (CurrentChar == '=') { _kind = LexKind.Le; NextChar(); } break; case '>': _kind = LexKind.Gt; NextChar(); if (CurrentChar == '=') { _kind = LexKind.Ge; NextChar(); } break; case '!': _kind = LexKind.Bang; NextChar(); if (CurrentChar == '=') { _kind = LexKind.Ne; NextChar(); } break; case '.': _kind = LexKind.Dot; NextChar(); if (CurrentChar == '.') { _kind = LexKind.DotDot; NextChar(); } else if (XmlCharType.IsDigit(CurrentChar)) { _kind = LexKind.Number; _numberValue = ScanFraction(); } break; case '/': _kind = LexKind.Slash; NextChar(); if (CurrentChar == '/') { _kind = LexKind.SlashSlash; NextChar(); } break; case '"': case '\'': _kind = LexKind.String; _stringValue = ScanString(); break; default: if (XmlCharType.IsDigit(CurrentChar)) { _kind = LexKind.Number; _numberValue = ScanNumber(); } else if (XmlCharType.IsStartNCNameSingleChar(CurrentChar)) { _kind = LexKind.Name; _name = ScanName(); _prefix = string.Empty; // "foo:bar" is one lexeme not three because it doesn't allow spaces in between // We should distinct it from "foo::" and need process "foo ::" as well if (CurrentChar == ':') { NextChar(); // can be "foo:bar" or "foo::" if (CurrentChar == ':') { // "foo::" NextChar(); _kind = LexKind.Axe; } else { // "foo:*", "foo:bar" or "foo: " _prefix = _name; if (CurrentChar == '*') { NextChar(); _name = "*"; } else if (XmlCharType.IsStartNCNameSingleChar(CurrentChar)) { _name = ScanName(); } else { throw XPathException.Create(SR.Xp_InvalidName, SourceText); } } } else { SkipSpace(); if (CurrentChar == ':') { NextChar(); // it can be "foo ::" or just "foo :" if (CurrentChar == ':') { NextChar(); _kind = LexKind.Axe; } else { throw XPathException.Create(SR.Xp_InvalidName, SourceText); } } } SkipSpace(); _canBeFunction = (CurrentChar == '('); } else { throw XPathException.Create(SR.Xp_InvalidToken, SourceText); } break; } return(true); }
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 '\'': this.kind = LexKind.String; this.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; 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.IsStartNCNameSingleChar(this.CurerntChar) #if XML10_FIFTH_EDITION || xmlCharType.IsNCNameHighSurrogateChar(this.CurerntChar) #endif ) { this.name = ScanName(); } else { throw XPathException.Create(Res.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(Res.Xp_InvalidName, SourceText); } } } SkipSpace(); this.canBeFunction = (this.CurerntChar == '('); } else { throw XPathException.Create(Res.Xp_InvalidToken, SourceText); } break; } return(true); }
public bool NextLex() { this.SkipSpace(); switch (this.CurerntChar) { case '[': case ']': case '|': case '#': case '$': case '(': case ')': case '*': case '+': case ',': case '-': case '=': case '@': this.kind = (LexKind)Convert.ToInt32(this.CurerntChar, CultureInfo.InvariantCulture); this.NextChar(); break; case '!': this.kind = LexKind.Bang; this.NextChar(); if (this.CurerntChar == '=') { this.kind = LexKind.Ne; this.NextChar(); } break; case '"': case '\'': this.kind = LexKind.String; this.stringValue = this.ScanString(); break; case '.': this.kind = LexKind.Dot; this.NextChar(); if (this.CurerntChar != '.') { if (XmlCharType.IsDigit(this.CurerntChar)) { this.kind = LexKind.Number; this.numberValue = this.ScanFraction(); } } else { this.kind = LexKind.DotDot; this.NextChar(); } break; case '/': this.kind = LexKind.Slash; this.NextChar(); if (this.CurerntChar == '/') { this.kind = LexKind.SlashSlash; this.NextChar(); } break; case '<': this.kind = LexKind.Lt; this.NextChar(); if (this.CurerntChar == '=') { this.kind = LexKind.Le; this.NextChar(); } break; case '>': this.kind = LexKind.Gt; this.NextChar(); if (this.CurerntChar == '=') { this.kind = LexKind.Ge; this.NextChar(); } break; case '\0': this.kind = LexKind.Eof; return(false); default: if (XmlCharType.IsDigit(this.CurerntChar)) { this.kind = LexKind.Number; this.numberValue = this.ScanNumber(); } else { if (!this.xmlCharType.IsStartNCNameSingleChar(this.CurerntChar)) { throw XPathException.Create("Xp_InvalidToken", this.SourceText); } this.kind = LexKind.Name; this.name = this.ScanName(); this.prefix = string.Empty; if (this.CurerntChar == ':') { this.NextChar(); if (this.CurerntChar != ':') { this.prefix = this.name; if (this.CurerntChar != '*') { if (!this.xmlCharType.IsStartNCNameSingleChar(this.CurerntChar)) { throw XPathException.Create("Xp_InvalidName", this.SourceText); } this.name = this.ScanName(); } else { this.NextChar(); this.name = "*"; } } else { this.NextChar(); this.kind = LexKind.Axe; } } else { this.SkipSpace(); if (this.CurerntChar == ':') { this.NextChar(); if (this.CurerntChar != ':') { throw XPathException.Create("Xp_InvalidName", this.SourceText); } this.NextChar(); this.kind = LexKind.Axe; } } this.SkipSpace(); this.canBeFunction = this.CurerntChar == '('; } break; } return(true); }
public bool NextLex() { prevLexEnd = curIndex; SkipSpace(); lexStart = curIndex; switch (curChar) { case '\0': kind = LexKind.Eof; return(false); case ',': case '@': case '(': case ')': case '|': case '*': case '[': case ']': case '+': case '-': case '=': case '#': case '$': case '{': case '}': kind = (LexKind)curChar; NextChar(); break; case '<': kind = LexKind.Lt; NextChar(); if (curChar == '=') { kind = LexKind.Le; NextChar(); } break; case '>': kind = LexKind.Gt; NextChar(); if (curChar == '=') { kind = LexKind.Ge; NextChar(); } break; case '!': kind = LexKind.Bang; NextChar(); if (curChar == '=') { kind = LexKind.Ne; NextChar(); } break; case '.': kind = LexKind.Dot; NextChar(); if (curChar == '.') { kind = LexKind.DotDot; NextChar(); } else if (xmlCharType.IsDigit(curChar)) { ScanFraction(); } break; case '/': kind = LexKind.Slash; NextChar(); if (curChar == '/') { kind = LexKind.SlashSlash; NextChar(); } break; case '"': case '\'': ScanString(); break; default: if (xmlCharType.IsDigit(curChar)) { ScanNumber(); } else if (xmlCharType.IsStartNCNameChar(curChar)) { kind = LexKind.Name; this.name = ScanNCName(); this.prefix = string.Empty; int saveSourceIndex = curIndex; // "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 (curChar == ':') { NextChar(); // can be "foo:bar" or "foo::" if (curChar == ':') // "foo::" { NextChar(); kind = LexKind.Axis; } else // "foo:*", "foo:bar" or "foo: " { if (curChar == '*') { NextChar(); this.prefix = this.name; this.name = "*"; } else if (xmlCharType.IsStartNCNameChar(curChar)) { this.prefix = this.name; this.name = ScanNCName(); } else { // this lex is something like "foo:?". Let's it be recognized as name "foo" // and leave ":-" to be scaned late as unknown lex. SetSourceIndex(saveSourceIndex); } } } else { SkipSpace(); if (curChar == ':') { NextChar(); // it can be "foo ::" or just "foo :" if (curChar == ':') { NextChar(); kind = LexKind.Axis; } else { // this lex is something like "foo :?". Let's it be recognized as name "foo" // and leave ":-" to be scaned late as unknown lex. SetSourceIndex(saveSourceIndex); } } } // look ahead for '('. I don't want curIndex to be moved by SkipSpace() here to be able to detect presize lexem size. saveSourceIndex = curIndex; SkipSpace(); this.canBeFunction = (curChar == '('); SetSourceIndex(saveSourceIndex); } else { kind = LexKind.Unknown; NextChar(); } break; } return(true); }