[ragel-users] Re: Help with extracting a list of numbers
Adrian Thurston
thurs... at cs.queensu.ca
Wed Mar 26 02:14:01 UTC 2008
Just change the setting of pe to (strlen(linebuf) + 1) to include the
null character and it should work okay.
Adrian
Manoj Rajagopalan wrote:
> Hi Adrian
>
> The detection works only when I enter a space at the end. And yes,
> the terminating 0 is being sent. Hope this isn't a bug. Maybe I'm
> missing something really simple.
>
> I'm using Ragel 6.0 on Fedora 8.
>
> BTW, I'm attaching a small C++ program if anyone would like to run it.
>
> In the program, it prints out the ending character (*pe) and
> confirms that it is '\0'. Should 'pe' point to the last char or to one
> past it, i.e., is the character range [p,pe] or [p, pe) ?
>
> In one place in the manual I see p+strlen(buf) (fig 5.1, pg 36)
> whereas in another I see p+strlen(buf)+1 (pg 6)
>
>
> -- 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