[ragel-users] Parsing PokerHand-History file (kind of log file with actions)
Jens Saathoff
jensesaat at googlemail.com
Sat Jul 23 12:57:51 UTC 2011
Sorry. I forgot to attach my little test:
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <cmath>
void parse(char * str)
{
char *eof = NULL;
char *p = str; // data pointer
char *pe = str + strlen(str); // past end
int cs; // machine state
int len = 0;
char token[1024];
static char *text_start;
eof = pe;
%%{
machine parser;
write data;
action MarkStartOfName{
text_start = fpc;
}
action PrintPlayerName{
int text_len = fpc - text_start;
if (text_len > 0) {
printf("PLAYER(%.*s)\n", text_len, text_start);
}
}
playername = lower+ >MarkStartOfName ^(space 'raises' space '$' digit+ space
'to' space '$' digit+) @PrintPlayerName ;
#playername = any+ >MarkStartOfName ^ ' raises $1 to $2' /*(space 'raises'
space '$' digit+ space 'to' space '$' digit+)*/ @PrintPlayerName ;
main := playername;
write init;
write exec;
}%%
printf("\n");
}
int main()
{
parse("player raises $1 to $2");
getchar();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20110723/404657f9/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