private void ParseFunction(CreateFunctionContext node)
        {
            FullIdContext id = node.fullId();

            UidContext[] uids = id.uid();

            List <string> names = new List <string>();

            foreach (UidContext uid in uids)
            {
                string name = uid.simpleId().GetText();
                names.Add(name);
            }

            this.WriteKeyValue("Function", string.Join(".", names));

            this.WriteBeginBrace();

            string dataType = node.dataType().GetText();

            this.WriteKeyValue("dataType", dataType);

            FunctionParameterContext[] parameters = node.functionParameter();

            foreach (FunctionParameterContext parameter in parameters)
            {
                string name         = parameter.uid().GetText();
                string paraDataType = parameter.dataType().GetText();

                this.WriteKeyValue("parameter", $"{name} {paraDataType}");
            }

            RoutineBodyContext body = node.routineBody();

            this.WriteLine("body");

            this.WriteBeginBrace(2);

            this.indent = 4;

            BlockStatementContext block = body.blockStatement();

            foreach (IParseTree blockChild in block.children)
            {
                if (blockChild is ProcedureSqlStatementContext procedure)
                {
                    this.ParseProcedureStatement(procedure);
                }
                else
                {
                    string text = blockChild.GetText();

                    this.WriteLine(text, indent);
                }
            }

            this.WriteEndBrace(2);

            this.WriteEndBrace();
        }
Beispiel #2
0
        public List <Statement> ParseRoutineBody(RoutineBodyContext node)
        {
            List <Statement> statements = new List <Statement>();

            foreach (var child in node.children)
            {
                if (child is BlockStatementContext block)
                {
                    statements.AddRange(this.ParseBlockStatement(block));
                }
                else if (child is SqlStatementContext sqlStatement)
                {
                    statements.AddRange(this.ParseSqlStatement(sqlStatement));
                }
            }

            return(statements);
        }
Beispiel #3
0
 public void SetScriptBody(CommonScript script, RoutineBodyContext body)
 {
     script.Statements.AddRange(this.ParseRoutineBody(body));
 }