Esempio n. 1
0
        private void CreateTagSpans(ITextSnapshot snapshot)
        {
            var scanner = new TemplateScanner(snapshot.GetText());

            while (scanner.yylex() != (int)SyntaxKind.EOF)
            {
                SyntaxNode          token = scanner.yylval;
                IClassificationType classificationType;
                switch (token.Kind)
                {
                case SyntaxKind.BlockEnd:
                case SyntaxKind.ClassBlockStart:
                case SyntaxKind.DirectiveBlockStart:
                case SyntaxKind.ExpressionBlockStart:
                case SyntaxKind.StatementBlockStart:
                    classificationType = this.delimiterClassification;
                    break;

                case SyntaxKind.DirectiveName:
                    classificationType = this.directiveNameClassificaiton;
                    break;

                case SyntaxKind.AttributeName:
                    classificationType = this.attributeNameClassification;
                    break;

                case SyntaxKind.AttributeValue:
                    classificationType = this.attributeValueClassification;
                    break;

                case SyntaxKind.Code:
                    classificationType = this.codeBlockClassificaiton;
                    break;

                case SyntaxKind.Equals:
                case SyntaxKind.DoubleQuote:
                    // Ignore
                    continue;

                default:
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unexpected SyntaxKind value {0}.", token.Kind));
                }

                this.CreateTagSpan(snapshot.CreateTrackingSpan(token.Span, SpanTrackingMode.EdgeNegative), new ClassificationTag(classificationType));
            }
        }
Esempio n. 2
0
        private void ParseTextSnapshot(ITextSnapshot snapshot)
        {
            var scanner = new TemplateScanner(snapshot.GetText());

            var parser = new TemplateParser(scanner);

            parser.Parse();

            // Always return a template object, even if the parser couldn't build one, to avoid downstream errors.
            Template template = parser.Template ?? new Template();

            var errors = new List <TemplateError>(parser.Errors);

            errors.AddRange(template.Validate());

            this.OnTemplateChanged(new TemplateAnalysis(snapshot, template, errors));
        }