/// Tuesday, November 15

Reflex Syntax Change

After some tinkering with Reflex's grammar, I decided on this (very Groovy-like):

01: #ref "../../MGutz.Test.dll"
02:
03: new Person() {
04:     Name = 'mario'
05:     Weight = 160
06:     Hobbies = new string['scuba', 'biking']
07:     ID = GetUserID(Name)
08:     Vehicle = new Car('Infiniti', 'G35') {
09:         Color = 'Silver'
10:         Horses = 260
11:     }
12:     return this
13: }

In English, just in case it doesn't make sense:

Again, Reflex is not meant to be a full blown scripting language. It's a quick, easy way to create objects and invoke methods and properties using reflection with simple syntax. I plan to use it to map database tables and stored procedure results to objects and to map URLs to classes and methods. And, anywhere else I need to do reflection. (A Boo Web 2.0 Framework is coming).

// example in Boo

name = "mario"
weight = "160"
hobbies = "'scuba', 'biking', 'rugby'"

snippet = """
    #ref '../../MGutz.Test.dll'
    new Person() {
        Name = '${name}'
        Weight = ${weight}
        Hobbies = new string[${hobbies}]
    } 
"""

p = Reflex.Eval(snippet) as Person
// example in C#

string name = "mario";
string weight = "160";
string hobbies = "'scuba', 'biking', 'rugby'";

string template = @"
    #ref '../../MGutz.Test.dll'
    new Person() {
        Name = '{0}'
        Weight = {1}
        Hobbies = new string[{2}]
    }
";

string snippet = string.Format(template, name, weight, hobbies);
Person p = Reflex.Eval(snippet) as Person;

Reflex is white space agnostic (except for #ref pragma). This is equivalent:

#ref '../../MGutz.Test.dll'
new Person() { Name = '{0}' Weight = '{1}' Hobbies = new string[{2}] }

Comments:

What are you using for parsing?
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?