Esempio n. 1
0
        public static Query StaticGetQuery(string input)
        {
            ICharStream   stream = CharStreams.fromString(input);
            ITokenSource  lexer  = new MiniSQLLexer(stream);
            ITokenStream  tokens = new CommonTokenStream(lexer);
            MiniSQLParser parser = new MiniSQLParser(tokens);

            parser.BuildParseTree = true;
            IParseTree tree = parser.prog();

            MiniSQLVisitor visitor = new MiniSQLVisitor();
            Query          query   = (Query)visitor.Visit(tree);

            // import file
            int index = 0;

            while (index < query.StatementList.Count)
            {
                IStatement statement = query.StatementList[index];
                if (statement.Type == StatementType.ExecFileStatement)
                {
                    ExecFileStatement execFile = (ExecFileStatement)statement;
                    query.StatementList.RemoveAt(index);
                    string fileText = File.ReadAllText(execFile.FilePath);
                    Query  ret      = StaticGetQuery(fileText);
                    query.StatementList.InsertRange(index, ret.StatementList);
                    continue;
                }
                index++;
            }
            return(query);
        }
Esempio n. 2
0
        public override object VisitExecFileStatement([NotNull] MiniSQLParser.ExecFileStatementContext context)
        {
            ExecFileStatement obj = new ExecFileStatement();
            string            filePathWithQuote;

            if (context.SINGLE_QUOTED_TEXT() != null)
            {
                filePathWithQuote = context.SINGLE_QUOTED_TEXT().GetText();
            }
            else
            {
                filePathWithQuote = context.DOUBLE_QUOTED_TEXT().GetText();
            }
            string filePath = filePathWithQuote.Substring(1, filePathWithQuote.Length - 2);

            obj.FilePath = filePath;
            return(obj);
        }