/// <summary>
        /// Compiles a <see cref="UvssSelector"/> from the specified syntax node.
        /// </summary>
        private static UvssSelector CompileSelector(UvssSelectorBaseSyntax selector)
        {
            var parts     = new List <UvssSelectorPart>();
            var qualifier = UvssSelectorPartQualifier.None;

            for (int i = 0; i < selector.Components.Count; i++)
            {
                var component = selector.Components[i];
                switch (component.Kind)
                {
                case SyntaxKind.SelectorPart:
                    {
                        var part = CompileSelectorPart((UvssSelectorPartSyntax)component, qualifier);
                        parts.Add(part);
                        qualifier = UvssSelectorPartQualifier.None;
                    }
                    break;

                case SyntaxKind.GreaterThanToken:
                    qualifier = UvssSelectorPartQualifier.VisualChild;
                    break;

                case SyntaxKind.GreaterThanGreaterThanToken:
                    qualifier = UvssSelectorPartQualifier.TemplatedChild;
                    break;

                case SyntaxKind.GreaterThanQuestionMarkToken:
                    qualifier = UvssSelectorPartQualifier.LogicalChild;
                    break;
                }
            }
            return(new UvssSelector(parts));
        }
Example #2
0
        /// <summary>
        /// Adds a diagnostic indicating that a selector is invalid
        /// to the specified collection of diagnostics.
        /// </summary>
        /// <param name="collection">The collection to which to add the diagnostic.</param>
        /// <param name="node">The syntax node which is associated with the diagnostic.</param>
        internal static void ReportInvalidSelector(ref ICollection <DiagnosticInfo> collection,
                                                   UvssSelectorBaseSyntax node)
        {
            Contract.Require(node, nameof(node));

            var span       = new TextSpan(0, node.Width);
            var diagnostic = new DiagnosticInfo(node, DiagnosticID.InvalidSelector,
                                                DiagnosticSeverity.Error, span, $"Invalid selector");

            Report(ref collection, diagnostic);
        }