예제 #1
0
 public override VB.VisualBasicSyntaxNode VisitXmlNameAttribute(CSS.XmlNameAttributeSyntax node)
 {
     var Name = ((VBS.XmlNodeSyntax)node.Name.Accept(this));
     string ValueString = node.Identifier.ToString();
     VBS.XmlNodeSyntax Value = VBFactory.XmlString(global::VisualBasicSyntaxFactory.DoubleQuoteToken, SyntaxTokenList.Create(VBFactory.XmlTextLiteralToken(ValueString, ValueString)), global::VisualBasicSyntaxFactory.DoubleQuoteToken);
     return VBFactory.XmlAttribute(Name, Value);
 }
예제 #2
0
 public override VB.VisualBasicSyntaxNode VisitXmlTextAttribute(CSS.XmlTextAttributeSyntax node)
 {
     VBS.XmlNodeSyntax Name = (VBS.XmlNodeSyntax)node.Name.Accept(this);
     var TextTokens = DestVisualBasic.TriviaListSupport.TranslateTokenList(node.TextTokens);
     var XmlText = VBFactory.XmlText(TextTokens);
     VBS.XmlNodeSyntax Value = VBFactory.XmlString(global::VisualBasicSyntaxFactory.DoubleQuoteToken, SyntaxTokenList.Create(VBFactory.XmlTextLiteralToken(XmlText.ToString(), XmlText.ToString())), global::VisualBasicSyntaxFactory.DoubleQuoteToken);
     return VBFactory.XmlAttribute(Name, Value);
 }
예제 #3
0
        public override VB.VisualBasicSyntaxNode VisitXmlCrefAttribute(CSS.XmlCrefAttributeSyntax node)
        {
            VBS.XmlNameSyntax Name = (VBS.XmlNameSyntax)node.Name.Accept(this);

            var cref = node.Cref.Accept(this);
            var SyntaxTokens = new SyntaxTokenList();
            SyntaxTokens = SyntaxTokens.AddRange(cref.DescendantTokens());
            VBS.XmlNodeSyntax Value = VBFactory.XmlString(global::VisualBasicSyntaxFactory.DoubleQuoteToken, SyntaxTokens, global::VisualBasicSyntaxFactory.DoubleQuoteToken);
            return VBFactory.XmlAttribute(Name, Value);
        }
예제 #4
0
        public override VB.VisualBasicSyntaxNode VisitXmlElement(CSS.XmlElementSyntax node)
        {
            var Content = new SyntaxList <VBS.XmlNodeSyntax>();

            VBS.XmlElementStartTagSyntax StartTag = (VBS.XmlElementStartTagSyntax)node.StartTag.Accept(this);

            bool NoEndTag = string.IsNullOrWhiteSpace(node.EndTag.Name.LocalName.ValueText);
            var  EndTag   = NoEndTag ? VBFactory.XmlElementEndTag(((VBS.XmlNameSyntax)StartTag.Name)) : VBFactory.XmlElementEndTag((VBS.XmlNameSyntax)node.EndTag.Name.Accept(this));

            try
            {
                for (int i = 0, loopTo = node.Content.Count - 1; i <= loopTo; i++)
                {
                    var C = node.Content[i];
                    VBS.XmlNodeSyntax Node1 = (VBS.XmlNodeSyntax)C.Accept(this);
                    if (NoEndTag)
                    {
                        var LastToken = Node1.GetLastToken();
                        if (LastToken.ValueText.IsNewLine())
                        {
                            Node1 = Node1.ReplaceToken(LastToken, default(SyntaxToken));
                        }
                    }
                    Content = Content.Add(Node1);
                }

                if (node.EndTag?.HasLeadingTrivia == true && node.EndTag.GetLeadingTrivia()[0].IsKind(CS.SyntaxKind.DocumentationCommentExteriorTrivia) == true)
                {
                    var NewLeadingTriviaList = new SyntaxTriviaList();
                    NewLeadingTriviaList = NewLeadingTriviaList.Add(VBFactory.DocumentationCommentExteriorTrivia(node.EndTag.GetLeadingTrivia()[0].ToString().Replace("///", "'''")));
                    var NewTokenList = new SyntaxTokenList();
                    NewTokenList = NewTokenList.Add(VBFactory.XmlTextLiteralToken(NewLeadingTriviaList, " ", " ", new SyntaxTriviaList()));
                    Content      = Content.Add(VBFactory.XmlText(NewTokenList));
                    EndTag       = EndTag.WithoutLeadingTrivia();
                }
            }
            catch (OperationCanceledException ex)
            {
                throw;
            }
            catch (Exception ex)
            {
            }
            var XmlElement = VBFactory.XmlElement(StartTag, Content, EndTag);

            return(XmlElement);
        }
예제 #5
0
 public override VB.VisualBasicSyntaxNode VisitXmlEmptyElement(CSS.XmlEmptyElementSyntax node)
 {
     try
     {
         VBS.XmlNodeSyntax Name = (VBS.XmlNodeSyntax)node.Name.Accept(this);
         var ListOfAttributes   = GatherAttributes(node.Attributes);
         return(VBFactory.XmlEmptyElement(Name, ListOfAttributes));
     }
     catch (OperationCanceledException ex)
     {
         throw;
     }
     catch (Exception ex)
     {
         return(VBFactory.XmlText(node.GetText().ToString()));
     }
 }
        internal SyntaxTrivia ConvertTrivia(SyntaxTrivia t)
        {
            var switchExpr = t.RawKind;

            /* TODO ERROR: Skipped RegionDirectiveTrivia */
            switch (switchExpr)
            {
            case (int)CS.SyntaxKind.WhitespaceTrivia: {
                return(VBFactory.WhitespaceTrivia(t.ToString()));
            }

            case (int)CS.SyntaxKind.EndOfLineTrivia: {
                return(global::VisualBasicSyntaxFactory.VBEOLTrivia);
            }

            case (int)CS.SyntaxKind.SingleLineCommentTrivia: {
                if (t.ToFullString().EndsWith("*/"))
                {
                    return(VBFactory.CommentTrivia($"'{ReplaceLeadingSlashes(t.ToFullString().Substring(2, t.ToFullString().Length - 4))}"));
                }
                return(VBFactory.CommentTrivia($"'{ReplaceLeadingSlashes(t.ToFullString().Substring(2))}"));
            }

            case (int)CS.SyntaxKind.MultiLineCommentTrivia: {
                if (t.ToFullString().EndsWith("*/"))
                {
                    return(VBFactory.CommentTrivia($"'{ReplaceLeadingSlashes(t.ToFullString().Substring(2, t.ToFullString().Length - 4)).Replace(Constants.vbLf, "").Replace(Constants.vbCr, "")}"));
                }
                return(VBFactory.CommentTrivia($"'{ReplaceLeadingSlashes(t.ToFullString().Substring(2)).Replace(Constants.vbLf, "").Replace(Constants.vbCr, "")}"));
            }

            case (int)CS.SyntaxKind.DocumentationCommentExteriorTrivia: {
                return(VBFactory.SyntaxTrivia(VB.SyntaxKind.CommentTrivia, "'''"));
            }

            case (int)CS.SyntaxKind.DisabledTextTrivia: {
                if (TriviaDepth > 0)
                {
                    return(VBFactory.DisabledTextTrivia(t.ToString().WithoutNewLines(' ')));
                }
                return(VBFactory.DisabledTextTrivia(t.ToString().ConsistentNewlines()));
            }

            case (int)CS.SyntaxKind.PreprocessingMessageTrivia: {
                return(VBFactory.CommentTrivia($" ' {t}"));
            }

            case (int)CS.SyntaxKind.None: {
                return(default(SyntaxTrivia));
            }
            }

            /* TODO ERROR: Skipped EndRegionDirectiveTrivia */
            /* TODO ERROR: Skipped RegionDirectiveTrivia */
            CSS.StructuredTriviaSyntax StructuredTrivia = (CSS.StructuredTriviaSyntax)t.GetStructure();
            Debug.Assert(StructuredTrivia != null, $"Found new type of non structured trivia {t.RawKind}");
            var switchExpr1 = t.RawKind;

            switch (switchExpr1)
            {
            case (int)CS.SyntaxKind.DefineDirectiveTrivia: {
                CSS.DefineDirectiveTriviaSyntax DefineDirective = (CSS.DefineDirectiveTriviaSyntax)StructuredTrivia;
                var Name = VBFactory.Identifier(DefineDirective.Name.ValueText);
                VBS.ExpressionSyntax value = VBFactory.TrueLiteralExpression(global::VisualBasicSyntaxFactory.TrueKeyword);
                return(VBFactory.Trivia(WithAppendedTriviaFromEndOfDirectiveToken(WithConvertedTriviaFrom(VBFactory.ConstDirectiveTrivia(Name, value), DefineDirective), DefineDirective.EndOfDirectiveToken)
                                        ));
            }

            case (int)CS.SyntaxKind.UndefDirectiveTrivia: {
                CSS.UndefDirectiveTriviaSyntax UndefineDirective = (CSS.UndefDirectiveTriviaSyntax)StructuredTrivia;
                var Name = VBFactory.Identifier(UndefineDirective.Name.ValueText);
                VBS.ExpressionSyntax value = global::VisualBasicSyntaxFactory.NothingExpression;
                return(VBFactory.Trivia(WithAppendedTriviaFromEndOfDirectiveToken(WithConvertedTriviaFrom(VBFactory.ConstDirectiveTrivia(Name, value), UndefineDirective), UndefineDirective.EndOfDirectiveToken)
                                        ));
            }

            case (int)CS.SyntaxKind.EndIfDirectiveTrivia: {
                if (TriviaDepth > 0)
                {
                    TriviaDepth -= 1;
                    return(VBFactory.CommentTrivia($"' TODO VB does not allow directives here, original statement {t.ToFullString().WithoutNewLines(' ')}"));
                }
                CSS.EndIfDirectiveTriviaSyntax EndIfDirective = (CSS.EndIfDirectiveTriviaSyntax)StructuredTrivia;
                return(VBFactory.Trivia(WithAppendedTriviaFromEndOfDirectiveToken(VBFactory.EndIfDirectiveTrivia().WithConvertedTrailingTriviaFrom(EndIfDirective.EndIfKeyword), EndIfDirective.EndOfDirectiveToken)
                                        ));
            }

            case (int)CS.SyntaxKind.ErrorDirectiveTrivia: {
                CSS.ErrorDirectiveTriviaSyntax ErrorDirective = (CSS.ErrorDirectiveTriviaSyntax)StructuredTrivia;
                return(VBFactory.CommentTrivia($"' TODO: Check VB does not support Error Directive Trivia, Original Directive {ErrorDirective.ToFullString()}"));
            }

            case (int)CS.SyntaxKind.IfDirectiveTrivia: {
                if (t.Token.Parent?.AncestorsAndSelf().OfType <CSS.InitializerExpressionSyntax>().Any() == true)
                {
                    TriviaDepth += 1;
                }
                CSS.IfDirectiveTriviaSyntax IfDirective = (CSS.IfDirectiveTriviaSyntax)StructuredTrivia;
                string Expression1 = StringReplaceCondition(IfDirective.Condition.ToString());

                return(VBFactory.Trivia(WithAppendedTriviaFromEndOfDirectiveToken(VBFactory.IfDirectiveTrivia(global::VisualBasicSyntaxFactory.IfKeyword, VBFactory.ParseExpression(Expression1)).With(IfDirective.GetLeadingTrivia().ConvertTrivia(), IfDirective.Condition.GetTrailingTrivia().ConvertTrivia()), IfDirective.EndOfDirectiveToken)));
            }

            case (int)CS.SyntaxKind.ElifDirectiveTrivia: {
                if (t.Token.Parent.AncestorsAndSelf().OfType <CSS.InitializerExpressionSyntax>().Any())
                {
                    TriviaDepth += 1;
                }
                CSS.ElifDirectiveTriviaSyntax ELIfDirective = (CSS.ElifDirectiveTriviaSyntax)StructuredTrivia;
                string Expression1 = StringReplaceCondition(ELIfDirective.Condition.ToString());

                SyntaxToken IfOrElseIfKeyword;
                if (t.IsKind(CS.SyntaxKind.ElifDirectiveTrivia))
                {
                    IfOrElseIfKeyword = global::VisualBasicSyntaxFactory.ElseIfKeyword;
                }
                else
                {
                    IfOrElseIfKeyword = global::VisualBasicSyntaxFactory.IfKeyword;
                }
                return(VBFactory.Trivia(WithAppendedTriviaFromEndOfDirectiveToken(VBFactory.ElseIfDirectiveTrivia(IfOrElseIfKeyword, VBFactory.ParseExpression(Expression1))
                                                                                  .With(ELIfDirective.GetLeadingTrivia().ConvertTrivia(), ELIfDirective.Condition.GetTrailingTrivia().ConvertTrivia())
                                                                                  , ELIfDirective.EndOfDirectiveToken)));
            }

            case (int)CS.SyntaxKind.LineDirectiveTrivia: {
                return(VBFactory.CommentTrivia($"' TODO: Check VB does not support Line Directive Trivia, Original Directive {t}"));
            }

            case (int)CS.SyntaxKind.ElseDirectiveTrivia: {
                return(VBFactory.Trivia(WithTrailingEOL(VBFactory.ElseDirectiveTrivia().NormalizeWhitespace().WithConvertedTrailingTriviaFrom(((CSS.ElseDirectiveTriviaSyntax)StructuredTrivia).ElseKeyword))));
            }

            case (int)CS.SyntaxKind.EndRegionDirectiveTrivia: {
                CSS.EndRegionDirectiveTriviaSyntax EndRegionDirective = (CSS.EndRegionDirectiveTriviaSyntax)StructuredTrivia;
                return(VBFactory.Trivia(WithAppendedTriviaFromEndOfDirectiveToken(VBFactory.EndRegionDirectiveTrivia(global::VisualBasicSyntaxFactory.HashToken, global::VisualBasicSyntaxFactory.EndKeyword, global::VisualBasicSyntaxFactory.RegionKeyword), EndRegionDirective.EndOfDirectiveToken)));
            }

            case (int)CS.SyntaxKind.PragmaWarningDirectiveTrivia: {
                // Dim PragmaWarningDirectiveTrivia As CSS.PragmaWarningDirectiveTriviaSyntax = DirectCast(StructuredTrivia, CSS.PragmaWarningDirectiveTriviaSyntax)
                // Dim ErrorList As New List(Of VBS.IdentifierNameSyntax)
                // Dim TrailingTriviaStringBuilder As New StringBuilder
                // For Each i As CSS.ExpressionSyntax In PragmaWarningDirectiveTrivia.ErrorCodes
                // Dim ErrorCode As String = i.ToString
                // If ErrorCode.IsInteger Then
                // ErrorCode = $"CS_{ErrorCode}"
                // End If
                // ErrorList.Add(VBFactory.IdentifierName(ErrorCode))
                // For Each Trivial As SyntaxTrivia In i.GetTrailingTrivia
                // TrailingTriviaStringBuilder.Append(Trivial.ToString)
                // Next
                // Next
                // Dim WarningDirectiveTrivia As VBS.DirectiveTriviaSyntax
                // If PragmaWarningDirectiveTrivia.DisableOrRestoreKeyword.IsKind(CS.SyntaxKind.DisableKeyword) Then
                // WarningDirectiveTrivia = VBFactory.DisableWarningDirectiveTrivia(ErrorList.ToArray)
                // Else
                // WarningDirectiveTrivia = VBFactory.EnableWarningDirectiveTrivia(ErrorList.ToArray)
                // End If
                // Return VBFactory.CommentTrivia($" ' TODO {WarningDirectiveTrivia.NormalizeWhitespace}{TrailingTriviaStringBuilder.ToString}")
                return(default(SyntaxTrivia));
            }

            case (int)CS.SyntaxKind.RegionDirectiveTrivia: {
                CSS.RegionDirectiveTriviaSyntax RegionDirective = (CSS.RegionDirectiveTriviaSyntax)StructuredTrivia;
                var    EndOfDirectiveToken       = RegionDirective.EndOfDirectiveToken;
                string NameString                = $"\"{EndOfDirectiveToken.LeadingTrivia.ToString().Replace("\"", "")}\"";
                var    RegionDirectiveTriviaNode = VBFactory.RegionDirectiveTrivia(global::VisualBasicSyntaxFactory.HashToken, global::VisualBasicSyntaxFactory.RegionKeyword, VBFactory.StringLiteralToken(NameString, NameString)
                                                                                   ).WithConvertedTrailingTriviaFrom(EndOfDirectiveToken);
                return(VBFactory.Trivia(WithTrailingEOL(RegionDirectiveTriviaNode)));
            }

            case (int)CS.SyntaxKind.SingleLineDocumentationCommentTrivia: {
                CSS.DocumentationCommentTriviaSyntax SingleLineDocumentationComment = (CSS.DocumentationCommentTriviaSyntax)StructuredTrivia;
                var walker = new XMLVisitor();
                walker.Visit(SingleLineDocumentationComment);

                var xmlNodes = new List <VBS.XmlNodeSyntax>();
                for (int i = 0, loopTo = SingleLineDocumentationComment.Content.Count - 1; i <= loopTo; i++)
                {
                    var node = SingleLineDocumentationComment.Content[i];
                    if (!node.IsKind(CS.SyntaxKind.XmlText) && node.GetLeadingTrivia().Count > 0 && node.GetLeadingTrivia().First().IsKind(CS.SyntaxKind.DocumentationCommentExteriorTrivia))
                    {
                        if (i < SingleLineDocumentationComment.Content.Count - 1)
                        {
                            var NextNode = SingleLineDocumentationComment.Content[i + 1];
                            if (!NextNode.IsKind(CS.SyntaxKind.XmlText) || NextNode.GetLeadingTrivia().Count == 0 || !NextNode.GetLeadingTrivia().First().IsKind(CS.SyntaxKind.DocumentationCommentExteriorTrivia))
                            {
                                xmlNodes.Add(VBFactory.XmlText(" ").WithLeadingTrivia(VBFactory.DocumentationCommentExteriorTrivia("'''")));
                            }
                        }
                        node = node.WithoutLeadingTrivia();
                    }
                    VBS.XmlNodeSyntax Item = (VBS.XmlNodeSyntax)node.Accept(walker);
                    xmlNodes.Add(Item);
                }
                var DocumentationCommentTrivia = VBFactory.DocumentationCommentTrivia(VBFactory.List(xmlNodes.ToArray()));
                if (!DocumentationCommentTrivia.HasLeadingTrivia || !DocumentationCommentTrivia.GetLeadingTrivia()[0].IsKind(VB.SyntaxKind.DocumentationCommentExteriorTrivia))
                {
                    DocumentationCommentTrivia = DocumentationCommentTrivia.WithLeadingTrivia(VBFactory.DocumentationCommentExteriorTrivia("''' "));
                }
                var _DocumentationComment = VBFactory.Trivia(DocumentationCommentTrivia.WithTrailingTrivia(VBFactory.EndOfLine("")));
                return(_DocumentationComment);
            }

            case (int)CS.SyntaxKind.PragmaChecksumDirectiveTrivia: {
                CSS.PragmaChecksumDirectiveTriviaSyntax PragmaChecksumDirective = (CSS.PragmaChecksumDirectiveTriviaSyntax)StructuredTrivia;
                var Guid1          = VBFactory.ParseToken(PragmaChecksumDirective.Guid.Text.ToUpperInvariant());
                var Bytes          = VBFactory.ParseToken(PragmaChecksumDirective.Bytes.Text);
                var ExternalSource = VBFactory.ParseToken(PragmaChecksumDirective.File.Text);
                return(VBFactory.Trivia(WithAppendedTriviaFromEndOfDirectiveToken(
                                            VBFactory.ExternalChecksumDirectiveTrivia(global::VisualBasicSyntaxFactory.HashToken, global::VisualBasicSyntaxFactory.ExternalChecksumKeyword, global::VisualBasicSyntaxFactory.OpenParenToken, ExternalSource, global::VisualBasicSyntaxFactory.CommaToken, Guid1, global::VisualBasicSyntaxFactory.CommaToken, Bytes, global::VisualBasicSyntaxFactory.CloseParenToken), PragmaChecksumDirective.EndOfDirectiveToken)));
            }

            case (int)CS.SyntaxKind.SkippedTokensTrivia: {
                var Builder = new StringBuilder();
                foreach (SyntaxToken tok in ((CSS.SkippedTokensTriviaSyntax)StructuredTrivia).Tokens)
                {
                    Builder.Append(tok.ToString());
                }
                return(VBFactory.CommentTrivia($"' TODO: Error SkippedTokensTrivia '{Builder}'"));
            }

            case (int)CS.SyntaxKind.BadDirectiveTrivia: {
                return(VBFactory.CommentTrivia($"' TODO: Skipped BadDirectiveTrivia"));
            }

            case (int)CS.SyntaxKind.ConflictMarkerTrivia: {
                break;
            }

            case (int)CS.SyntaxKind.LoadDirectiveTrivia: {
                break;
            }

            default: {
                Debug.WriteLine(((VB.SyntaxKind)Conversions.ToUShort(t.RawKind)).ToString());

                break;
            }
            }
            throw new NotImplementedException($"t.Kind({(VB.SyntaxKind)Conversions.ToUShort(t.RawKind)}) Is unknown");
        }