Am 12.09.2012 22:25, schrieb Eldar Insafutdinov:

On Wednesday, 12 September 2012 at 19:50:22 UTC, Nick Sabalausky wrote:

On Wed, 12 Sep 2012 21:36:52 +0200
"Eldar Insafutdinov" e.insafutdinov@gmail.com wrote:

I don't quite understand about how exactly to use state machines
here, but I just thought - if there were support for Regexps how
would that fit in?

AIUI:

It would essentially be a lexer.

Vibe.d would collect all the regexes. Then, instead of the usual regex
approach of building one NFA/DFA for each regex (with one "Accept"
state each), it would essentially combine them like this:

(regex1)|(regex2)|(regex3)|(etc.)

And each of those parts would have their own separate "accept" state.

Ie, a lexer.

The main issue that got me started on this thing is that currently
wild-cards are not captured, so something like this wouldn't work:

router.get("/assets/*", serveStaticFiles("./public/"));

(I know you figured this out already... just posting here to remember
adding it to the docs later)

The following ought to work:

auto settings = new HttpFileServerSettings;
settings.serverPathPrefix = "/assets/";
router.get("/assets/*", serveStaticFiles("./public/", settings));

Currently when the matcher sees wildcard and it just returns a match.
That brings us to the question - do we really want to support them
properly? Sinatra has the following:

get '/say/*/to/*' do
  # matches /say/hello/to/world
  params[:splat] # => ["hello", "world"]

To do that the parser has to be a lot more sofisticated than it
currently is. The easiest option would be of course just to match and
capture the first * and be done with it.

Personally, all I've ever needed was '*' at the end for matching routes
for serveStaticFiles() and :var-style routes for anything else. That's
obviously also a reason why the wildcard support was never improved
beyond that.

But even if it stays at its current limited functionality, I would
improve two things: throw an error if a route has a '' that is not at
the end of the string, and put the contents matched by the '
' into
something like params["wildcard"].