I have implemented a pretty simple parser using Ragel. The "main" structure is a scanner.
I have something like this implemented:
action doSomething
{
doSomething(fpc);
}
foo = 'foo';
bar = 'bar';
main := |*
foo => { matchFoo(); };
bar => { matchBar(); };
space;
*|;
How do I match everything else not matched by the other rules (ie. basically an error condition, some kind of malformed input)? I'd like to implement that to be able to get an error on which line the malformed input is. I tried using an 'any' condition in the end of the scanner but that of course does not work because that will always be the "longest match" and thus the scanner will match it every time. I would definitely not want to take some kind of negation from a list containing all the other tokens (to rule them out from 'any') because that sounds wrong (hard to maintain and ends up being a big blob of code with many tokens). How do I match everything else not matched by something else in a scanner in Ragel?
Edit: Did some testing, and I can get it to work if I just match "any" in the end of the scanner. Then it will go to that expression when a character doesn't match. However if I try to match "any+" then it will not work because it will go there every time (for all of the data, it will always be the longest match in the scanner). The problem with just matching "any" is that I do not get the token start and token end pointers to WHOLE continuous block of unmatched data. How do I match the "longest continuous block of characters that doesn't match anything else"?