private void HandleError(SourceContext context, string code, params string[] messageParameters) { if (this.errors == null) { return; } this.errors.Add(new ErrorNode(code, messageParameters) { SourceContext = context }); }
private Token GetNextToken(bool stopAtEndOfLine) { this.isWhitespace = false; switch (this.state) { case Scanner.State.StringLiteral1: case Scanner.State.StringLiteral2: if (this.endPos >= this.maxPos) { if (!stopAtEndOfLine) { this.HandleError(this.beginBlock, SR.UnclosedString, new string[0]); } return(Token.EndOfFile); } Token token1; if ((int)this.GetChar(this.endPos) == 38) { this.isWhitespace = false; token1 = this.ScanEntityReference(); } else { token1 = this.ScanXmlString(this.state == Scanner.State.StringLiteral1 ? '"' : '\'', true); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; } else { this.state = Scanner.State.Attributes; } } return(token1); case Scanner.State.Text: if (this.endPos >= this.maxPos) { return(Token.EndOfFile); } Token token2; if ((int)this.GetChar(this.endPos) == 38) { token2 = this.ScanEntityReference(); } else { token2 = this.ScanXmlText(stopAtEndOfLine); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; } else { this.state = Scanner.State.Xml; } } return(token2); case Scanner.State.LiteralComment: if (this.endPos >= this.maxPos) { if (!stopAtEndOfLine) { this.HandleError(this.beginBlock, SR.UnclosedComment, new string[0]); } return(Token.EndOfFile); } Token token3 = this.ScanXmlComment(stopAtEndOfLine); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; } else { this.state = Scanner.State.Xml; } return(token3); case Scanner.State.Xml: if (this.endPos >= this.maxPos) { return(Token.EndOfFile); } this.startPos = this.endPos; if (this.mode == Scanner.State.InternalSubset) { this.SkipWhitespace(); if (this.startPos < this.endPos) { this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); this.isWhitespace = true; return(Token.LiteralContentString); } if ((int)this.GetChar(this.endPos) == 93 && this.mode == Scanner.State.InternalSubset) { ++this.endPos; this.mode = Scanner.State.Xml; this.state = Scanner.State.Tag; return(Token.RightBracket); } } if ((int)this.GetChar(this.endPos) == 38) { return(this.ScanEntityReference()); } Token token4 = this.ScanXmlText(stopAtEndOfLine); if (this.startPos < this.endPos) { this.state = (int)this.GetChar(this.endPos) != 60 ? Scanner.State.Text : Scanner.State.Tag; return(token4); } this.isWhitespace = false; break; case Scanner.State.CData: if (this.endPos >= this.maxPos) { if (!stopAtEndOfLine) { this.HandleError(this.beginBlock, SR.UnclosedCData, new string[0]); } return(Token.EndOfFile); } Token token5 = this.ScanXmlCharacterData(stopAtEndOfLine); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; } else { this.state = Scanner.State.Xml; } return(token5); case Scanner.State.PI: if (this.endPos >= this.maxPos) { if (!stopAtEndOfLine) { this.HandleError(this.beginBlock, SR.UnclosedPI, new string[0]); } return(Token.EndOfFile); } Token token6 = this.ScanXmlProcessingInstructionsTag(stopAtEndOfLine); if (this.stillInsideMultiLineToken) { this.stillInsideMultiLineToken = false; if (token6 == Token.Identifier && this.unescapedString == "xml") { this.state = Scanner.State.Tag; } } else { this.state = Scanner.State.Xml; } return(token6); } this.startPos = this.endPos; char char1 = this.GetChar(this.endPos++); switch (char1) { case ':': this.unescapedString = ":"; return(Token.Colon); case '<': char char2 = this.GetChar(this.endPos); switch (char2) { case '/': this.GetChar(++this.endPos); this.state = Scanner.State.EndTag; this.unescapedString = "</"; return(Token.StartOfClosingTag); case '?': ++this.endPos; this.beginBlock = this.CurrentSourceContext; this.state = Scanner.State.PI; this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); return(Token.StartProcessingInstruction); case '!': char char3 = this.GetChar(++this.endPos); switch (char3) { case '-': if ((int)this.GetChar(++this.endPos) == 45) { ++this.endPos; this.beginBlock = this.CurrentSourceContext; this.state = Scanner.State.LiteralComment; this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); return(Token.StartLiteralComment); } --this.endPos; --this.endPos; break; case '[': if ((int)this.GetChar(this.endPos + 1) == 67 && (int)this.GetChar(this.endPos + 2) == 68 && ((int)this.GetChar(this.endPos + 3) == 65 && (int)this.GetChar(this.endPos + 4) == 84) && ((int)this.GetChar(this.endPos + 5) == 65 && (int)this.GetChar(this.endPos + 6) == 91)) { this.endPos += 7; this.beginBlock = this.CurrentSourceContext; this.state = Scanner.State.CData; this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); return(Token.StartCharacterData); } this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos); this.state = Scanner.State.Xml; this.HandleError(SR.ExpectingToken, "CDATA["); return(Token.IllegalCharacter); default: if (XmlCharType.IsStartNameChar(char3)) { this.state = Scanner.State.Tag; this.unescapedString = "<!"; if (this.mode != Scanner.State.InternalSubset) { this.mode = Scanner.State.DocType; } return(Token.MarkupDeclaration); } this.unescapedString = char3.ToString(); this.HandleError(SR.ExpectingToken, "DOCTYPE"); this.state = Scanner.State.Xml; return(Token.IllegalCharacter); } break; default: if (!XmlCharType.IsStartNameChar(char2)) { this.HandleError(SR.ExpectingTagName); this.state = Scanner.State.Xml; break; } this.unescapedString = "<"; this.state = Scanner.State.Tag; break; } return(Token.StartOfTag); case '=': this.state = Scanner.State.Attributes; this.unescapedString = "="; return(Token.Assign); case '>': this.unescapedString = ">"; Token token7 = this.state == Scanner.State.EndTag ? Token.EndOfEndTag : Token.EndOfTag; this.state = Scanner.State.Xml; if (this.mode == Scanner.State.DocType) { this.mode = Scanner.State.Xml; } return(token7); case '?': if ((int)this.GetChar(this.endPos) == 62) { ++this.endPos; this.unescapedString = "?>"; this.state = Scanner.State.Xml; return(Token.EndOfTag); } break; case '[': this.unescapedString = "["; this.mode = Scanner.State.InternalSubset; return(Token.LeftBracket); case ']': this.unescapedString = "]"; if ((int)this.GetChar(this.endPos) == 62) { this.unescapedString = "]"; this.state = Scanner.State.Tag; this.mode = Scanner.State.Xml; } return(Token.RightBracket); case '\'': case '"': this.LiteralQuoteChar = char1; this.unescapedString = char1.ToString(); this.state = (int)char1 == 34 ? Scanner.State.StringLiteral1 : Scanner.State.StringLiteral2; this.beginBlock = this.CurrentSourceContext; return(Token.StartStringLiteral); case '/': if ((int)this.GetChar(this.endPos) != 62) { return(Token.StringLiteral); } this.unescapedString = "/>"; ++this.endPos; this.state = Scanner.State.Xml; return(Token.EndOfSimpleTag); case char.MinValue: this.startPos = this.endPos; return(Token.EndOfFile); case '\t': case '\n': case '\r': case ' ': this.SkipWhitespace(); if (this.state != Scanner.State.EndTag) { this.state = Scanner.State.Attributes; } return(Token.Whitespace); } if (this.mode == Scanner.State.InternalSubset) { switch (char1) { case '#': this.unescapedString = "#"; return(Token.Pound); case '%': this.unescapedString = "%"; return(Token.Percent); case '(': this.unescapedString = "("; return(Token.LeftParen); case ')': this.unescapedString = ")"; return(Token.RightParen); case '*': this.unescapedString = "*"; return(Token.Star); case '+': this.unescapedString = "+"; return(Token.Plus); case ',': this.unescapedString = ","; return(Token.Comma); case '?': this.unescapedString = "?"; return(Token.QuestionMark); case '|': this.unescapedString = "|"; return(Token.Or); } } if (XmlCharType.IsNameChar(char1)) { --this.endPos; if (this.mode == Scanner.State.InternalSubset || this.mode == Scanner.State.DocType) { Token token8 = this.ScanKeyword(); if (token8 != Token.Identifier) { return(token8); } } this.ScanName(); if (this.lastToken != Token.Colon) { this.isXslKeyword = this.IsXslKeyword(); } return(Token.Identifier); } this.unescapedString = char1.ToString(); this.HandleError(SR.IllegalNameCharacter, new string[2] { char1.ToString(), Convert.ToInt32(char1).ToString() }); return(Token.IllegalCharacter); }