[ragel] sample code
Adrian Thurston
thurston at colm.net
Wed Feb 7 16:08:54 UTC 2018
Hi,
It's because space* accepts the zero-length string. So "abc" is actually
three words with zero-length whitespace in between. Well, technically
it's both that and what you want, so you need to remove the ambiguity.
What you need is more like this:
space* wyraz ( space+ wyraz )*
-Adrian
On 2018-02-05 07:06, xoru wrote:
> How put "a ab abc t abcdn abcde"
> and get
> 'a'
> 'ab'
> 'abc'
> 'abcd'
> 'abcde'
>
> When i use main := (space* wyraz )* i get only chars not words
>
> /* @LANG: c */
> #include <stdio.h>
> #include <string.h>
>
> %%{
> machine foo;
>
> action beginning { pocz = p; }
> action ending { printf("'%.*s'n",(int)(p - pocz), pocz); }
>
> wyraz = [a-z]+ >beginning %ending;
> main := ( space* wyraz ) ;
>
> write data noerror nofinal;
> }%%
>
> int main(int argc, char **argv)
> {
> int cs = 0;
> char *pocz;
>
> if (argc > 1)
> {
> char *p = argv[1];
> char *pe = p + strlen(p);
> char *eof = pe;
> %%write init;
> %%write exec;
> }
>
> return 0;
> }
>
> _______________________________________________
> ragel mailing list
> ragel at colm.net
> http://www.colm.net/cgi-bin/mailman/listinfo/ragel [1]
Links:
------
[1] http://www.colm.net/cgi-bin/mailman/listinfo/ragel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20180207/0b02e767/attachment-0002.html>
More information about the ragel-users
mailing list