[ragel-users] Simple URL parser

hsanson hsan... at gmail.com
Fri May 23 09:07:17 UTC 2008


Ok, so I tried harder and read the URL spec (RFC 1738) and did a direct 
translation from the ABNF syntax to Ragel syntax and now it works (almost).

I still have a few (actually a lot) of questions:

1 - If you see my code (attached) you will see I parse the scheme, 
hostname, port and path parts of the URL using almost identical
     actions. The only difference is the variables used to store the 
parsed strings. Is there a way to pass the actions some variables?
     So I can create a single function and pass the variable to store as 
a parameter?

2 - For some reason the last parsing never finishes. If I pass an URL 
like "http://hostname" the parser gives me the scheme "http" but
     not the hostname. If I pass an URL like "http://hostname:8080" the 
parser outputs the scheme and hostname but not the port. And if
     I provide a path like "http://hostname:8080/file.html" the parser 
gives me all except for the path. As you see the last string never get's
     parsed and I don't know why??.

3 - Is there a better/cleaner way to do this??

thanks
Horacio

hsanson wrote:
> To learn how to use Ragel I am implementing a simple URL parser that
> receives something like "http://www.ragel.com:8080/file.txt" and
> returns each part (scheme, hostname, port, path) as strings. As I
> understand doing this with Ragel should be a breeze.
>
> Still there is something I am not getting right and would like some
> advice, see code below:
>
> The scheme part seems to work so I assume my understanding of Ragel is
> not that bad. The problem is with the hostname and port parts. The
> hostname action gets called for each character on the hostname, that
> is not the intended behavior and the port action never gets called.
>
> Any tips to take me back on track would be greatly appreciated.
>
> Horacio
>   

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: url.rl
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20080523/476352ef/attachment-0001.ksh>


More information about the ragel-users mailing list