Compile time regex matching
Jason den Dulk via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 15 04:36:55 PDT 2014
On Monday, 14 July 2014 at 11:43:01 UTC, Philippe Sigaud via
Digitalmars-d-learn wrote:
> You can try Pegged, a parser generator that works at
> compile-time
> (both the generator and the generated parser).
I did, and I got it to work. Unfortunately, the code used to in
the CTFE is left in the final executable even though it is not
used at runtime. So now the question is, is there away to get rid
of the excess baggage?
BTW Here is the code I am playing with.
import std.stdio;
string get_match()
{
import pegged.grammar;
mixin(grammar(`
MyRegex:
foo <- "abc"* "def"?
`));
auto result = MyRegex(import("config-file.txt")); //
compile-time parsing
return "writeln(\""~result.matches[0]~"\");";
}
void main()
{
mixin(get_match());
}
More information about the Digitalmars-d-learn
mailing list