Urlang

Posted by Jeremy Voorhis Tue, 29 May 2007 23:56:00 GMT

Some weeks ago, after discovering Rack, I took it upon myself to experiment with my own anti-framework in Ruby, using existing libraries whenever possible and filling in the blanks as I go. A vital piece of most web frameworks is the dispatcher – the module that delegates web requests to application code.

The basic premise of my design is to encode common data structures within the path of a url, and to lookup the appropriate action in a dispatch table. I don’t have a working dispatcher yet, but I do have this:

irb(main):002:0> UrlParser.parse("/foo/1,2,3/meep=fleem;fliffl=mumble,grumble/")
=> [["foo"], ["1", "2", "3"], {"meep"=>["fleem"], "fliffl"=>["mumble", "grumble"]}]

The simple language uses a slash to separate values, a comma to group them into a list, and equals and semi-colon together to create a hash. The values are returned as a list.

The next step is to determine the semantics of how an action is selected. My tastes would be satisfied by a very simple form of pattern matching, with this approximate syntax, mixing literals and types:

register(:module => PostsController, :action => :show,
         :path => ['posts', Integer], :method => GET)

Further refinements to the path language might include recognizing ints and floats, and distinguishing between array and scalar values.

If you find the idea interesting, or even terrible, I’d love to hear your thoughts on both the path language and the dispatching semantics.

p.s. No, I’m not actually calling this “Urlang”.

Comments

(leave url/email »)