Exemplo n.º 1
0
        public static CompileResult Compile(string typeSql, string typeSqlFileName)
        {
            //create the antlr-based lexer and parser
            var lexer = new TypeSqlLexer(new ANTLRStringStream(typeSql));
             var rewriteTokenStream = new TokenRewriteStream(lexer);
            var parser = new TypeSqlParser(rewriteTokenStream);

            //parse the typeSql, producing the AST
            var ast = (CommonTree) parser.typesql().Tree;
             var nodeStream = new CommonTreeNodeStream(ast);

            //transform the AST into raw-sql
             var rawSqlOutput = new RawSqlTransform(nodeStream);
             nodeStream.TokenStream = rewriteTokenStream;
             rawSqlOutput.typeSql();
             string rawSql = rewriteTokenStream.ToString();

            //reset
             lexer.Reset();
             rewriteTokenStream.Reset();
             nodeStream.Reset();
            //and transform the AST into DAO source code
             var daoTransform = new DaoTransform(nodeStream){TemplateGroup = new StringTemplateGroup(
                new StreamReader(typeof(TypeSqlCompiler).Assembly.GetManifestResourceStream("TypeSql.Parsing.DapperDao.stg")),
                typeof (TemplateLexer))};
             var template = daoTransform.typeSql(typeSqlFileName, rawSql).Template;
             string daoSourceCode = template.ToString();

            return new CompileResult(daoSourceCode, rawSql);
        }
Exemplo n.º 2
0
 public ReplaceOp( TokenRewriteStream stream, int from, int to, object text )
     : base(stream, from, text)
 {
     lastIndex = to;
 }
Exemplo n.º 3
0
 protected RewriteOperation( TokenRewriteStream stream, int index, object text )
 {
     this.index = index;
     this.text = text;
     this.stream = stream;
 }
Exemplo n.º 4
0
 public InsertBeforeOp( TokenRewriteStream stream, int index, object text )
     : base(stream, index, text)
 {
 }
Exemplo n.º 5
0
 protected RewriteOperation(TokenRewriteStream stream, int index)
 {
     this.stream = stream;
     this.index = index;
 }