[ragel-users] Re: Machine not running terminating actions

Matt Mower s... at mattmower.com
Wed Jan 3 08:31:19 UTC 2007


Hi Adrian,

On 03/01/07, Adrian Thurston <thurs... at cs.queensu.ca> wrote:
> When it comes to ordering actions on the same character, just remember
> that there is an outer-inner ordering. It goes outer start actions,
> inner start actions, inner rest actions, outer rest actions. "rest"
> meaning finishing, leaving, and all actions. It seems that what you have
> now is right.
>

Cool. I think I'd figured that out intuitively but not on a conscious level.

> Leaving actions (%) only fire on character transitions. What is
> happening is that at the end of the input the machine is just exiting.

Ah.

> There is no character to cause the action to get executed. If you embed
> an eof action (using %eof exit_diff) at the same places that you've
> specified the leaving actions (%exit_diff) and you write the eof switch
> (with %%write eof;) then they will fire.
>

Zed prompted me to look at write eof, but I misread the guide and
didn't realise you had to embed specific EOF actions. I guess using
Ruby so much has lead me to expect magic everywhere ;-)

> You can try it out with something simple like the following. I find the
> smaller machines are easier to reason about and what you learn
> generalizes well.

Good point.

>         sub = ( 's' [^\n]* '\n' ) %e1 %eof e1;

%eof, isn't that another action the same as %e1?  When I looked
through the 5.16 guide about EOF actions it suggested I should use %/
(maybe %eof is alternative syntax? I couldn't find it when I
searched).

Anyway I tried:

hunk = hunkHeader >enter_hunk hunkBody %exit_hunk %/exit_hunk;
	
	fileName = ( lineChar+ ) >mark %copy_to_filespec;
	
	fileSpec = "Index:" nbsp+ fileName '\n'+;
	
	diffHeader = ( fileSpec separator oldFile newFile );
	diffBody = hunk* %exit_diff %/exit_diff;

and it worked first time out (since I already had the %% write eof, it
just wasn't doing anything!)

> ( ignoreCode | hunkEndChar @{ fhold; } );
>

I removed the lookahead as you suggested. I'll consume the \\ prefixed
comment inside 'line' from now on.

> In general, it's advisable to avoid fhold unless you're about to jump
> somewhere using fgoto or you're really sure of what you're doing. The

Yeah I think we can safely say I don't *quite* know what I'm doing
yet. But I do feel like I'm getting, slowly, to grips with it. I think
that part of my problem is that I'm not a visual thinker, I can't
imagine the resulting graph as I'm constructing the machine. I
probably need to be a bit less sloppy in my reasoning to compensate
;-)

So, this morning, I have:

[Session started at 2007-01-03 08:24:20 +0000.]
2007-01-03 08:24:20.716 Ragel2[1666] begin_diff
2007-01-03 08:24:20.716 Ragel2[1666]     filespec:
app/helpers/application_helper.rb
2007-01-03 08:24:20.716 Ragel2[1666]   begin_hunk
2007-01-03 08:24:20.716 Ragel2[1666]   end_hunk
2007-01-03 08:24:20.716 Ragel2[1666] end_diff
2007-01-03 08:24:20.716 Ragel2[1666] begin_diff
2007-01-03 08:24:20.716 Ragel2[1666]     filespec:
app/views/layouts/application.rhtml
2007-01-03 08:24:20.716 Ragel2[1666]   begin_hunk
2007-01-03 08:24:20.716 Ragel2[1666]   end_hunk
2007-01-03 08:24:20.716 Ragel2[1666] end_diff
2007-01-03 08:24:20.716 Ragel2[1666] begin_diff
2007-01-03 08:24:20.716 Ragel2[1666]     filespec: db/schema.rb
2007-01-03 08:24:20.716 Ragel2[1666]   begin_hunk
2007-01-03 08:24:20.716 Ragel2[1666]   end_hunk
2007-01-03 08:24:20.716 Ragel2[1666]   begin_hunk
2007-01-03 08:24:20.716 Ragel2[1666]   end_hunk
2007-01-03 08:24:20.717 Ragel2[1666]   begin_hunk
2007-01-03 08:24:20.717 Ragel2[1666]   end_hunk
2007-01-03 08:24:20.717 Ragel2[1666]   begin_hunk
2007-01-03 08:24:20.717 Ragel2[1666]   end_hunk
2007-01-03 08:24:20.717 Ragel2[1666] end_diff
2007-01-03 08:24:20.717 Ragel2[1666] Parser exit no errors

Thank you Adrian & Zed!

Regards,

Matt

-- 
Matt Mower :: http://matt.blogs.it/



More information about the ragel-users mailing list