[ragel-users] Re: Help with extracting a list of numbers
Manoj Rajagopalan
ma... at nanorex.com
Wed Mar 26 00:08:31 UTC 2008
Oh and in the program that I sent to this group in my previous email,
the print_info() action to be executed when the last state ('\0') is
reached never gets executed:
main :=
space*
'bond' %{cerr << "saw 'bond'" << endl;}
(space+ whole_number %foundNumberAction)+
space* 0
@{ print_info();}
;
Input: bond <number> <number> <number> ...
Here is a twist: when I extract the user input into a character buffer,
then replace the last NULL char with '\n' and make the next character
NULL, incrementing pe by 1 and then changing the pattern's last 0 to
'\n', the machine works perfectly.
Does ragel interpret line-ending NULL chars in some special way?
-- Manoj
Adrian Thurston wrote:
> Hi Manoj,
>
> Are you sure the null is being sent to the parser? If it is then
> printNumber should be executed on the last character.
>
> Adrian
>
> Manoj Rajagopalan wrote:
>> Hi all,
>>
>> I'm trying to write a pattern to extract a list of numbers following
>> the keyword bond and I'm not able to figure out why my pattern below
>> always skips the last number
>>
>> My input is of the form:
>>
>> bond <number> <number> ...
>>
>> %%{
>> machine bond_parser;
>>
>> whole_number = digit+ >to{intVal=0;} ${intVal = intVal*10 +
>> (fc-'0');} ;
>>
>> main :=
>> space* 'bond'
>> (space+ whole_number %printNumber)+
>> space* 0;
>> }%%
>>
>> where printNumber is an action to print the number just updated into the
>> integer variable intVal.
>>
>> The 0 at the end of the pattern is the NULL character that cin.getline()
>> adds when reading upto the newline character from the console.
>>
>> I realize this may be due to the leaving action for the last number that
>> never gets called but could someone tell me a way around this?
>>
>> Thanks,
>> Manoj
>>
>
> >
More information about the ragel-users
mailing list