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_______________________________________________
ragel-users mailing list
[email protected]
http://www.complang.org/mailman/listinfo/ragel-users