[ragel-users] Re: ragel and memory usage

Adrian Thurston thurs... at cs.queensu.ca
Mon Jan 22 16:45:26 UTC 2007


Hi Damir,

If you run

ragel -M contact_param -s memory.rl >memory.xml

And then look at the XML file you'll see that there are several final states
with transitions on ',' (44) in them. They seem to come from URIs. This is a
problem for making a comma-separated list of contact_param. You need to
exclude the comma if you want to make an unambiguous list.

Contact = (("Contact" | "m" ) HCOLON
    (STAR | (contact_param (COMMA contact_param)*)));

You should probably see what the RFC has to say, but if you want a quick fix
you can resolve the ambiguity explicitly using priorities. This resolution
favours the the COMMA which separates items.

COMMA_pri = (SWS "," @(contact_COMMA, 1) SWS);
contact_param_pri = contact_param $(contact_COMMA, 0);

Contact = ( ( "Contact" | "m" ) HCOLON (STAR |
    (contact_param_pri (COMMA_pri contact_param_pri)*)));

You can also resolve the ambiguity by making a new version of contact_param
that does not have any commas. This can be done with "strong subtraction"
(see the manual).

contact_param_nocomma = contact_param -- ",";

To get a feel for what is going on here play around with a mini-version of
your parser and look at the graphviz output.

action in {}
action all {}
action out {}

sym = "+" | "-" | ",";
word = ( [a-z] | sym )+ >in $all %out;

WS = ' ';
COMMA = WS* "," @1 WS*;

word_lowpri = word $(COMMA,0);
word_nocomma = word -- ',';

main := ':' word_nocomma (COMMA word_nocomma)*;

Cheers,
 Adrian

Damir Nedzibovic wrote:
> Hi Adrian,
> 
> it seems that I wasn't able to remove the ambiguity after all :-(
> 
> I managed to further isolate the problem, I think:
> 
> if I replace this line
> 
> contact_param  = ((name_addr | addr_spec) (SEMI contact_params)*);
> 
> with
> 
> contact_param  = ((name_addr ) (SEMI contact_params)*);
> 
> the problem goes away, and ragel is able to complete the task.
> 
> I'm pretty much clues at this point...
> 
> thanks,
> d
> 
> 
> 



More information about the ragel-users mailing list