diff options
author | matthewsotoudeh <matthewsot@outlook.com> | 2014-11-28 00:19:55 -0800 |
---|---|---|
committer | matthewsotoudeh <matthewsot@outlook.com> | 2014-11-28 00:19:55 -0800 |
commit | 97f83a7f8fc3e7a0852e14d2686d88a6b195320e (patch) | |
tree | 6024a1490d4212f1f393bf18e4d3f49c4c3dfa72 | |
parent | 4198074d9c34bcaaafe77d320d140dc15c34c59e (diff) |
commented up StatementSyntaxParser
-rw-r--r-- | SharpSwift/SharpSwift/Converters/LogicSyntaxParser.cs | 33 | ||||
-rw-r--r-- | SharpSwift/SharpSwift/Converters/StatementSyntaxParser.cs | 50 |
2 files changed, 52 insertions, 31 deletions
diff --git a/SharpSwift/SharpSwift/Converters/LogicSyntaxParser.cs b/SharpSwift/SharpSwift/Converters/LogicSyntaxParser.cs index 85e1a68..e69c682 100644 --- a/SharpSwift/SharpSwift/Converters/LogicSyntaxParser.cs +++ b/SharpSwift/SharpSwift/Converters/LogicSyntaxParser.cs @@ -59,5 +59,38 @@ namespace SharpSwift.Converters return section.Statements.TakeWhile(statement => !(statement is BreakStatementSyntax)) // Swift doesn't use break; statements. .Aggregate(output, (current, statement) => current + (" " + SyntaxNode(statement))); //TODO: Handle case/switch indenting in Indenter.cs } + + /// <summary> + /// Converts an if statement to Swift + /// </summary> + /// <example>if (x == y) { }</example> + /// <param name="statement">The statement to convert</param> + /// <returns>The converted Swift statement</returns> + [ParsesType(typeof(IfStatementSyntax))] + public static string IfStatement(IfStatementSyntax statement) + { + var output = statement.IfKeyword.Text + " ("; + output += SyntaxNode(statement.Condition); + output += ")" + NewLine + SyntaxNode(statement.Statement); + if (statement.Else != null) + { + output += SyntaxNode(statement.Else); + } + return output; + } + + /// <summary> + /// Converts an else clause to Swift + /// </summary> + /// <example>else { }</example> + /// <param name="clause">The else clause to convert</param> + /// <returns>The converted Swift clause</returns> + [ParsesType(typeof(ElseClauseSyntax))] + public static string ElseClause(ElseClauseSyntax clause) + { + var output = clause.ElseKeyword.Text + " "; + output += SyntaxNode(clause.Statement); + return output; + } } } diff --git a/SharpSwift/SharpSwift/Converters/StatementSyntaxParser.cs b/SharpSwift/SharpSwift/Converters/StatementSyntaxParser.cs index 41b5eaf..0511733 100644 --- a/SharpSwift/SharpSwift/Converters/StatementSyntaxParser.cs +++ b/SharpSwift/SharpSwift/Converters/StatementSyntaxParser.cs @@ -5,55 +5,43 @@ namespace SharpSwift.Converters { partial class ConvertToSwift { - //using(var something = new StreamReader()) { something } + /// <summary> + /// Converts a using statement to Swift + /// </summary> + /// <example>using(var something = new StreamReader()) { something }</example> + /// <param name="statement">The statement to convert</param> + /// <returns>The converted Swift statement</returns> [ParsesType(typeof(UsingStatementSyntax))] - public static string UsingStatement(UsingStatementSyntax node) + public static string UsingStatement(UsingStatementSyntax statement) { - var output = SyntaxNode(node.Declaration) + ";" + NewLine; + var output = SyntaxNode(statement.Declaration) + ";" + NewLine; - output += Block((BlockSyntax)node.Statement, false); + output += Block((BlockSyntax)statement.Statement, false); //Swift calls deinit when you make a variable nil output += string.Join("", - node.Declaration.Variables.Select(variable => variable.Identifier.Text + " = nil;" + NewLine)); + statement.Declaration.Variables.Select(variable => variable.Identifier.Text + " = nil;" + NewLine)); return output; } - + /// <summary> + /// Converts a return statement to Swift + /// </summary> + /// <param name="statement">The statement to convert</param> + /// <returns>The converted Swift statement</returns> [ParsesType(typeof(ReturnStatementSyntax))] - public static string ReturnStatement(ReturnStatementSyntax node) + public static string ReturnStatement(ReturnStatementSyntax statement) { var output = "return"; - if (node.Expression != null) + if (statement.Expression != null) { - output += " " + SyntaxNode(node.Expression); + output += " " + SyntaxNode(statement.Expression); } - return output + Semicolon(node.SemicolonToken); - } - - [ParsesType(typeof(IfStatementSyntax))] - public static string IfStatement(IfStatementSyntax node) - { - var output = node.IfKeyword.Text + " ("; - output += SyntaxNode(node.Condition); - output += ")" + NewLine + SyntaxNode(node.Statement); - if (node.Else != null) - { - output += SyntaxNode(node.Else); - } - return output; - } - - [ParsesType(typeof(ElseClauseSyntax))] - public static string ElseClause(ElseClauseSyntax node) - { - var output = node.ElseKeyword.Text + " "; - output += SyntaxNode(node.Statement); - return output; + return output + Semicolon(statement.SemicolonToken); } } } |