On 3/10/12 5:56 PM, Andrej Mitrovic wrote:
I see you are not the only one who started writing string array
literals like this:
enum PEGCode = grammarCode!(
"Grammar<- S Definition+ EOI"
,"Definition<- RuleName Arrow Expression"
,"RuleName<- Identifier>(ParamList?)"
,"Expression<- Sequence (OR Sequence)*"
);
IOW comma on the left side. I know it's not a style preference but
actually a (unfortunate but needed) technique for avoiding bugs. :)
So can you use this to actually parse D code, extract syntax trees and
stuff like that? I'm clueless about parsing but it looks very neat.
Nice work!
I, too, think this is very significant work! Suggestion for Philippe:
instead of this:
enum PEGCode = grammarCode!(
"Grammar <- S Definition+ EOI"
,"Definition <- RuleName Arrow Expression"
,"RuleName <- Identifier>(ParamList?)"
,"Expression <- Sequence (OR Sequence)*"
);
how about this:
enum PEGCode = grammarCode!("
Grammar <- S Definition+ EOI;
Definition <- RuleName Arrow Expression;
RuleName <- Identifier>(ParamList?);
Expression <- Sequence (OR Sequence)*;
");
Splitting on ";" is trivial and makes client code considerably easier to
play with.
I'll get back to this.
Andrei