public XmlAttributeExpressionNode([NotNull] XmlValueExpressionNode name, XmlValueExpressionNode equal, [NotNull] XmlValueExpressionNode value, int start, int end) : base(start, end) { Should.NotBeNull(name, "name"); Should.NotBeNull(value, "value"); Name = name; Equal = equal; Value = value; }
public XmlAttributeExpressionNode([NotNull] XmlValueExpressionNode name, XmlValueExpressionNode equal, [NotNull] XmlValueExpressionNode value, int start, int end) : base(start, end) { Should.NotBeNull(name, nameof(name)); Should.NotBeNull(value, nameof(value)); Name = name; Equal = equal; Value = value; }
public XmlElementExpressionNode([NotNull] XmlValueExpressionNode startTag, string name, int start, int end) : base(start, end) { Should.NotBeNull(startTag, nameof(startTag)); Should.NotBeNull(name, nameof(name)); StartTag = startTag; _name = name; _elements = new List <XmlExpressionNode>(); _attributes = new List <XmlExpressionNode>(); }
protected override void AcceptInternal(IExpressionVisitor visitor) { StartTag = AcceptWithCheck(visitor, StartTag, true); if (StartTagEnd != null) { StartTagEnd = AcceptWithCheck(visitor, StartTagEnd, true); } if (EndTag != null) { EndTag = AcceptWithCheck(visitor, EndTag, true); } for (int i = 0; i < _elements.Count; i++) { XmlExpressionNode node = AcceptWithCheck(visitor, _elements[i], false); if (node == null) { _elements.RemoveAt(i); i--; } else { _elements[i] = node; } } for (int i = 0; i < _attributes.Count; i++) { XmlExpressionNode node = AcceptWithCheck(visitor, _attributes[i], false); if (node == null) { _attributes.RemoveAt(i); i--; } else { _attributes[i] = node; } } }
protected override void AcceptInternal(IExpressionVisitor visitor) { Name = AcceptWithCheck(visitor, Name, true); Equal = AcceptWithCheck(visitor, Equal, true); Value = AcceptWithCheck(visitor, Value, true); }
private XmlExpressionNode TryParseElement() { int startPosition = _tokenizer.FirstCharPosition; var tagEnd = _tokenizer.Position; _tokenizer.NextToken(false); if (!IsXmlIdentifier()) { var node = new XmlValueExpressionNode(XmlValueExpressionType.ElementStartTag, startPosition, tagEnd); return InvalidExpression(XmlInvalidExpressionType.Element, startPosition, node); } var startTag = new XmlValueExpressionNode(XmlValueExpressionType.ElementStartTag, startPosition, _tokenizer.Position); string nameString = _tokenizer.Value; _tokenizer.NextToken(true); var elementNode = new XmlElementExpressionNode(startTag, nameString, startPosition, -1); while (_tokenizer.Token != TokenType.Eof) { if (IsXmlIdentifier()) { XmlExpressionNode attribute = TryParseAttribute(elementNode); elementNode.AddAttribute(attribute); continue; } if (_tokenizer.Token == XmlTokens.CloseElement) { elementNode.UpdateCloseTag( new XmlValueExpressionNode(XmlValueExpressionType.ElementEndTag, _tokenizer.FirstCharPosition, _tokenizer.Position), _tokenizer.Position); _tokenizer.NextToken(false); return elementNode; } if (_tokenizer.Token == TokenType.GreaterThan) { elementNode.UpdateStartTagEnd(new XmlValueExpressionNode(XmlValueExpressionType.ElementStartTagEnd, _tokenizer.FirstCharPosition, _tokenizer.Position)); _tokenizer.NextToken(false); IList<XmlExpressionNode> nodes = TryParseElementValue(); for (int i = 0; i < nodes.Count; i++) elementNode.AddElement(nodes[i]); int closeElementPosition = _tokenizer.FirstCharPosition; if (_tokenizer.Token != XmlTokens.ComplexCloseElement) return InvalidExpression(XmlInvalidExpressionType.Element, startPosition, elementNode); _tokenizer.NextToken(false); if (_tokenizer.Value != nameString) return InvalidExpression(XmlInvalidExpressionType.Element, startPosition, elementNode); if (_tokenizer.NextToken(false) != TokenType.GreaterThan) return InvalidExpression(XmlInvalidExpressionType.Element, startPosition, elementNode); elementNode.UpdateCloseTag( new XmlValueExpressionNode(XmlValueExpressionType.ElementEndTag, closeElementPosition, _tokenizer.Position), _tokenizer.Position); _tokenizer.NextToken(false); return elementNode; } if (_tokenizer.Token == TokenType.Whitespace) _tokenizer.NextToken(true); return InvalidExpression(XmlInvalidExpressionType.Element, startPosition, elementNode); } return InvalidExpression(XmlInvalidExpressionType.Element, startPosition, elementNode); }
private XmlExpressionNode TryParseAttribute(XmlElementExpressionNode element) { int startPosition = _tokenizer.FirstCharPosition; var name = new XmlValueExpressionNode(element, XmlValueExpressionType.AttributeName, startPosition, _tokenizer.Position); if (_tokenizer.NextToken(true) != TokenType.Equal) return InvalidExpression(XmlInvalidExpressionType.Attribute, startPosition, EndElementTokens, name); var equal = new XmlValueExpressionNode(element, XmlValueExpressionType.AttributeEqual, name.End, _tokenizer.Position); if (_tokenizer.NextToken(true) != TokenType.StringLiteral) return InvalidExpression(XmlInvalidExpressionType.Attribute, startPosition, EndElementTokens, name, equal); var value = new XmlValueExpressionNode(XmlValueExpressionType.AttributeValue, _tokenizer.FirstCharPosition, _tokenizer.Position); int position = _tokenizer.Position; _tokenizer.NextToken(true); return new XmlAttributeExpressionNode(name, equal, value, startPosition, position); }
bool IXmlHandler.CanAutoComplete(bool textChanged) { var node = bindingEditor.GetNodeAt(bindingEditor.SelectionStart - 1); _lastValueNode = node as XmlValueExpressionNode; if (_lastValueNode != null) return _lastValueNode.Type == XmlValueExpressionType.ElementStartTag || _lastValueNode.Type == XmlValueExpressionType.AttributeName; if (textChanged) return false; var invalidExpressionNode = node as XmlInvalidExpressionNode; if (invalidExpressionNode != null && invalidExpressionNode.Nodes != null) _lastElement = invalidExpressionNode.Nodes.OfType<XmlElementExpressionNode>().FirstOrDefault(); else _lastElement = node as XmlElementExpressionNode; return _lastElement != null; }
protected override void AcceptInternal(IExpressionVisitor visitor) { StartTag = AcceptWithCheck(visitor, StartTag, true); if (StartTagEnd != null) StartTagEnd = AcceptWithCheck(visitor, StartTagEnd, true); if (EndTag != null) EndTag = AcceptWithCheck(visitor, EndTag, true); for (int i = 0; i < _elements.Count; i++) { XmlExpressionNode node = AcceptWithCheck(visitor, _elements[i], false); if (node == null) { _elements.RemoveAt(i); i--; } else _elements[i] = node; } for (int i = 0; i < _attributes.Count; i++) { XmlExpressionNode node = AcceptWithCheck(visitor, _attributes[i], false); if (node == null) { _attributes.RemoveAt(i); i--; } else _attributes[i] = node; } }
public void UpdateCloseTag([NotNull]XmlValueExpressionNode endTag, int endPosition) { Should.NotBeNull(endTag, nameof(endTag)); EndTag = endTag; UpdatePosition(Start, endPosition); }
protected override void AcceptInternal(IExpressionVisitor visitor) { Name = AcceptWithCheck(visitor, Name, true); Equal = AcceptWithCheck(visitor, Equal, true); Value = AcceptWithCheck(visitor, Value, true); }
public void UpdateStartTagEnd([NotNull] XmlValueExpressionNode startTagEnd) { Should.NotBeNull(startTagEnd, nameof(startTagEnd)); StartTagEnd = startTagEnd; }
public void UpdateCloseTag([NotNull] XmlValueExpressionNode endTag, int endPosition) { Should.NotBeNull(endTag, nameof(endTag)); EndTag = endTag; UpdatePosition(Start, endPosition); }