On 2/28/12 11:15 PM, Nick Sabalausky wrote:
In Goldie, I've taken an inverted approach, which IMHO is easier to use: The
types are automatically generated from the grammar, not the other way
around. So applying that approach to the above code, it'd be more like this:

mixin genGrammar!("myGrammar", `
     Identifier = [a-zA-Z_][a-zA-Z_0-9]*
     Module = Declaration+
     Declaration = StructDeclaration
     StructDeclaration = 'struct' Identifier '{' Declaration* '}'
`);

Which generates these classes:

Parser!"myGrammar"
Symbol!("myGrammar.Identifier")
Symbol!("myGrammar.Module")
Symbol!("myGrammar.Declaration")
Symbol!("myGrammar.StructDeclaration")

and/or these:

Parser_myGrammar
Symbol_myGrammar!"Identifier"
Symbol_myGrammar!"Module"
Symbol_myGrammar!"Declaration"
Symbol_myGrammar!"StructDeclaration"

would could then be aliased by the user however they wanted:

alias Symbol_myGrammar MySym;

And there can still be hooks (delegates, subclassing, whatever) to add
customized behavior/functionality.

I think this is the right approach.

Andrei


Reply via email to