picoe / Eto.Parse

Recursive descent LL(k) parser for .NET with Fluent API, BNF, EBNF and Gold Grammars
MIT License
148 stars 30 forks source link

[Req] PL/SQL Parser #31

Open tsutomi opened 8 years ago

tsutomi commented 8 years ago

Hi! I'm developing a .NET SQL-99 database system ( http://github.com/deveel/deveeldb ): in the old version (pre-2.0) I used a CC that I ported from Java (JavaCC to CSharpCC), that was performing quite well, but with a lot of problems with the maintainance and extendibility. Because of these issues, I decided to switch to Irony, that was quite a discovery, letting me define the grammar of the SQL parser directly in-code and with huge control on the analysis of the sources.

A guy interested in my project pointed me to Eto.Parse, especially highlighting the performances gain, and based on your reports this is justified. So now I'm very interested in understanding more about it, although I see an evident learning curve not easy to overcome.

Could you provide a sample of a complete PL/SQL parser that I can use as reference?

tsutomi commented 8 years ago

I tried creating a SQL-2003 parser using an EBNF grammar (attached): the parser build takes seconds and the match hangs forever:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Eto.Parse.Grammars;

namespace Eto.Parse.SqlTest {
    class Program {
        static void Main(string[] args) {
            var sqlFile = Path.Combine(Environment.CurrentDirectory, "sql-2003-2.txt");
            string fileContent;
            using (var reader = File.OpenText(sqlFile)) {
                fileContent = reader.ReadToEnd();
            }

            var grammar = new BnfGrammar();
            var parser = grammar.Build(fileContent, "SQL procedure statement");

            var match = parser.Match("SELECT * FROM table1 AS a INNER JOIN table2 AS B ON a.id = b.a_id WHERE a.name = 'test'");
            if (match.Empty) {
                Console.Out.WriteLine("Empty match");
            }
        }
    }
}

sql-2003-2.txt

ArsenShnurkov commented 8 years ago
rule is not defined I parsed your test SELECT statement - https://github.com/ArsenShnurkov/SqlParser-on-EtoParse/blob/9c4e2edadf0756760c6c40878c06441292af253a/test1/Globals.cs start - Tue Dec 15 22:20:04 stop - Wed Dec 16 01:52:51 debug time < 4h