Sorry for a late reply!
Your letter somehow got to spam, so I overlooked it.
There are some errors in your program:
First of all, re2c rule for path
"href=".+'>' { return PATH; }
should look like
"href="[^>]+'>' { return PATH; }
because ".+" will consume all characters except "\n", so when re2c
reaches ">",
it will happily consume it and proceed to the end of the string. "[>]"
is what you need.
Next, I changed the main re2c loop. You put the loop in 'main', so that
you have to
returne from 'scan' every time on default character:
[^] { return END; }
It's a possible way to do things, but very inefficient: you have to call
'scan' on each
input character. A much better way (and the usual way for re2c) is to
make a loop
inside of 'scan':
for (;;) {
... // re2c code
}
And instead of 'return END;' in default rule simply go to the start of
'for':
[^] { continue; }
But you should be careful with the end of the string:
"\x00" { return END; }
This rule *must* go before the default rule '[^]'. (It's better to use
the new default rule '*':
it always has the lowest priority.)
Please see the full working example in attach. Hope that helped!
Ulya
#include <stdio.h>
#include <stdlib.h>
enum {
PATH, END
};
int scan(char** p, char** lex)
{
char* marker;
for (;;) {
*lex = *p;
/*!re2c
re2c:define:YYCTYPE = "char";
re2c:define:YYCURSOR = *p;
re2c:define:YYMARKER = marker;
re2c:yyfill:enable = 0;
re2c:yych:conversion = 1;
re2c:indent:top = 1;
"href="[^>]+'>' { return PATH; }
"\x00" { return END; }
[^] { continue; }
*/
}
}
int main() {
char *p ="sdfsdfsdfsdf <a href='/page/site.jsp'> sdfsdfsdfsdfsdf<a>";
char *last = p;
int sz;
switch (scan(&p, &last)) {
case PATH:
sz = p - last - 1;
printf("url is: '%.*s'\n", sz, last);
break;
case END:
printf("no url\n");
break;
}
return 0;
}
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Re2c-general mailing list
Re2c-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/re2c-general