Discussion:
[ragel-users] How to specify where to stop when scanning a string
dinesh rtp
2013-10-15 22:27:24 UTC
Permalink
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.complang.org/pipermail/ragel-users/attachments/20131015/7d1c998d/attachment.html>
Adrian Thurston
2013-11-24 18:03:41 UTC
Permalink
The null character is specified in the grammar.
Post by dinesh rtp
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' )
}%%
%% 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??
_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users
Loading...