Exemple #1
0
        private ArgumentNode ParseArgument(ArgumentSyntax argument)
        {
            var expression = ParseExpression(argument.Expression);
            var kArgument  = KSyntaxFactory.Argument().WithExpression(expression);

            return(kArgument);
        }
Exemple #2
0
        private PredefinedTypeNode ParsePredefinedType(PredefinedTypeSyntax type)
        {
            var keyword         = KSyntaxFactory.Token(KSyntaxKind.LocalKeyword);
            var kPredefinedType = KSyntaxFactory.PredefinedType(keyword);

            return(kPredefinedType);
        }
Exemple #3
0
        private IdentifierNameExpressionNode ParseIdentifierNameExpression(IdentifierNameSyntax identifierNameSyntax)
        {
            var name = identifierNameSyntax.Identifier.Text;
            var kIdentifierExpression = KSyntaxFactory.IdentifierNameExpression(KSyntaxFactory.Identifier(name));

            return(kIdentifierExpression);
        }
Exemple #4
0
        private LiteralExpressionNode ParseLiteralExpression(LiteralExpressionSyntax literalExpression)
        {
            var value = literalExpression.Token.Text;
            var kLiteralExpression = KSyntaxFactory.LiteralExpression((KSyntaxKind)literalExpression.Kind(), KSyntaxFactory.Literal(value));

            return(kLiteralExpression);
        }
Exemple #5
0
        //private ForStatementNode ParseForStatement(ForStatementSyntax forStatement)
        //{
        //    //var localVarName = "countdown";
        //    //var initValue = 10;
        //    //var conditionalExpression = "countdown = 0";
        //    //var statement = $"FROM {{local {localVarName} is {initValue}.}} {conditionalExpression} STEP {{SET {localVarName} to {localVarName} - 1.}} DO";

        //    throw new NotImplementedException();
        //}

        private ExpressionStatementNode ParseExpressionStatement(ExpressionStatementSyntax expressionStatement)
        {
            var expression           = ParseExpression(expressionStatement.Expression);
            var kExpressionStatement = KSyntaxFactory.ExpressionStatement().WithExpression(expression);

            return(kExpressionStatement);
        }
Exemple #6
0
        private InvocationExpressionNode ParseInvocationExpression(InvocationExpressionSyntax invocationExpressionSyntax)
        {
            var expression           = ParseExpression(invocationExpressionSyntax.Expression);
            var argumentList         = ParseArgumentList(invocationExpressionSyntax.ArgumentList);
            var invocationExpression = KSyntaxFactory.InvocationExpression().WithExpression(expression).WithArgumentList(argumentList);

            return(invocationExpression);
        }
Exemple #7
0
        private FieldDeclarationNode ParseFieldDeclaration(FieldDeclarationSyntax fieldDeclaration)
        {
            var declaration       = ParseDeclaration(fieldDeclaration.Declaration);
            var kFieldDeclaration = KSyntaxFactory.FieldDeclaration()
                                    .WithVariableDeclaration(declaration)
                                    .WithPeriod(KSyntaxFactory.Token(KSyntaxKind.Period));

            return(kFieldDeclaration);
        }
Exemple #8
0
        private VariableDeclaratorNode ParseDeclarator(VariableDeclaratorSyntax variableDeclaratorSyntax)
        {
            var identifier  = KSyntaxFactory.Identifier(variableDeclaratorSyntax.Identifier.Text);
            var initializer = ParseInitializer(variableDeclaratorSyntax.Initializer);
            var kDeclarator = KSyntaxFactory.VariableDeclarator()
                              .WithIdentifier(identifier)
                              .WithInitializer(initializer);

            return(kDeclarator);
        }
Exemple #9
0
        private VariableDeclarationNode ParseDeclaration(VariableDeclarationSyntax declaration)
        {
            var type = ParseType(declaration.Type);
            var variableDeclarator = ParseDeclarator(declaration.Variables.First());
            var kDeclaration       = KSyntaxFactory.VariableDeclaration()
                                     .WithType(type)
                                     .WithVariableDeclarator(variableDeclarator);

            return(kDeclaration);
        }
Exemple #10
0
        private EqualsValueClauseNode ParseInitializer(EqualsValueClauseSyntax initializer)
        {
            var isToken      = KSyntaxFactory.Token(KSyntaxKind.IsKeyword);
            var value        = ParseExpression(initializer.Value);
            var kInitializer = KSyntaxFactory.EqualsValueClause()
                               .WithIsKeyword(isToken)
                               .WithValue(value);

            return(kInitializer);
        }
Exemple #11
0
        private AssignmentExpressionNode ParseSimpleAssignmentExpression(AssignmentExpressionSyntax assignmentExpression)
        {
            var set                   = KSyntaxFactory.Token(KSyntaxKind.SetKeyword);
            var leftExpression        = ParseExpression(assignmentExpression.Left);
            var to                    = KSyntaxFactory.Token(KSyntaxKind.ToKeyword);
            var rightExpression       = ParseExpression(assignmentExpression.Right);
            var kAssignmentExpression = KSyntaxFactory.AssignmentExpression(KSyntaxKind.SimpleAssignmentExpression)
                                        .WithSet(set).WithLeft(leftExpression).WithTo(to).WithRight(rightExpression);

            return(kAssignmentExpression);
        }
Exemple #12
0
        private ArgumentListNode ParseArgumentList(ArgumentListSyntax argumentList)
        {
            var kArgumentList        = KSyntaxFactory.ArgumentList();
            var sourceOpenParenSpan  = argumentList.OpenParenToken.Span;
            var sourceCloseParenSpan = argumentList.CloseParenToken.Span;

            kArgumentList.WithOpenParenToken(KSyntaxFactory.Token(KSyntaxKind.OpenParenToken, sourceOpenParenSpan.Start, sourceOpenParenSpan.End));

            foreach (var argument in argumentList.Arguments)
            {
                var kArgument = ParseArgument(argument);
                kArgumentList.AddArguments(kArgument);
            }

            kArgumentList.WithCloseParenToken(KSyntaxFactory.Token(KSyntaxKind.CloseParenToken, sourceCloseParenSpan.Start, sourceCloseParenSpan.End));
            return(kArgumentList);
        }