//TODO: XmlDecl //TODO: XmlDeclVersionInfo //TODO: XmlDeclEncodingDecl //TODO: XmlDeclSDDecl //TODO: XmlProcessingInstruction //TODO: XmlDocTypeDecl private List<AstNode> ParseXmlContent() { // XmlContent -> { XmlElement | xmlText }. List<AstNode> content = new List<AstNode>(); while (CurrentTokenIn(TokenType.XmlTagStart, TokenType.XmlText)) { if (CurrentTokenType == TokenType.XmlTagStart) { Token token = _scanner.PeekToken(1); //TODO: does this need to be here because it stops the parsing of "<" // // If no token follows then return the content list // if (token == null) // { // return content; // } if (token != null && token.Type == TokenType.XmlForwardSlash) { // The '<' starts a end tag so exit the loop of the parent element body // Return nodes created and do not process the closing tag return content; } // Parse this element content.Add(ParseXmlElement()); } else if (CurrentTokenType == TokenType.XmlText) { XmlTextNode xmlTextNode = new XmlTextNode(_scanner.CurrentToken.Image); xmlTextNode.Position = GetCurrentTokenPosition(); content.Add(xmlTextNode); _scanner.GetToken(); } //TODO write some comments if (content.Count == 0 || (content.Count == 0 && _scanner.EOF)) { AddError("The parser has been pre-emptively terminated because it appears " + "as if the parser is stuck. [In ParseXmlContent()]"); break; } } return content; }
private XmlAttribute ParseXmlAttribute() { // XmlAttribute -> XmlName "=" ( "\"" { xmlAttributeText | NVStatement } "\"" // | "'" { xmlAttributeText | NVStatement } "'" ). XmlAttribute xmlAttribute; //TODO: ParseXmlName instead of matching an XmlAttributeName if (CurrentTokenType == TokenType.XmlAttributeName) { xmlAttribute = new XmlAttribute(_scanner.CurrentToken.Image); _scanner.GetToken(); } else { AddError("Expected attribute name"); return null; } MatchToken(TokenType.XmlEquals); bool doubleQuotes; if (_scanner.CurrentToken != null && _scanner.CurrentToken.Type == TokenType.XmlDoubleQuote) { _scanner.GetToken(); doubleQuotes = true; } else if (_scanner.CurrentToken != null && _scanner.CurrentToken.Type == TokenType.XmlSingleQuote) { _scanner.GetToken(); doubleQuotes = false; } else { AddError("Expected quotes around attribute value."); return null; } while ((CurrentTokenType != TokenType.XmlDoubleQuote && doubleQuotes) || (CurrentTokenType != TokenType.XmlSingleQuote && !doubleQuotes)) { AstNode astNode; if (CurrentTokenType == TokenType.XmlAttributeText) { astNode = new XmlTextNode(_scanner.CurrentToken.Image); _scanner.GetToken(); } else if (CurrentTokenIn(TokenType.NVDirectiveHash, TokenType.NVDollar)) { astNode = ParseNVStatement(); } else { AddError("Expected XML attribute value or NVelocity statement."); break; } xmlAttribute.Content.Add(astNode); } //TODO: else if(CurrentTokenType == TokenType.XmlSingleQuote) if (doubleQuotes) { MatchToken(TokenType.XmlDoubleQuote); } else { MatchToken(TokenType.XmlSingleQuote); } return xmlAttribute; }