public void ParseXmlElementWithSingleQuotesAroundAttribute() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "<tag attr='value'/>"); TemplateNode template = parser.ParseTemplate(); // Template has 1 XML Element XmlElement xmlElement = (XmlElement)template.Content[0]; // Element has 1 Attribute Assert.AreEqual(1, xmlElement.Attributes.Count); XmlAttribute xmlAttribute = (XmlAttribute)xmlElement.Attributes[0]; Assert.AreEqual("attr", xmlAttribute.Name); // Element has 1 XML text node Assert.AreEqual(1, xmlAttribute.Content.Count); XmlTextNode xmlTextNode = (XmlTextNode)xmlAttribute.Content[0]; Assert.AreEqual("value", xmlTextNode.Text); AssertNoErrors(parser); }
public void XmlTextNodePosition() { Parser parser = GetNewParser("this is some text"); TemplateNode templateNode = parser.ParseTemplate(); // Check XmlTextNode position XmlTextNode xmlTextNode = (XmlTextNode)templateNode.Content[0]; AssertPosition(new Position(1, 1, 1, 18), xmlTextNode.Position); }
public void ParseXmlText() { Parser parser = GetNewParser("This is some XmlText"); TemplateNode template = parser.ParseTemplate(); // Template has 1 XML text node Assert.AreEqual(1, template.Content.Count); Assert.AreEqual(typeof(XmlTextNode), template.Content[0].GetType()); XmlTextNode xmlTextNode = (XmlTextNode)template.Content[0]; Assert.AreEqual("This is some XmlText", xmlTextNode.Text); AssertNoErrors(parser); }
//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); }
public void XmlElementWithXmlTextNodeInContentPosition() { Parser parser = GetNewParser("<element>some text</element>"); TemplateNode templateNode = parser.ParseTemplate(); // Check XmlElement position XmlElement xmlElement = (XmlElement)templateNode.Content[0]; AssertPosition(new Position(1, 1, 1, 29), xmlElement.Position); // Check XmlTextNode position XmlTextNode xmlTextNode = (XmlTextNode)xmlElement.Content[0]; AssertPosition(new Position(1, 10, 1, 19), xmlTextNode.Position); }
public void ReferenceFollowedByText() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$Ajax.InstallScripts() text\n text"); // ^ ^ TemplateNode templateNode = parser.ParseTemplate(); // XmlTextNode, it is only one text node XmlTextNode point1 = (XmlTextNode)templateNode.GetNodeAt(1, 24); XmlTextNode point2 = (XmlTextNode)templateNode.GetNodeAt(2, 2); AssertPosition(new Position(1, 23, 2, 13), point1.Position); AssertPosition(new Position(1, 23, 2, 13), point2.Position); }
public void ParseReferenceInBetweenXmlTextNodes() { Parser parser = GetNewParser( "text$first.second(100) text"); // ^ ^ ^ TemplateNode templateNode = parser.ParseTemplate(); // XmlTextNode XmlTextNode text1 = (XmlTextNode)templateNode.GetNodeAt(1, 4); AssertPosition(new Position(1, 1, 1, 5), text1.Position); // NVReference NVDesignator designator = (NVDesignator)templateNode.GetNodeAt(1, 6); AssertPosition(new Position(1, 5, 1, 23), designator.Position); // XmlTextNode XmlTextNode text2 = (XmlTextNode)templateNode.GetNodeAt(1, 24); AssertPosition(new Position(1, 23, 1, 28), text2.Position); }
public void ParseElementWithTextContent() { Parser parser = GetNewParser("<tag>text content</tag>"); TemplateNode template = parser.ParseTemplate(); // Template has 1 element Assert.AreEqual(1, template.Content.Count); Assert.AreEqual(typeof(XmlElement), template.Content[0].GetType()); XmlElement xmlElement = (XmlElement)template.Content[0]; Assert.AreEqual("tag", xmlElement.Name); Assert.AreEqual(false, xmlElement.IsSelfClosing); // With text content Assert.AreEqual(1, xmlElement.Content.Count); Assert.AreEqual(typeof(XmlTextNode), xmlElement.Content[0].GetType()); XmlTextNode xmlTextNode = (XmlTextNode)xmlElement.Content[0]; Assert.AreEqual("text content", xmlTextNode.Text); AssertNoErrors(parser); }
public void ParseXmlElementWithAttributes() { Parser parser = GetNewParser("<tag attr=\"value\"/>"); TemplateNode template = parser.ParseTemplate(); // Template has 1 XML Element XmlElement xmlElement = (XmlElement)template.Content[0]; // Element has 1 Attribute Assert.AreEqual(1, xmlElement.Attributes.Count); XmlAttribute xmlAttribute = (XmlAttribute)xmlElement.Attributes[0]; Assert.AreEqual("attr", xmlAttribute.Name); // Element has 1 XML text node Assert.AreEqual(1, xmlAttribute.Content.Count); XmlTextNode xmlTextNode = (XmlTextNode)xmlAttribute.Content[0]; Assert.AreEqual("value", xmlTextNode.Text); AssertNoErrors(parser); }
private void ReadBinaryText(XmlTextNode textNode, int length) { ReadText(textNode, ValueHandleType.Base64, length); }
private void ReadText(XmlTextNode textNode, ValueHandleType type, int length) { int offset = BufferReader.ReadBytes(length); textNode.Value.SetValue(type, offset, length); if (this.OutsideRootElement) VerifyWhitespace(); }
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); }