Compile time regex matching
Artur Skawina via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 14 06:19:16 PDT 2014
On 07/14/14 13:42, Philippe Sigaud via Digitalmars-d-learn wrote:
> asserts get an entire copy of the parse tree. It's a bit wasteful, but
> using 'immutable' directly does not work here, but this is OK:
>
> enum res = MyRegex("abcabcdefFOOBAR"); // compile-time parsing
> immutable result = res; // to avoid copying the enum value everywhere
static immutable result = MyRegex("abcabcdefFOOBAR"); // compile-time parsing
> The static asserts then works (not the toString, though). Maybe
diff --git a/pegged/peg.d b/pegged/peg.d
index 98959294c40e..307e8a14b1dd 100644
--- a/pegged/peg.d
+++ b/pegged/peg.d
@@ -55,7 +55,7 @@ struct ParseTree
/**
Basic toString for easy pretty-printing.
*/
- string toString(string tabs = "")
+ string toString(string tabs = "") const
{
string result = name;
@@ -262,7 +262,7 @@ Position position(string s)
/**
Same as previous overload, but from the begin of P.input to p.end
*/
-Position position(ParseTree p)
+Position position(const ParseTree p)
{
return position(p.input[0..p.end]);
}
[completely untested; just did a git clone and fixed the two
errors the compiler was whining about. Hmm, did pegged get
faster? Last time i tried (years ago) it was unusably slow;
right now, compiling your example, i didn't notice the extra
multi-second delay that was there then.]
artur
More information about the Digitalmars-d-learn
mailing list