Hello Daniel

Thank you for your email. I am of the impression that the AST transformation 
works on a valid AST. I am trying to define custom syntax to make a valid 
custom AST. This means I am creating new syntax that is not easy to represent 
using the groovy language spec. Is that the right way to think about this or 
are you saying that it should be possible to use fluent call mechanims and 
chaining to get what I want. I am not sure if that is easy to achieve because 
the syntax for my custom query can get hairy

regards
Saravanan

On 2020/08/09 01:24:57, Daniel Sun <sun...@apache.org> wrote: 
> I think you want to implement your own DSL. The AST transformation of Groovy 
> could help you.
> 
> Cheers,
> Daniel Sun
> On 2020/08/08 23:54:47, Saravanan Palanichamy <chava...@gmail.com> wrote: 
> > Hello everyone
> > 
> > If I wanted to introduce new syntax in my groovy script, how would I go 
> > about doing it? I want to embed custom syntax directly into the groovy file 
> > and have it be parsed into my custom AST nodes. An example would be
> > 
> > myFunction() {
> >    List<MyTableValues> tableValues = select value from mySQLTable where 
> > (select tableName from myTableNames where user = $userName)
> > 
> >  ... Use table Values
> > }
> > 
> > I want to enable a few behaviors
> > a) Check for syntax correctness (which is why I want to parse using antlr 
> > grammar)
> > b) Check for semantic correctness (I suppose if I parsed this into my 
> > custom AST nodes, that takes care of that. I could make an 
> > SQLExpressionASTNode and validate things there)
> > c) Enable a debug experience where I am able to see the result of the inner 
> > SQL first and then see it move to the outer SQL (this would be super 
> > awesome, but I realize this is in the purview of the groovy IDE plugin. I 
> > am asking here to see if I can get any pointers)
> > 
> > My limited ideas so far are to annotate the List declaration with @SQL, 
> > hook into the semantic phase to translate the select clause (embedded in a 
> > gstring) into a validated, redirect into a custom function call.
> > 
> > so if I see
> > 
> > @SQL List<MyTableValues> tableValues = "select ...."
> > 
> > I'll convert it to
> > @SQL List<MyTableValues> tableValues = sqlRunner.run("select ...")
> > 
> > This does not get me debuggability though and it feels contrived
> > 
> > regards
> > Saravanan
> > 
> 

Reply via email to