[ragel-users] Re: Starting out with Java

Marc Cooper auxb... at googlemail.com
Sun Sep 9 22:19:56 UTC 2007


> > 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.

Ah! Okay. It's a shame that this is not made clear anywhere. I pulled
down the svn "Development Version" and that seems to have plenty of
good stuff in it.

> > 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.

Reminds me of the Java code I'm working on at present, where the
author has converted everything into null-terminated byte arrays...
and passes them around. Who needs objects?

> If you remove it (main := [a-z]+ @{ res = 1;
> fbreak; };) and set pe = data.length, your machine will work perfectly
> fine.

Thanks. That's an improvement, but I'm still wrong somewhere. I'll put
my thinking cap on - it's probably to do with the args[0].length, but
it's late here. Good to know I'm on the right track... and now have
some examples to play with.

> > 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.

Yup, but I still think that examples on the web-page would help. The
capabilities are not made very clear, and I think that's a shame.

> Good luck, I'm also trying to learn Ragel.

I can already see that I need a lot more than luck!

Thanks again.

-- 
Best,
Marc



More information about the ragel-users mailing list