static bool IsInDeclarationContext(ParseItem current)
        {
            // exclude when not nested in rule block
            if (current is ControlDirectiveBody && (current.Parent == null || !(current.Parent.Parent is RuleBlock)))
                return false;

            return current is RuleBlock || current is NestedPropertyBlock;
        }
        private bool IsNestedSelector(ParseItem current)
        {
            while (current != null)
            {
                if (current is RuleBlock)
                    return true;

                current = current.Parent;
            }

            return false;
        }
        private SimpleSelector FindSelector(ParseItem item)
        {
            while (item != null)
            {
                if (item is SimpleSelector)
                    return item as SimpleSelector;

                item = item.Parent;
            }

            return null;
        }
 public virtual void Add(ParseItem item, ITextProvider text)
 {
     if (item is VariableDefinition)
     {
         AddVariable(item as VariableDefinition, text);
     }
     else if (item is BlockItem)
     {
         var block = item as BlockItem;
         Parse(new BlockScopeContainer(block), block.Children, text);
     }
 }
        static PropertyDeclaration FindDeclaration(ParseItem item)
        {
            while (item != null)
            {
                if (item is PropertyDeclaration)
                    return item as PropertyDeclaration;

                item = item.Parent;
            }

            return null;
        }
        static bool IsUnclosedVariable(ParseItem current)
        {
            while (current != null)
            {
                var definition = current as VariableDefinition;
                if (definition != null && definition.Semicolon == null)
                    return true;

                current = current.Parent;
            }

            return false;
        }
Ejemplo n.º 7
0
        public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream)
        {
            ParseItem item;
            if (itemFactory.TryCreateParsedOrDefault(this, text, stream, out item))
            {
                Value = item;
                Children.Add(item);
            }

            if (stream.Current.Type == TokenType.Comma)
                Comma = Children.AddCurrentAndAdvance(stream, SassClassifierType.Punctuation);

            return Children.Count > 0;
        }
Ejemplo n.º 8
0
        public override void Add(ParseItem item, ITextProvider text)
        {
            if (item is SassImportDirective)
            {
                var directive = item as SassImportDirective;
                foreach (var file in directive.Files.Where(x => x.IsValid))
                    Containers.Add(new ImportContainer(directive, IntellisenseManager.Get(file.Document)));
            }
            else if (item is XmlDocumentationComment)
            {
                var comment = item as XmlDocumentationComment;
                foreach (var tag in comment.Children.OfType<FileReferenceTag>().Where(x => x.Document != null))
                    Containers.Add(new ImportContainer(tag, IntellisenseManager.Get(tag.Document)));
            }
            else if (item is MixinDefinition)
            {
                var definition = item as MixinDefinition;
                if (definition.Name != null && definition.Name.Name != null)
                {
                    Parse(new MixinContainer(definition, text), definition.Children, text);

                    var name = text.GetText(definition.Name.Name.Start, definition.Name.Name.Length);
                    _Mixins.Add(definition.End, new MixinCompletionValue(name));
                }
            }
            else if (item is UserFunctionDefinition)
            {
                var definition = item as UserFunctionDefinition;
                if (definition.Name != null)
                {
                    Parse(new FunctionContainer(definition, text), definition.Children, text);

                    var name = text.GetText(definition.Name.Start, definition.Name.Length);
                    _Functions.Add(definition.End, new UserFunctionCompletionValue(name));
                }
            }
            else
            {
                base.Add(item, text);
            }
        }
Ejemplo n.º 9
0
 public void Add(ParseItem item, ITextProvider text)
 {
     throw new NotSupportedException("you can't add items to this type of container.");
 }
Ejemplo n.º 10
0
 public ImportContainer(ParseItem source, IIntellisenseCache cache)
 {
     Cache = cache;
     Start = source.Start;
     End = source.End;
 }
Ejemplo n.º 11
0
        private bool IsUnclosed(ParseItem current)
        {
            while (current != null)
            {
                if (current.IsUnclosed) return true;
                if (current is BlockItem) return false;

                current = current.Parent;
            }

            return false;
        }
 static bool IsDefinitionScope(ParseItem current)
 {
     return current is Stylesheet || current is BlockItem;
 }
Ejemplo n.º 13
0
        public bool TryCreate(ComplexItem parent, ITextProvider text, ITokenStream stream, out ParseItem item)
        {
            item = null;
            switch (stream.Current.Type)
            {
            case TokenType.EndOfFile:
                item = null;
                return(false);

            case TokenType.StartOfFile:
                item = Create <Stylesheet>(parent, text, stream);
                break;

            case TokenType.NewLine:
                item = new TokenItem();
                break;

            case TokenType.String:
            case TokenType.BadString:
                item = new StringValue();
                break;

            case TokenType.OpenCssComment:
                item = new CssComment();
                break;

            case TokenType.CppComment:
                item = new CppComment();
                break;

            case TokenType.OpenHtmlComment:
                item = new HtmlComment();
                break;

            case TokenType.At:
                item = CreateAtRule(parent, text, stream);
                break;

            case TokenType.Dollar:
                item = CreateVariableDefinitionOrReference(parent, text, stream);
                break;

            case TokenType.Bang:
                item = CreateBang(parent, text, stream);
                break;

            case TokenType.Function:
                item = CreateFunction(parent, text, stream);
                break;

            case TokenType.XmlDocumentationComment:
                item = new XmlDocumentationComment();
                break;

            case TokenType.Asterisk:
            case TokenType.GreaterThan:
            case TokenType.Tilde:
            case TokenType.Colon:
            case TokenType.DoubleColon:
            case TokenType.Ampersand:
            case TokenType.OpenBrace:
            case TokenType.Hash:
            case TokenType.Period:
            case TokenType.Identifier:
            case TokenType.OpenInterpolation:
                item = CreateBestFittingItem(parent, text, stream);
                break;
            }

            return(item != null);
        }
Ejemplo n.º 14
0
        public bool TryCreateParsed <T>(ComplexItem parent, ITextProvider text, ITokenStream stream, out ParseItem item) where T : ParseItem
        {
            item = null;

            if (ExternalItemFactory != null)
            {
                item = ExternalItemFactory.CreateItem(this, text, stream, parent, typeof(T));
            }

            if (item == null && TryCreate(parent, text, stream, out item))
            {
                if (!(item is T))
                {
                    item = null;
                }
            }

            if (item != null)
            {
                return(item.Parse(this, text, stream));
            }

            return(false);
        }
Ejemplo n.º 15
0
        public bool TryCreateParsedOrDefault(ComplexItem parent, ITextProvider text, ITokenStream stream, out ParseItem item)
        {
            if (!TryCreate(parent, text, stream, out item))
            {
                item = new TokenItem();
            }

            if (!item.Parse(this, text, stream))
            {
                item = null;
            }

            return(item != null);
        }