On Sun, 2006-09-10 at 14:42 -0700, Erick Tryzelaar wrote:
> We don't currently have a way to plug into pattern expressions, do we?
We do now, they're ordinary expressions now. This was changed
after implementing pattern calculus.
> I
> was toying with the idea of having a simpler interface to the tre
> package, and I was thinking it'd be nice if we could do something like:
>
> match "hello" with
> | "hi" => expr1
> | regex2 => expr2
> | regex3 => expr3
> | regex4 as m:regex_match => expr4
> | regex5 as s:list[string] => expr5
> | regex6 => expr6
> | "ho" => expr7
> | _ => expr8
> endmatch
This is not quite the same issue, at present this requires
a distinct
regmatch // or
reglex
construction, and you cannot extract subexpressions.
The code for doing that in a deterministic automata exists
in an Ocaml encoding and is based on Ville Laurikari's TRE
algorithm.
It is even (illegally) in the repository, stolen from
Ocaml. Unfortunately it can't be used, because the code
has Q public licence which isn't BSD compatible ..
and I don't understand the algorithm well enough to
recode it.
That aside .. there was provision to write
match x with
| "Hello" =>
| regexp identifier as x => x ..
in the syntax, but the 'regexp' pattern isn't supported.
You CAN write
match x with
| "Hello" => ..
| x where (tre_match "(.*\\.[hc]pp")) =>
or something similiar, where the 'when' expression is
an arbitrary expression returning bool .. but there's
no way here to get the subexpressions either, even though
there is a function that can return them.
All this could be 'fixed' somehow using constant regexps
in string form, but I don't believe in that much as
a general solution.
For constant regexps, the solution is to find some theoretician
that understands Ville Laurikari's algorithm and politely ask
if they could implement an Ocaml version for deterministic automata.
For string regexps, we already have the algorithm: weird
but the run time version is available for arbitrary
regexps as strings .. but no compile time version.
[TRE is LGPL which isn't BSD compatible but it's really
a packaging issue, there's no violation of the intent]
The syntax for *using* it is a mess, I think it returns
an array and count for the substrings extracted,
use is unsafe, and defaults to "". This needs to be fixed.
-----------------------------------
There are a variety of 'hacks, kludges, and sweeteners' that
could make Felix more Perlish, without compromising the
overall static typing etc.
For example:
new dictionary;
insert x <- "world";
print "Hello $x"; endl;
is easy enough to implement: tcl/perl/bash interpolation
of variables, even if the string isn't constant, is quite
possible.
Some people will shudder .. but the point is this hackery
isn't core language.
To be more general: providing some library stuff which allows
you to do 'dynamically typed programming' is just fine.
No reason not to 'embed' an interpreter in the system:
the real thing is to make sure it can be done by the
user for 'any' interpreter they like, so that it
isn't part of the core system (though the generic
embedding support is).
Felix was always intended to support user defined Domain Specific
sub Languages (DSSLs).
One of the *core* DSSL's I want to support is SQL.
[Using SQLlite by default]
In some sense the whole reason for the 'advanced' stuff
in Felix is to allow this: the GLR parser isn't a plugin
as with other languages, it's a core tool with direct
compiler support for a reason (it is needed to make
itself a plugin :))
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language