예제 #1
0
        public string Visit(FunctionExpression function)
        {
            var codeWriter = new XzaarCodeWriter();

            codeWriter.Write("fn " + function.Name + "(", currentIndent);
            codeWriter.Write(string.Join(", ", function.GetParameters().Select(v => v.Type.Name + " " + v.Name).ToArray()));
            codeWriter.Write(") ");
            if (function.ReturnType.Name != "void")
            {
                codeWriter.Write("-> " + function.ReturnType.Name + " ");
            }
            codeWriter.Write("{");
            codeWriter.NewLine();

            var body = function.GetBody();

            if (body != null)
            {
                currentIndent++;
                codeWriter.Write(Visit(body));
                currentIndent--;
            }

            codeWriter.Write("}", currentIndent);
            codeWriter.NewLine();
            return(codeWriter.ToString());
        }
예제 #2
0
        public FunctionExpression Visit(FunctionExpression function)
        {
            codeWriter.Write("fn " + function.Name + "(", currentIndent);
            codeWriter.Write(string.Join(", ", function.GetParameters().Select(v => v.Type.Name + " " + v.Name).ToArray()));
            codeWriter.Write(") {");
            codeWriter.NewLine();

            var body = function.GetBody();

            if (body != null)
            {
                currentIndent++;
                Visit(body);
                currentIndent--;
            }

            codeWriter.Write("}", currentIndent);
            codeWriter.NewLine();
            return(null);
        }