Ejemplo n.º 1
0
        public void GetDiagnosticsFromNullToken()
        {
            var token = new SyntaxToken(null);

            Assert.Equal(Location.None, token.GetLocation());
            token.GetDiagnostics().Verify();
        }
        protected void WriteSyntaxToken(SyntaxToken syntaxToken)
        {
            WriteIndent();
            var diagnostics = syntaxToken.GetDiagnostics();
            var tokenString = $"{typeof(SyntaxKind).Name}.{syntaxToken.Kind};[{syntaxToken.Text}];{string.Join(", ", diagnostics.Select(diagnostic => diagnostic.Id + diagnostic.Span))}";

            Write(tokenString);
        }
Ejemplo n.º 3
0
        private static string GetTokenContent(SyntaxToken token)
        {
            var content     = token.IsMissing ? "<Missing>" : token.Content;
            var diagnostics = token.GetDiagnostics();
            var tokenString = $"{typeof(SyntaxKind).Name}.{token.Kind};[{content}];{string.Join(", ", diagnostics.Select(diagnostic => diagnostic.Id + diagnostic.Span))}";

            return(tokenString);
        }
Ejemplo n.º 4
0
        private void WriteToken(SyntaxToken token)
        {
            WriteIndent();
            var content     = token.IsMissing ? "<Missing>" : token.Content;
            var diagnostics = token.GetDiagnostics();
            var tokenString = $"{token.Kind};[{content}];{string.Join(", ", diagnostics.Select(diagnostic => diagnostic.Id + diagnostic.Span))}";

            Write(tokenString);
        }
Ejemplo n.º 5
0
        protected internal void Accept(SyntaxToken token)
        {
            if (token != null)
            {
                foreach (var error in token.GetDiagnostics())
                {
                    Context.ErrorSink.OnError(error);
                }

                TokenBuilder.Add(token);
            }
        }
Ejemplo n.º 6
0
        public virtual Tuple <SyntaxToken, SyntaxToken> SplitToken(SyntaxToken token, int splitAt, SyntaxKind leftType)
        {
            var left = CreateToken(token.Content.Substring(0, splitAt), leftType, RazorDiagnostic.EmptyArray);

            SyntaxToken right = null;

            if (splitAt < token.Content.Length)
            {
                right = CreateToken(token.Content.Substring(splitAt), token.Kind, token.GetDiagnostics());
            }

            return(Tuple.Create(left, right));
        }
        private static void ProcessMultiLineRawStringLiteralToken(
            SourceText text, SyntaxToken token, ArrayBuilder <StringIndentationRegion> result, CancellationToken cancellationToken)
        {
            // Ignore strings with errors as we don't want to draw a line in a bad place that makes things even harder
            // to understand.
            if (token.ContainsDiagnostics && token.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error))
            {
                return;
            }

            cancellationToken.ThrowIfCancellationRequested();
            if (!TryGetIndentSpan(text, (ExpressionSyntax)token.GetRequiredParent(), out _, out var indentSpan))
            {
                return;
            }

            result.Add(new StringIndentationRegion(indentSpan));
        }
Ejemplo n.º 8
0
        protected internal void Accept(SyntaxToken token)
        {
            if (token != null)
            {
                if (token.Kind == SyntaxKind.NewLine)
                {
                    Context.StartOfLine = true;
                }
                else if (token.Kind != SyntaxKind.Whitespace)
                {
                    Context.StartOfLine = false;
                }

                foreach (var error in token.GetDiagnostics())
                {
                    Context.ErrorSink.OnError(error);
                }

                TokenBuilder.Add(token);
            }
        }