I am new to Ragel and have been trying to parse a specific pattern of Regex expression. I want action done
to be executed if a match is found and parse_error
to be executed if there is no match even for any single character missing.
Here is the code I have written:
#include <iostream>
#include <string.h>
#include <stdio.h>
%%{
action done {
printf("done\n");
}
action parse_error {
printf("error : %c\n",fc);
}
machine ldf;
main := (':'.'LoadSdf'.[0-9]+.[a-zA-Z0-9_\-\.])@done | //execute done
(^(':'.'LoadSdf'.[0-9]+.[a-zA-Z0-9_\-\.])) $err(parse_error); //execute parse error for no match
}%%
%%write data;
int main(int argc, char** argv)
{
int cs;
if(argc > 1) {
char *p = argv[1];
char *pe = p+strlen(p) + 1;
%%write init;
%%write exec;
}
return 0;
}
The behaviour I see is that actions done
and parse_error
are both executed when there is a perfect match of the regex expression.
Can anyone provide some tips on how I can tackle this case?