[ragel-users] Split ragel source files to several and include one to other
Jonathan Castello
twisolar at gmail.com
Tue Feb 15 19:50:57 UTC 2011
Hi Oleg,
When you 'include' one machine into another, the first machine's
actions and states become available to the new one. But it can't find
the 'thread_id' state (because there is none), so it fails. You've got
the right idea with your second try, but you need there to be a
thread_id -state- you can reference:
----
{{%
machine thread_id;
action thread_id_begin { thread_id= 0; }
action thread_id_step { thread_id= thread_id * 10 + (fc - '0'); }
action thread_id_end { set_thread_id(thread_id); }
key = 'Thread_id: ';
value = ([0-9] @thread_id_step;)+ %thread_id_end;
thread_id = (key @thread_id_begin) . value;
main := thread_id;
%}}
----
Factoring out 'main' into its own named state lets you use it from
another machine. Now, when you try to use the thread_id state from
your second machine, the lookup is successful. If you don't use the
thread_id machine directly and just include it into other machines,
you don't need the 'main' definition there, either.
The above code is untested, but I did more or less the same thing with
my Telnet parser [1][2].
Hope that helps,
~Jonathan Castello
[1] https://github.com/Twisol/anachronism/blob/master/ext/anachronism/parser_common.rl
[2] https://github.com/Twisol/anachronism/blob/master/ext/anachronism/anachronism.rl
On Tue, Feb 15, 2011 at 2:54 AM, Oleg Tsarev <zabivator at gmail.com> wrote:
> Hello guys,
>
> I try to use ragel in the open-source project "Percona-Playback":
> https://code.launchpad.net/~tsarev/percona-playback/alpha
> Ragel is great compliant to my targets.
>
> But I have trouble what can't solve and documentation not answer to my
> question.
> So I read parts 2.1.4, but don't understand how its work
>
> Suppose I have one machine (thread_id.rl file):
> {{%
> machine thread_id;
> action thread_id_begin { thread_id= 0; }
> action thread_id_step { thread_id= thread_id * 10 + (fc - '0'); }
> action thread_id_end { set_thread_id(thread_id); }
> key = 'Thread_id: ';
> value = ([0-9] @thread_id_step;)+ %thread_id_end;
> main := (key @thread_id_begin) . value;
> %}}
>
> Now i want two things:
> 1) Write unit test to this machine
> 2) Use this machine to another, more complex machine.
>
> I tried to include this machine in another file:
> %%{
> machine thread_id_test;
> error = [^\n]* '\n'
> >{ std::cout << "start skip: '"; }
> ${ std::cout << fc; }
> @{ std::cout < "'\n" << std::flush; fgoto main; };
> thread_id= include thread_id "../../src/parser/thread_id.rl";
> main := (thread_id | error)*;
> write data;
> }%%
>
> but receive error:
> [ 69%] Generating thread_id_test.cc
> /storage/project/playback/head/test/parser/thread_id_test.rl:39:10: at token
> TK_ColonEquals: parse error
>
> I tried another way:
> %%{
> machine thread_id_test;
> include thread_id "../../src/parser/thread_id.rl";
> error = [^\n]* '\n'
> >{ std::cout << "start skip: '"; }
> ${ std::cout << fc; }
> @{ std::cout < "'\n" << std::flush; fgoto main; };
> main := (thread_id | error)*;
> write data;
> }%%
>
> but get another error:
> [ 69%] Generating thread_id_test.cc
> /storage/project/playback/head/test/parser/thread_id_test.rl:39:14: graph
> lookup of "thread_id" failed
>
> Thank you very much for any help.
>
> Best regards, Oleg
>
> _______________________________________________
> ragel-users mailing list
> ragel-users at complang.org
> http://www.complang.org/mailman/listinfo/ragel-users
>
>
_______________________________________________
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