[ragel-users] Starting out with Java
Christer Sandberg
chr... at gmail.com
Sun Sep 9 19:33:37 UTC 2007
On 9/9/07, bluetooth <auxb... at googlemail.com> wrote:
>
> Hi,
>
> I'm trying to understand the basics of using ragel in Java. But I
> can't find any examples, so I'm struggling to get started.
>
> I notice that "the test directory" is often referenced in posts here,
> but no clue is given as to where this mysterious directory might be
> found. That might be a help.
>
It's found below the top directory when unpacking the ragel source dist.
> Taking simple.rl as a starting point, I so far have:
>
> public class Ragel {
>
> %% machine foo;
>
> public static void main(String[] args) {
> %% write data noerror nofinal;
> int cs, res = 0;
> if (args[0].length() > 0) {
> char[] data = args[0].toCharArray();
> int p = 0;
> int pe = data.length + 1;
> %%{
> main := [a-z]+ 0 @{ res = 1; fbreak; };
> write init;
> write exec;
> }%%
> }
> System.out.println("Execute = " + res);
> }
> }
>
>
> However, this fails for matches with an out of bounds exception.But if
> I set pe = data.length, then no matches are ever found.
>
main := [a-z]+ 0 @{ res = 1; fbreak; };
The 0 above is only interesting when used with C/C++ since all strings
are null-terminated. If you remove it (main := [a-z]+ @{ res = 1;
fbreak; };) and set pe = data.length, your machine will work perfectly
fine.
> Just a suggestion, but examples of simple.rl in Ruby and Java might
> broaden your user base quite considerably. Putting the group on gmane
> might also garner a lot more input.
>
Again, there are some good examples in the test directory in the source dist.
Good luck, I'm also trying to learn Ragel.
Christer
More information about the ragel-users
mailing list