2012/2/20 <span dir="ltr"><<a href="mailto:ragel-user@jgoettgens.de">ragel-user@jgoettgens.de</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div style="font-size:12pt;font-family:'Calibri'">
<div>Ivan,</div>
<div> </div>
<div>so you need to mark the beginning and the end of either “command” or “data”
mode given the keywords “*OPEN*” and “*CLOS*”. Right? Once matched it is
entirely up to you what to do with the matched text (User Actions, chapter 3).
You could post a typical token stream and an outline of your ragel specs.
Otherwise it is difficult to see the cause of your problem. </div>
<div> </div>
<div>jg</div>
<div style="font-size:small;font-style:normal;text-decoration:none;font-family:'Calibri';display:inline;font-weight:normal"> </div></div></div></div>
<br>_______________________________________________<br>
ragel-users mailing list<br>
<a href="mailto:ragel-users@complang.org">ragel-users@complang.org</a><br>
<a href="http://www.complang.org/mailman/listinfo/ragel-users" target="_blank">http://www.complang.org/mailman/listinfo/ragel-users</a><br></blockquote></div><br>I'm sorry if my post wasn't clear enough.<br><br>
I've managed to achieve the results that I expect, although I don't know
if it is the most effective way to do it. I'm gonna post it in this
e-mail. My objective is to read the stream of characters between the
*OPEN* and *CLOS* "tokens". Thanks in advance for any tips or insights
on this.<br>
<br>
#include <stdio.h><br>
#include <stdlib.h><br>
#include <string.h><br>
#include <stdbool.h><br>
<br>
%%{<br>
<br>
machine test;<br>
<br>
action open_found {<br>
printf("FOUND OPEN\r\n");<br>
fgoto data;<br>
}<br>
action close_found {<br>
printf("FOUND CLOSE\r\n");<br>
fgoto main;<br>
}<br>
action new_data_char {<br>
printf("NEW CHAR: %c, lock: %d\n", fc, lock_data);<br>
if (!lock_data)<br>
rec[count++] = fc;<br>
}<br>
action close_candidate {<br>
printf("CLOSE CANDIDATE: %c\n", fc);<br>
lock_data = true;<br>
cacount = 0;<br>
fhold; fgoto clos;<br>
}<br>
action not_close {<br>
printf("NOT CLOSE: %c, candidate: %s, cacount: %d\n", fc, candidate, cacount);<br>
lock_data = false;<br>
strncat(rec, candidate, cacount);<br>
count += cacount;<br>
fgoto data;<br>
}<br>
action store_candidate_char {<br>
printf("CANDIDATE CHAR: %c\n", fc);<br>
candidate[cacount++] = fc;<br>
}<br>
<br>
open = /.*\*OPEN\*/;<br>
close = /.*\*CLOS\*/;<br>
<br>
main :=<br>
(open %open_found)+;<br>
<br>
data := /.*\*/ @~new_data_char %~close_candidate;<br>
clos := /\*CLOS\*/ $/{fbreak;} $store_candidate_char @!(not_close) @close_found;<br>
<br>
}%%<br>
<br>
%% write data;<br>
<br>
const char *p, *pe, *eof;<br>
int cs;<br>
const char *ts, *te;<br>
int act;<br>
int stack[128] = {0};<br>
int top;<br>
<br>
char rec[1024] = {0};<br>
unsigned int count = 0;<br>
char candidate[1024] = {0};;<br>
unsigned int cacount = 0;<br>
bool lock_data = false;<br>
<br>
bool parse(const char * str) {<br>
p = str; pe = str + strlen(str); eof = pe;<br>
<br>
%% write exec;<br>
<br>
return true;<br>
}<br>
<br>
int main(int argc, char **argv) {<br>
char buf[2048] = "aaaaaaaaaa*OPEN*bbbbbbbb*CLbbbbbbbbb*CLOS*aaaaaaaaaaaaaaaaaaaa";<br>
<br>
%% write init;<br>
<br>
parse(buf);<br>
<br>
printf("data[%d] = %s\n", count, rec);<br>
return 0;<br>
}<br>
<br><br>