[ragel-users] Ragel question

Daniel Kenshalo umdkenshalo at yahoo.com
Sat Jan 21 14:11:50 UTC 2012


Really like ragel.  I have a question about the best way to implement a parser for the following format which can be repeated in a given file


ZCZC

<well formatted fixed width text> = meta-data machine


ZEM

ID:
   <any punct. etc>

IDXXX:

    <any, characters, punct. etc>

ID WITH SPACE:

   <any-text>


NNNN


A very simplified version of my machine is:
report = ('ZCZC' meta-data 'ZEM' body :>> 'NNNN')
main := report*

For the body machine I am struggling to define a machine that captures the 
identifier (always at start of line and has ':' character) and reads 
until the next occurrence of any identifier.  The identifiers may or may not be present for example one file may have ID, IDXXX and the next can have ID, ID WITH SPACE.  Really I'm just looking for text at the 
beginning of a line with a ':' character.  It's challenging b/c there is no way to tell when I'm done reading "any" and start a new ID 
<any> block.

Thanks for any help or insight you may provide.  I was thinking that scanner 
may be the only way for this type of input where I scan for the tokens 
and read in my host language until the next token, but this seems sorta 
"hack-tackulous" 


My scanner would be (which I have tested and seems to for) and then I 
would use smaller machines to further process down the input

action token {
// read line by line until line that starts w/ '\n' [A-Z ] ':' is reached
// insert each line in buffer/some key value pair map etc.
}

body := |*
'\n' [A-Z ]{3, 10} ':' @token  // the {3,10} is b/c tokens at beginning of line are no longer than 10 characters
*|;
Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20120121/08f610f0/attachment-0001.html>
-------------- next part --------------
_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users


More information about the ragel-users mailing list