[ragel-users] Transition actions on EOF handling

Adrian Thurston thurs... at cs.queensu.ca
Sat Jun 30 03:04:48 UTC 2007


Hi,

One way to handle it is to send some EOF character (maybe zero) and then
change main to

main := char+ 0;

Another way is to embed EOF actions which handle the last item.

action act_e { printf("foo\n"); }

"e" %act_e %/act_e |

Finally, if you don't need lookahead (in other words if a match can be
declared on the last character of each item -- in other other words if
no pattern is a prefix of some other pattern) then you can use the @
action embedding operator to avoid this problem. This seems to be the
case with this example, though if it has been elided it may not be.

Cheers,
 Adrian

Alexander Strange wrote:
> I wrote this program:
> #include <stdio.h>
> #include <string.h>
> %% machine romaji;
> %% write data;
> 
> int main(void)
> {
> 	char buf[1024];
> 	int ilen;
> 
> 	scanf("%s",buf);
> 	ilen = strlen(buf);
> 	{
> 		char *p = buf, *pe = &buf[ilen], *m="qqq";
> 		int cs;
> 		%%{
> 			alphtype unsigned char;
> 
> 			action mora_out {printf("%s",m);}
> 
> 			mora = ("a" % {m="あ";} |
> 					"e" % {m="え";} |
> 					"i" % {m="い";} |
> 					"o" % {m="お";} |
> 					"u" % {m="う";} |
> 					"ga" % {m="が";} |
> 					"ge" % {m="げ";} |
> 					"gi" % {m="ぎ";} |
> 					"go" % {m="ご";} |
> 					"gu" % {m="ぐ";}) % mora_out;
> 
> 			char = mora;
> 
> 			main := char+;
> 		}%%
> 
> 		%% write init;
> 		%% write exec;
> 		%% write eof;
> 	}
> 	printf("\n");
> 	return 0;
> }
> 
> and run it:
> 
>> ./r2h
> aei
> あえ
> 
> I don't blame you if you can't read the output, but there should be 3
> characters instead of two. The last one isn't firing, apparently
> because it reaches the end of the string. I've got the same problem
> (worked around) in Perian 1.0, which uses Ragel for the subtitle
> parsing. Is there a general way to handle this?
> 
> Also, how fast is Ragel for general text searches? At the expense of
> more tables and FSM purity, it could maybe implement something really
> fast like Boyer-Moore.
> 
> 
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "ragel-users" group.
> To post to this group, send email to ragel-users at googlegroups.com
> To unsubscribe from this group, send email to ragel-users-unsubscribe at googlegroups.com
> For more options, visit this group at http://groups.google.com/group/ragel-users?hl=en
> -~----------~----~----~----~------~----~------~--~---

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20070629/bda5674c/attachment-0001.sig>


More information about the ragel-users mailing list