/// <summary>
            /// Initializes a new instance of the <see cref="WithTwoChildren"/> class from
            /// the specified binary reader.
            /// </summary>
            /// <param name="reader">The binary reader with which to deserialize the object.</param>
            /// <param name="version">The file version of the data being read.</param>
            private WithTwoChildren(BinaryReader reader, Int32 version)
                : base(reader, version)
            {
                this.child0 = reader.ReadSyntaxNode(version);
                ChangeParent(this.child0);

                this.child1 = reader.ReadSyntaxNode(version);
                ChangeParent(this.child1);
            }
        /// <summary>
        /// Initializes a new instance of the <see cref="SkippedTokensTriviaSyntax"/> class.
        /// </summary>
        /// <param name="tokens">The node that represents the skipped tokens.</param>
        public SkippedTokensTriviaSyntax(
            SyntaxNode tokens)
            : base(SyntaxKind.SkippedTokensTrivia)
        {
            this.Tokens = tokens;
            ChangeParent(tokens);

            this.SlotCount = 1;
            UpdateIsMissing();
        }
            /// <summary>
            /// Initializes a new instance of the <see cref="WithTwoChildren"/> class.
            /// </summary>
            /// <param name="child0">The list's first child.</param>
            /// <param name="child1">The list's second child.</param>
            internal WithTwoChildren(SyntaxNode child0, SyntaxNode child1)
            {
                SlotCount = 2;

                this.child0 = child0;
                ChangeParent(child0);

                this.child1 = child1;
                ChangeParent(child1);
            }
            /// <summary>
            /// Initializes a new instance of the <see cref="WithThreeChildren"/> class.
            /// </summary>
            /// <param name="child0">The list's first child.</param>
            /// <param name="child1">The list's second child.</param>
            /// <param name="child2">The list's third child.</param>
            internal WithThreeChildren(SyntaxNode child0, SyntaxNode child1, SyntaxNode child2)
            {
                SlotCount = 3;

                this.child0 = child0;
                ChangeParent(child0);

                this.child1 = child1;
                ChangeParent(child1);

                this.child2 = child2;
                ChangeParent(child2);
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Concatenates two syntax nodes into a single list.
        /// </summary>
        /// <param name="left">The left node.</param>
        /// <param name="right">The right node.</param>
        /// <returns>A node that represents the concatenation of the specified nodes.</returns>
        internal static SyntaxNode Concat(SyntaxNode left, SyntaxNode right)
        {
            if (left == null)
                return right;

            if (right == null)
                return left;

            var temp = default(ArrayElement<SyntaxNode>[]);
            var leftList = left as SyntaxList;
            var rightList = right as SyntaxList;

            if (leftList != null)
            {
                if (rightList != null)
                {
                    temp = new ArrayElement<SyntaxNode>[left.SlotCount + right.SlotCount];
                    leftList.CopyTo(temp, 0);
                    rightList.CopyTo(temp, left.SlotCount);
                    return List(temp);
                }

                temp = new ArrayElement<SyntaxNode>[left.SlotCount + 1];
                leftList.CopyTo(temp, 0);
                temp[left.SlotCount].Value = right;
                return List(temp);
            }

            if (rightList != null)
            {
                temp = new ArrayElement<SyntaxNode>[rightList.SlotCount + 1];
                temp[0].Value = left;
                rightList.CopyTo(temp, 1);
                return List(temp);
            }

            return List(left, right);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Changes the specified node's parent to this node.
        /// </summary>
        /// <param name="node">The node to update.</param>
        protected void ChangeParent(SyntaxNode node)
        {
            if (node == null || node.Parent == this)
                return;

            if (node.Parent != null)
                node.Parent.IsStale = true;

            node.Parent = this;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Changes the node's leading and trailing trivia.
        /// </summary>
        /// <param name="leading">The node's leading trivia.</param>
        /// <param name="trailing">The node's trailing trivia.</param>
        internal virtual void ChangeTrivia(SyntaxNode leading, SyntaxNode trailing)
        {
            var firstToken = GetFirstToken();
            if (firstToken != null)
                firstToken.ChangeLeadingTrivia(leading);

            var lastToken = GetLastToken();
            if (lastToken != null)
                lastToken.ChangeTrailingTrivia(trailing);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Changes the node's trailing trivia.
 /// </summary>
 /// <param name="trivia">The node's trailing trivia.</param>
 internal virtual void ChangeTrailingTrivia(SyntaxNode trivia)
 {
     var lastToken = GetLastToken();
     if (lastToken != null)
         lastToken.ChangeTrailingTrivia(trivia);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Changes the node's leading trivia.
 /// </summary>
 /// <param name="trivia">The node's leading trivia.</param>
 internal virtual void ChangeLeadingTrivia(SyntaxNode trivia)
 {
     var firstToken = GetFirstToken();
     if (firstToken != null)
         firstToken.ChangeLeadingTrivia(trivia);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Visits the specified syntax node.
 /// </summary>
 /// <param name="node">The node to visit.</param>
 /// <returns>A node which should replace the visited node, or a reference to the visited node
 /// itself if no changes were made.</returns>
 public virtual SyntaxNode VisitSyntaxNode(SyntaxNode node)
 {
     return node;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Styles the specified node.
        /// </summary>
        /// <param name="node">The node to style.</param>
        /// <param name="type">The classification type to apply to the node.</param>
        /// <param name="withLeadingTrivia">A value indicating whether to style the node's leading trivia.</param>
        /// <param name="withTrailingTrivia">A value indicating whether to style the node's trailing trivia.</param>
        private void Style(SyntaxNode node, IClassificationType type,
            Boolean withLeadingTrivia = false,
            Boolean withTrailingTrivia = false)
        {
            if (node == null || node.IsMissing || type == null)
                return;

            var start = node.Position + (withLeadingTrivia ? 0 : node.GetLeadingTriviaWidth());
            var width = node.FullWidth - (
                (withLeadingTrivia ? 0 : node.GetLeadingTriviaWidth()) +
                (withTrailingTrivia ? 0 : node.GetTrailingTriviaWidth()));

            classifier(start, width, type, node.Kind);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates a list with a single child.
 /// </summary>
 /// <param name="child">The list's child.</param>
 /// <returns>The list that was created.</returns>
 internal static SyntaxNode List(SyntaxNode child)
 {
     return child;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a list from the specified array.
        /// </summary>
        /// <param name="nodes">The array of nodes from which to create the list.</param>
        /// <param name="count">The number of nodes in the array to copy into the created list.</param>
        /// <returns>The list that was created.</returns>
        internal static SyntaxList List(SyntaxNode[] nodes, Int32 count)
        {
            var array = new ArrayElement<SyntaxNode>[count];
            for (int i = 0; i < count; i++)
                array[i].Value = nodes[i];

            return List(array);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates a list from the specified array.
 /// </summary>
 /// <param name="nodes">The array of nodes from which to create the list.</param>
 /// <returns>The list that was created.</returns>
 internal static SyntaxList List(SyntaxNode[] nodes)
 {
     return List(nodes, nodes.Length);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Creates a list with three children.
 /// </summary>
 /// <param name="child0">The list's first child.</param>
 /// <param name="child1">The list's second child.</param>
 /// <param name="child2">The list's third child.</param>
 /// <returns>The list that was created.</returns>
 internal static WithThreeChildren List(SyntaxNode child0, SyntaxNode child1, SyntaxNode child2)
 {
     return new WithThreeChildren(child0, child1, child2);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Gets a collection containing the specified trivia.
 /// </summary>
 private IEnumerable<SyntaxNode> DescendIntoTrivia(SyntaxNode trivia)
 {
     if (trivia.IsList)
     {
         for (int i = 0; i < trivia.SlotCount; i++)
         {
             var trivium = trivia.GetSlot(i);
             if (trivium != null)
                 yield return trivium;
         }
     }
     else
     {
         yield return trivia;
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Serializes a <see cref="SyntaxNode"/> instance to 
        /// the specified stream.
        /// </summary>
        /// <param name="writer">The binary writer with which to serialize the object.</param>
        /// <param name="node">The syntax node to serialize.</param>
        /// <param name="version">The file version of the data being written.</param>
        public static void ToStream(BinaryWriter writer, SyntaxNode node, Int32 version)
        {
            Contract.Require(writer, nameof(writer));
            Contract.Require(node, nameof(node));

            var typeID = default(Byte);
            if (!idByType.TryGetValue(node.GetType(), out typeID))
                throw new InvalidOperationException(UvssStrings.UnrecognizedSyntaxNodeType.Format(node.GetType().Name));

            writer.Write(typeID);

            node.Serialize(writer, version);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Creates a list with two children.
 /// </summary>
 /// <param name="child0">The list's first child.</param>
 /// <param name="child1">The list's second child.</param>
 /// <returns>The list that was created.</returns>
 internal static WithTwoChildren List(SyntaxNode child0, SyntaxNode child1)
 {
     return new WithTwoChildren(child0, child1);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Visits the specified syntax node.
        /// </summary>
        /// <param name="node">The syntax node to visit.</param>
        public void Visit(SyntaxNode node)
        {
            if (node == null)
                return;

            if (node is SyntaxToken)
                Visit(node.GetLeadingTrivia());

            switch (node.Kind)
            {
                case SyntaxKind.SingleLineCommentTrivia:
                case SyntaxKind.MultiLineCommentTrivia:
                    VisitCommentTrivia((StructurelessSyntaxTrivia)node);
                    break;

                case SyntaxKind.NumberToken:
                    VisitNumber((SyntaxToken)node);
                    break;

                case SyntaxKind.AnimationKeyword:
                case SyntaxKind.AsKeyword:
                case SyntaxKind.EventKeyword:
                case SyntaxKind.HandledKeyword:
                case SyntaxKind.ImportantKeyword:
                case SyntaxKind.KeyframeKeyword:
                case SyntaxKind.PlaySfxKeyword:
                case SyntaxKind.PlayStoryboardKeyword:
                case SyntaxKind.PropertyKeyword:
                case SyntaxKind.SetHandledKeyword:
                case SyntaxKind.SetKeyword:
                case SyntaxKind.TargetKeyword:
                case SyntaxKind.TransitionKeyword:
                case SyntaxKind.TriggerKeyword:
                    VisitKeyword((SyntaxToken)node);
                    break;

                case SyntaxKind.Selector:
                    VisitSelector((UvssSelectorSyntax)node);
                    break;

                case SyntaxKind.SelectorPart:
                case SyntaxKind.InvalidSelectorPart:
                    VisitSelectorPart((UvssSelectorPartBaseSyntax)node);
                    break;

                case SyntaxKind.PseudoClass:
                    VisitPseudoClass((UvssPseudoClassSyntax)node);
                    break;

                case SyntaxKind.Rule:
                    VisitRule((UvssRuleSyntax)node);
                    break;

                case SyntaxKind.EventName:
                    VisitEventName((UvssEventNameSyntax)node);
                    break;

                case SyntaxKind.PropertyName:
                    VisitPropertyName((UvssPropertyNameSyntax)node);
                    break;

                case SyntaxKind.PropertyValueToken:
                    VisitPropertyValueToken((SyntaxToken)node);
                    break;

                case SyntaxKind.Storyboard:
                    VisitStoryboard((UvssStoryboardSyntax)node);
                    break;

                case SyntaxKind.StoryboardTarget:
                    VisitStoryboardTarget((UvssStoryboardTargetSyntax)node);
                    break;

                case SyntaxKind.AnimationKeyframe:
                    VisitAnimationKeyframe((UvssAnimationKeyframeSyntax)node);
                    break;

                case SyntaxKind.NavigationExpression:
                    VisitNavigationExpression((UvssNavigationExpressionSyntax)node);
                    break;

                case SyntaxKind.UnknownDirective:
                    VisitUnknownDirective((UvssUnknownDirectiveSyntax)node);
                    break;

                case SyntaxKind.CultureDirective:
                    VisitCultureDirective((UvssCultureDirectiveSyntax)node);
                    break;
            }

            for (int i = 0; i < node.SlotCount; i++)
            {
                var child = node.GetSlot(i);
                if (child != null)
                {
                    Visit(child);
                }
            }

            if (node is SyntaxToken)
                Visit(node.GetTrailingTrivia());
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Visits the specified node.
 /// </summary>
 /// <param name="node">The node to visit.</param>
 /// <returns>A node which should replace the visited node, or a reference to the visited node
 /// itself if no changes were made.</returns>
 public virtual SyntaxNode Visit(SyntaxNode node)
 {
     return node?.Accept(this);
 }