NOODB: “M”

I mentioned previously that I’m sure I’m not going to be happy with the query parser I built.

TEXT => NEUTRAL FORMAT => REPOSITORY SPECIFIC QUERY

The NEUTRAL FORMAT is good, at least so far. But, it’s the conversion process from text to the neutral format that’s going to be beat.

I spent some time today working with “M”. Since M allows you to define DSLs and how to parse them, I thought I could use it to parse the text.

The theory is holding up, though progress has been slow.

Given this sample text:

from m in movie select m.Crap
from d in director select d.Name

I created an “M” grammar…

module HelloWorld {
    @{CaseInsensitive{}}
    language HelloWorld {
        syntax Main = 
            s:SelectQuery* => SelectQueries { valuesof(s) };
        
        syntax SelectQuery = From a:Alias In t:Table Select Field
            => { Alias => a, Table => t};
        
        @{Classification["Keyword"]}
        token From = "from";

        @{Classification["Keyword"]}
        token In = "in";

        @{Classification["Identifier"]}
        token Alias = AlphaNumeric;

        @{Classification["Identifier"]}
        token Table = AlphaNumeric;
        
        @{Classification["Identifier"]}
        token Select = "select";
        token AlphaNumeric = ('A'..'Z' | 'a'..'z' | '0'..'9')+;       
        interleave ignore = ' ' | '\r' | '\n';   
                
        token FieldAlias = AlphaNumeric;
        token FieldName = AlphaNumeric;
        syntax Field = 
                FieldAlias + "." + FieldName
                | FieldAlias;
    }
}

That results in this, so far…

SelectQueries{
  {
    Alias => "m",
    Table => "movie"
  },
  {
    Alias => "d",
    Table => "director"
  }
}

I’ve hardly scratched the surface of what I’m going to need, but at least it’s some progress.

The OSLO stuff is pretty amazing. I watched 7 videos today… cool product. I don’t know yet how this grammar is going to convert to code, but we’ll see.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: