Well ... this is pretty cool:
///// re2t.flx
include "std/re2";
open Re2;
instance Str[StringPiece] { fun str(x:StringPiece)=>string x; }
var r = RE2 ("(h)ello|(H)ello");
var n = r.NumberOfCapturingGroups;
println$ "Captures = "+str n;
var s = "Hello";
var v = _ctor_varray[StringPiece]$ (n+1).ulong, StringPiece "";
var res = Re2::Match(r,StringPiece s,0, ANCHOR_START, v.stl_begin, v.len.int);
println$ res;
println$ v;
////
~/felix>flx --test=build/release-optimized/ re2t
Captures = 2
true
varray(Hello, , H)
////
BTW: the Felix implementation is sweeter then the tre one, using varray instead
of STL vector, but that's just because I haven't upgraded the tre one .. :)
Hope you like the "OO" syntax:
var n = r.NumberOfCapturingGroups;
haha .. which of course just means:
var n = NumberOfCapturingGroups r;
Buglets: two buglets are identified in Felix here.
First, note I used (n+1).ulong to cast an int to a size_t, required by varray.
Originally I had (n+1).size but that didn't insert any cast. The standard
library says:
typedef size = ulong;
Using ulong I get
static_cast<unsigned long>(PTF n+1)
in C++, the cast is missing if I use Felix size. Not sure why, perhaps Felix
doesn't
chain down typedefs to find the right C++ to cast with, perhaps the compiler
just ignore it: don't know. Notice, there are no _ctor_ things in the library:
T x
in Felix just becomes a cast (or should ..?)
The other buglet is the need to use _ctor_varray instead of just varray,
that's because Felix supports polymorphic functions just fine,
but it doesn't support polymorphic "ctor" constructions properly in the
parser. This is just a matter of hacking the Scheme code a bit.
The problem is that the construction:
ctor T : argt = ...
is changed to
fun _ctor_T : argt -> T = ...
which is all fine, but what if T is polymorphic? Consider:
ctor T[U]: argt -> T[U] = ..
being converted to
fun _ctor_T[U] : argt -> T[U] = ...
and it all looks cool .. but it isn't. Just consider:
fun _ctor_T[U,V] :argt -> T[U*V] = ...
This is just fine, but the correct syntax to make this from ctor is:
ctor[U,V] T[U*V]: argt = ".."
Note the type variables are announced (quantified) on the binder "ctor"
and then used to specify the type T[U*V] being constructed, unfortunately this
syntax breaks:
ctor vector[T]: unit = "vector<?1>()";
for example, since the "T" after "vector" isn't quantified after "ctor" like it
should
be. Other forms used the correct syntax, for example:
open[U,V] X[U * V];
opens module X on all pairs. So the bottom line is that fixing this will
required
modifying all that code using the "wrong" syntax (in the standard library,
tools,
and any user code).
--
john skaller
[email protected]
------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language