SQL Language Definition.

Jun 16, 2008 at 12:55 PM
Hey all,

And let me first say what a fantastic project this is.  I have been writing a custom parser for the last 2 months which in 2 hours i have managed to scrap in favour of Irony :)

I was just wondering what has happened to the SQL Language definition, i see it was removed in the latest code available on the Source Code Tab.

Is there any links any is aware of that implements the SQL Language in Irony as i really think this is one of the best components \ API's available for the .net framework.

Cheers everyone :)

Jun 16, 2008 at 4:29 PM


thanks for praising Irony!

SQL grammar - this was an unfinished effort by one of the contributors, it was not planned to be included in samples until it's done, it just slipped through, so I removed it from file set in latest submission. So SQL grammar is still unfinished - wanna take over it? - you're welcome to do it; I can promise all help and support I can.

thanks again


Jun 16, 2008 at 4:35 PM

Hello Roman,

I have already started work on implementing the SQL language in Irony.

I am still trying to get my head around many of the constructs and the way Irony works, its been years since i did absolutely anything to do with parsers \ linkers \ compilers.

Its late afternoon here now , so i am going to make some dinner for the family and will probably post back tomorrow with any updates or questions i have.

Cheers :)

Aug 12, 2008 at 12:52 PM
Any update? I'm looking to do the same thing - parse SQL for auto-completion use.
Nov 3, 2008 at 8:33 PM
If you want a good example of a SQL grammar for an LALR, go to Gold Parser's web site and get it. (http://www.devincook.com/goldparser/grammars/index.htm)

That being said:  auto-completion for SQL actually is a very difficult thing to do. You might not think so at first, but honestly the only reason auto-complete works so well for C# and vb.net is because they're static typed, and the thing can parse, compile, and use reflection on them while you're typing.  You'll need to have a connection to the database in order to determine what kind of column is generated when a given expression is typed in the SELECT clause column list, and some of them cannot be determined even until the query is run and some aggregate is tabulated.  Actually, if you followed LINQ at all, you'll know that this is one of the reasons they make you say "FROM" before you say "SELECT."   That means you can't possibly add much effect, in a disconnected environment, other than to pop up all of the possible next tokens, and if identifiers are valid next tokens, well, might as well skip autocomplete.   Loosely typed languages do not work well with autocompletion. In fact, static typing's popularity was probably only expanded because of such widespread use of the technology in auto-completion scenarios. 
Nov 4, 2008 at 5:08 AM
thanks for the link and info!
Nov 29, 2008 at 9:10 PM
Just checked in a SQL parser sample - have a look
Nov 30, 2008 at 4:13 AM
Nice!  I think you forgot the bits from the TerminalFactory for the ext identifier, nevertheless I have a way that I came up with to do that:

I can (mis-)use the CommentTerminal constructor, and just accidentally forget to add it to the NonGrammarTerminals collection.

Terminal boxId = new CommentTerminal("boxID", "[", "]");

Then I guess you can string it up with a plus to make the extended identifier.

Terminal shortId = new IdentifierTerminal("shortID");

NonTerminal idChunk = new NonTerminal("IDChunk");

idChunk.Rule = boxId | shortId;

NonTerminal extId = new NonTerminal("extId");
extId.Rule = MakePlusRule(extId, Symbol("."),  idChunk);

I don't know if that's what you did or not, but I spent a little bit on my own figuring that out for a similar scenario
a while back around the original test release time. Perhaps you have a simpler way?  If so, I certainly wouldn't object to seeing it!

Nov 30, 2008 at 4:34 AM
Just checked the 19274 version in source, using Browse Source on codeplex - the function is there. Just in case, here is the source: 

public static StringLiteral CreateSqlExtIdentifier(string name) {
      StringLiteral term = new StringLiteral(name, TermOptions.SpecialIgnoreCase);
      term.AddStartEnd("[", "]", ScanFlags.DisableEscapes);
      term.AddStartEnd("\"", ScanFlags.DisableEscapes);
      return term;

As you see, I used a StringLiteral (instead of CommentTerminal as you suggest), but I had to enhance it to support different open/close symbols.
all the rest is just like you describe - see SqlGrammar in samples...
Nov 30, 2008 at 4:50 PM
Wow, ok it appears it was there before anyway, I just missed it.  I must be going nuts, because I looked 3 times. Thanks.