public static void Transpile(this Syntax.FunctionSyntax functionNode, ref StringBuilder sb) { _ = functionNode ?? throw new ArgumentNullException(nameof(functionNode)); functionNode.FunctionDeclarationNode.Transpile(ref sb); functionNode.DeclarationLineDelimiterNode.Transpile(ref sb); functionNode.LocalVariableListNode.Transpile(ref sb); functionNode.StatementListNode.Transpile(ref sb); sb.Append("end"); functionNode.LastLineDelimiterNode.Transpile(ref sb); TranspileStringConcatenationHandler.ResetLocalVariables(); }
public static MethodDeclarationSyntax Transpile(this Syntax.FunctionSyntax functionNode) { _ = functionNode ?? throw new ArgumentNullException(nameof(functionNode)); // TODO: do smth with constant keyword? var functionDeclr = functionNode.FunctionDeclarationNode.Transpile(); return(functionDeclr.WithBody( SyntaxFactory.Block( functionNode.LocalVariableListNode.Transpile().Concat( functionNode.StatementListNode.Transpile()))) .WithModifiers( new Microsoft.CodeAnalysis.SyntaxTokenList( SyntaxFactory.Token(Microsoft.CodeAnalysis.CSharp.SyntaxKind.PublicKeyword), SyntaxFactory.Token(Microsoft.CodeAnalysis.CSharp.SyntaxKind.StaticKeyword)))); }