Hi!

IMHO you won't be able to handle all the corner cases without full grammar
parser.
For example consider a "SET TERM" inside an "EXECUTE BLOCK".
Lacking the grammar understnding you won't recognize that as an invalid
term in the execute block and
you'll simply cut the block in half. So the decision is how far do you want
to go.

Writing a full scale parser for FB SQL in a rather easy but very tedious
and time-consuming task.
Having that as a tool would be a great addition to FB ecosystem.
The parser in FB itself is written in yacc so it's faily transportable.
Sill you'll have to go rule by rule
and convert to C#.
Actually I have tried this myself in F# (it's far far better suited for
parsers) and am about 50% through.
I would gladly donate the code if you'd be interested.

If you would preffer the faster approach I would suggest:
 - a simple lexer by hand that recognizes tokens "SET" "TERM"
CURRENT_TERM_SYMBOL "--" , NEWLINE OTHER_TOKEN and STRING
 - a parser that iterates the tokens form lexer, tests for sequences:
"SET" "TERM" OTHER_TOKEN CURRENT_TERM_SYMBOL - to set new terms
CURRENT_TERM_SYMBOL - to yield accumulated OTHER_TOKENs and STRINGs
-  -- to start a comment and skip everything till NEWLINE
this should be an easy enough state machine to write by hand.

Cheers!
Michał






2015-10-05 15:30 GMT+02:00 Jiří Činčura <j...@cincura.net>:

> Hi,
>
> I'm working on a bug fix for DNET-266. And the more and more I tweak the
> parser I wrote this morning to properly handle all the edge cases I'm
> wondering whether it would make sense to take a dependency on some
> library or class that can do some basic parsing. We don't need full
> grammar features like ANTLR, just something that can tokenize SQL and
> handle comments (or in general tokenizer with "escaping" support).
>
> What do you think? Any recommendations?
>
> BTW the bugfix is sponsored by SMS-Timing. Kudos to them.
>
> --
> Mgr. Jiří Činčura
> Independent IT Specialist
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Firebird-net-provider mailing list
> Firebird-net-provider@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/firebird-net-provider
>
------------------------------------------------------------------------------
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to