[ragel-users] Newbie advice

Adrian Thurston thurs... at cs.queensu.ca
Mon Aug 27 14:57:01 UTC 2007


Hi Dave,

Yes you have the idea, just remove '--\n' from the possible matches of a
line.

%%{
    machine sections;
    action onSection {}

    any_line = [^\n]* '\n';
    marker_line = '--\n';

    section = (any_line - marker_line)* marker_line @onSection;

    main = section*;
}%%

Cheers,
 Adrian

ddri... at gmail.com wrote:
> Hello,
> 
> I'm trying to use Ragel to split apart a structured text file.  As a
> simplified example, I want to split apart sections of a file separated
> by "--" on its own line, e.g.:
> 
> foo--
> bar
> --
> bing
> --
> --
> baz
> --
> 
> This sample has four sections (the third one is empty).  I've got a
> simple machine like this that seems to work:
> 
>     section = (any* $onChar '\n')? :>> "--\n" @onSection;
>     main := section*;
> 
> The idea is that I buffer up section data in the onChar action, and
> then I can process it in onSection.  While this machine does seem to
> work, onChar is being called for the trailing "--".  I understand why
> this is being done, but I'm looking for advice to work around it.
> Should I just delete the trailing "--" in onSection?  Or is there a
> better way?
> 
> Thanks,
> 
> -Dave
> 
> 
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "ragel-users" group.
> To post to this group, send email to ragel-users at googlegroups.com
> To unsubscribe from this group, send email to ragel-users-unsubscribe at googlegroups.com
> For more options, visit this group at http://groups.google.com/group/ragel-users?hl=en
> -~----------~----~----~----~------~----~------~--~---
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20070827/e0341aef/attachment-0001.sig>


More information about the ragel-users mailing list