Example #1
0
        public SqlCompileResult Compile(SqlCompileContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            var compiler = SqlParsers.Default;
            var compileResult = new SqlCompileResult(context);

            try {
                var sqlSource = context.SourceText;
                var result = compiler.Parse(sqlSource);

                foreach (var error in result.Errors) {
                    var location = new SourceLocation(error.Line, error.Column);
                    compileResult.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, error.Message, location));
                }

                var builder = new StatementBuilder();
                var statements = builder.Build(result.RootNode, sqlSource);

                foreach (var statement in statements) {
                    compileResult.Statements.Add(statement);
                }
            } catch (SqlParseException ex) {
                compileResult.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, ex.Message));
            } catch (Exception ex) {
                compileResult.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, ex.Message));
            }

            return compileResult;
        }
        public SqlCompileResult Compile(SqlCompileContext context)
        {
            var result = new SqlCompileResult(context);

            try {
                SetInput(context.SourceText);

                // plSqlParser = MakeParser(context.SourceText, message => result.Messages.Add(message));
                var parseResult = plSqlParser.compilationUnit();

                if (parseResult == null)
                {
                    throw new InvalidOperationException();
                }

                if (messages.Count > 0)
                {
                    foreach (var message in messages)
                    {
                        result.Messages.Add(message);
                    }
                }

                if (result.HasErrors)
                {
                    return(result);
                }

                var visitor   = new SqlStatementVisitor();
                var statement = visitor.Visit(parseResult);

                if (statement is SequenceOfStatements)
                {
                    var sequence = ((SequenceOfStatements)statement).Statements;
                    foreach (var child in sequence)
                    {
                        result.Statements.Add(child);
                    }
                }
                else
                {
                    result.Statements.Add(statement);
                }
            } catch (Exception ex) {
                result.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, ex.Message));
            }

            return(result);
        }
Example #3
0
        public SqlCompileResult Compile(SqlCompileContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var compileResult = new SqlCompileResult(context);

            try {
                var sqlSource = context.SourceText;
                var result    = SqlParsers.Default.Parse(sqlSource);

                foreach (var error in result.Errors)
                {
                    var location = new SourceLocation(error.Line, error.Column);
                    compileResult.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, error.Message, location));
                }

                ITypeResolver typeResolver = null;
                if (context.Context != null)
                {
                    typeResolver = context.Context.TypeResolver();
                }

                var builder = new SqlCodeObjectBuilder(typeResolver);
                var objects = builder.Build(result.RootNode);

                foreach (var statement in objects)
                {
                    compileResult.CodeObjects.Add(statement);
                }
            } catch (SqlParseException ex) {
                compileResult.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, ex.Message));
            } catch (Exception ex) {
                compileResult.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, ex.Message));
            }

            return(compileResult);
        }
Example #4
0
        public SqlCompileResult Compile(SqlCompileContext context)
        {
            var result = new SqlCompileResult(context);

            try {
                SetInput(context.SourceText);

                // plSqlParser = MakeParser(context.SourceText, message => result.Messages.Add(message));
                var parseResult = plSqlParser.compilationUnit();

                if (parseResult == null)
                    throw new InvalidOperationException();

                if (messages.Count > 0) {
                    foreach (var message in messages) {
                        result.Messages.Add(message);
                    }
                }

                if (result.HasErrors)
                    return result;

                var visitor = new SqlStatementVisitor();
                var statement = visitor.Visit(parseResult);

                if (statement is SequenceOfStatements) {
                    var sequence = ((SequenceOfStatements) statement).Statements;
                    foreach (var child in sequence) {
                        result.Statements.Add(child);
                    }
                } else {
                    result.Statements.Add(statement);
                }
            } catch (Exception ex) {
                result.Messages.Add(new SqlCompileMessage(CompileMessageLevel.Error, ex.Message));
            }

            return result;
        }