/// <inheritdoc /> public Result<BlockSyntax, Diagnostic> ToSyntaxNode(IdentifierNameSyntax inputIdentifier, IdentifierNameSyntax spaceIndexIdentifier) { return GetCommandMethods().AndThen(commands => { IdentifierNameSyntax secondSpaceIndexIdentifier = IdentifierName(spaceIndexIdentifier.Identifier.ValueText + "2"), subCommandNameIdentifier = IdentifierName("subCommandName"); var commandsSwitchSections = new List<SwitchSectionSyntax>(commands.Count); foreach (var command in commands) { var block = command.Value.ToSyntaxNode(inputIdentifier, secondSpaceIndexIdentifier); if (block.IsErr) return block; commandsSwitchSections.Add(SwitchSection( List(new SwitchLabelSyntax[] { CaseSwitchLabel ( LiteralExpression ( SyntaxKind.StringLiteralExpression, Literal ( command.Key ) ) ) }), List(new StatementSyntax[] { block.Ok.Value, BreakStatement ( ) }) )); } return (Result<BlockSyntax, Diagnostic>) Block(new StatementSyntax[] { /* Int32 secondSpaceIndex = input.IndexOf ( ' ', spaceIndex ) */ LocalDeclarationStatement( /* Int32 secondSpaceIndex = input.IndexOf ( ' ', spaceIndex + 1 ) */ VariableDeclaration( /* Int32 */ Utilities.GetTypeSyntax(CommandManager.CommonSymbols.System_Int32), /* secondSpaceIndex = input.IndexOf ( ' ', spaceIndex + 1 ) */ SeparatedList(new[] { /* secondSpaceIndex = input.IndexOf ( ' ', spaceIndex + 1 ) */ VariableDeclarator( secondSpaceIndexIdentifier.Identifier, null, /* = input.IndexOf ( ' ', spaceIndex + 1 ) */ EqualsValueClause( (ExpressionSyntax) inputIdentifier.AsDynamic() .IndexOf(' ', spaceIndexIdentifier.AsDynamic() + 1) ) /* /= input.IndexOf ( ' ', spaceIndex ) */ ) /* /secondSpaceIndex = input.IndexOf ( ' ', spaceIndex ) */ } ) ) /* /Int32 secondSpaceIndex = input.IndexOf ( ' ', spaceIndex ) */ ), /* /Int32 secondSpaceIndex = input.IndexOf ( ' ', spaceIndex ) */ /* String subCommandName = secondSpaceIndex != -1 ? input.Substring ( spaceIndex + 1, secondSpaceIndex ) : input; */ LocalDeclarationStatement( VariableDeclaration( /* String */ Utilities.GetTypeSyntax(CommandManager.CommonSymbols.System_String), /* subCommandName = secondSpaceIndex != -1 ? input.Substring ( spaceIndex + 1, secondSpaceIndex ) : input; */ SeparatedList(new[] { /* subCommandName = secondSpaceIndex != -1 ? input.Substring ( spaceIndex + 1, secondSpaceIndex ) : input */ VariableDeclarator( subCommandNameIdentifier.Identifier, null, EqualsValueClause( /* secondSpaceIndex != -1 ? input.Substring ( spaceIndex + 1, secondSpaceIndex ) : input */ ConditionalExpression( (ExpressionSyntax) (secondSpaceIndexIdentifier.AsDynamic() != -1), (ExpressionSyntax) inputIdentifier.AsDynamic() .Substring(spaceIndexIdentifier.AsDynamic() + 1, secondSpaceIndexIdentifier), inputIdentifier ) /* /secondSpaceIndex != -1 ? input.Substring ( spaceIndex + 1, secondSpaceIndex ) : input */ ) ) /* /subCommandName = secondSpaceIndex != -1 ? input.Substring ( spaceIndex + 1, secondSpaceIndex ) : input */ }) ) ), /* /String subCommandName = secondSpaceIndex != -1 ? input.Substring ( spaceIndex + 1, secondSpaceIndex ) : input; */ SwitchStatement( subCommandNameIdentifier, List(commandsSwitchSections) ), }); }); }