[ragel-users] How to specify where to stop when scanning a string

dinesh rtp mariner_element at hotmail.com
Tue Oct 15 22:27:24 UTC 2013


I have a struct,
typedef struct {  char* start_add;  char* end_add;} string_def;
I used the example from the documentation,
#include <string.h>#include <stdio.h>
%%{   machine foo;   main :=        ( 'foo' | 'bar' )        0 @{ res = 1; };}%%
%% write data;

int main(){  int cs, res = 0;  char *p = "foo";  char *pe = p + strlen(p) + 1;  %% write init;  %% write exec;  printf("result = %i\n", res );  return 0;}
This works fine : " result = 1" is the output.
If I tweak this a little to work the way my struct is.
extern string_def new_string(char* str, int len) {  string_def s;  s.start_add = str;  s.end_add = str + len;  return s;}
int main(){  string_def str = new_string("foo\0", 4); ==> Works  // string_def str = new_string("foo", 3); ==> does not work, I WANT THIS TO WORK  int cs, res = 0;  char *p = str.start_add;  char *pe = str.end_add;  %% write init;  %% write exec;  printf("result = %i\n", res );  return 0;}
Is ragel looking for a null character? How to override this behavior?? 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20131015/7d1c998d/attachment-0001.html>
-------------- next part --------------
_______________________________________________
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