Re: Feature request - attribute type should not be altered for terminal rules
Joel de Guzman <[email protected]> Fri, 11 May 2012 17:43:47 +0800
| Newsgroups | gmane.comp.parsers.spirit.devel,gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 5/11/2012 11:10 AM, Vitaly Budovski wrote: >> Semantic actions use the AA attribute when you #define >> BOOST_SPIRIT_ACTIONS_ALLOW_ATTR_COMPAT. That way, if you pass in a >> bignum, your SA will get the bignum that int_ parsed for you. >> >> (In your case, you are getting the warning because you passed in >> an int which the word parser takes in as its AA and passes that to >> your SA as _1 and you compare to an unsigned) >> >> Now, imagine if we force int_ to always pass _1 with type int. >> If you passed a bignum, that will be lossy! >> >> 1) the int_ parser parses a big number, say >> "1234567890123456789012345678901234567" >> 2) compiles that into a bignum >> 3) converts it to an int (oops) >> 4) passes it to your SA >> >> Step no. 3 is problematic. The bignum will be downsized to an int. >> Step no. 4 is also problematic because now, there is no way to get >> the actual bignum result that was parsed. >> > > Perhaps there is a way to introduce a step 2a, which checks > compatibility between the parsed result (bignum) and output result > (int) and issues a warning. > I guess what I'm saying is that Spirit should determine compatibility > between AA and DA. > If the user does the conversion manually to a compatible type e.g. > parse(f, l, _val = bignum_p[if_else_(_1 > 1e200, 5, 6)], int) there > will not be an issue. > Both 5 and 6 are convertible to int without overflow. I see your point. Perhaps a way to fix this is to introduce the concept of fixed attributes. I.e. some parsers (e.g. word or even rule) have fixed attributes and can therefore prevent attribute replacement. If int_ becomes a parser with a fixed attribute, then it's attribute will always be int. Same for word; same for rule<I, T()>; or grammar. Thoughts? I still have to think this through... Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/