|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
Look mom! No semantic actions.In an attempt to get with the times I have been trying to use
less semantic actions and more direct attribute parsing. I would like some advice on how others would proceed with this. my_rule %= ( a | b ) ; a and b are both the same type... I want to know which got parsed... a or b. I typically use a semantic action to grab a and b... so that makes it easy. But I want to become part of the hip crowd! For a concrete (and shortened) example: path %= ( regex_search | product_name ); regex_search %= lit( "regex<" ) >> lexeme[ *( char_ - '>' ) ] >> '>' ; product_name %= *( alnum | '_' | '-' ); rule< Iterator, path_result_type(), ascii::space_type > path; rule< Iterator, std::string(), ascii::space_type > product_name; rule< Iterator, std::string(), ascii::space_type > regex_search; path_result_type could simply be a std::string. Or.... maybe I could do something like: struct path_result_type { std::string product; bool is_regex; }; BOOST_FUSION_ADAPT_STRUCT( path_result_type, (std::string, product) ) and then do some semantic action magic with the is_regex member. But I'm not sure how to access it from _val (not yet at least). Though that seems to still be old school. So what I was thinking was something more like: struct path_result_type { tuple<std::string,bool> product; }; BOOST_FUSION_ADAPT_STRUCT( path_result_type, (tuple<std::string,bool>, product) ) and changing the path rule to be path %= ( (regex_search > ????) | (product_name > ???? ) ); where ???? is some eps like parser that consumes nothing but produces a boolean attribute. So what should I be doing? Thanks - michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: Look mom! No semantic actions.On Mon, Oct 26, 2009 at 1:47 PM, Michael Caisse
<boost@...> wrote: > In an attempt to get with the times I have been trying to use > less semantic actions and more direct attribute parsing. I would > like some advice on how others would proceed with this. > > my_rule %= ( a | b ) ; > > a and b are both the same type... > > I want to know which got parsed... a or b. I typically > use a semantic action to grab a and b... so that makes it > easy. But I want to become part of the hip crowd! > > For a concrete (and shortened) example: > > path %= ( regex_search > | > product_name ); > > regex_search %= lit( "regex<" ) >> lexeme[ *( char_ - '>' ) ] >> '>' ; > > product_name %= *( alnum | '_' | '-' ); > > rule< Iterator, path_result_type(), ascii::space_type > path; > rule< Iterator, std::string(), ascii::space_type > product_name; > rule< Iterator, std::string(), ascii::space_type > regex_search; > > > path_result_type could simply be a std::string. Or.... > maybe I could do something like: > > > struct path_result_type > { > std::string product; > bool is_regex; > }; > > BOOST_FUSION_ADAPT_STRUCT( > path_result_type, > (std::string, product) > ) > > > and then do some semantic action magic with the is_regex member. But I'm > not sure how to access it from _val (not yet at least). > > Though that seems to still be old school. So what I was thinking was something > more like: > > struct path_result_type > { > tuple<std::string,bool> product; > }; > > BOOST_FUSION_ADAPT_STRUCT( > path_result_type, > (tuple<std::string,bool>, product) > ) > > and changing the path rule to be > > path %= ( (regex_search > ????) > | > (product_name > ???? ) ); > > where ???? is some eps like parser that consumes nothing but > produces a boolean attribute. > > So what should I be doing? If you have a bool which is "is_regex", then the ???? after regex_search should be: attr(true) The ???? after product_name then would be: attr(false) ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: Look mom! No semantic actions.OvermindDL1 wrote:
> On Mon, Oct 26, 2009 at 1:47 PM, Michael Caisse > <boost@...> wrote: > >> >> struct path_result_type >> { >> tuple<std::string,bool> product; >> }; >> >> BOOST_FUSION_ADAPT_STRUCT( >> path_result_type, >> (tuple<std::string,bool>, product) >> ) >> >> and changing the path rule to be >> >> path %= ( (regex_search > ????) >> | >> (product_name > ???? ) ); >> >> where ???? is some eps like parser that consumes nothing but >> produces a boolean attribute. >> >> So what should I be doing? >> > > If you have a bool which is "is_regex", then the ???? after > regex_search should be: attr(true) > The ???? after product_name then would be: attr(false) > > Of course this works perfectly fine. If only I would remember attr. Thanks OvermindDL1 ... I knew you would come through. michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: Look mom! No semantic actions.On Mon, Oct 26, 2009 at 4:34 PM, Michael Caisse
<boost@...> wrote: > OvermindDL1 wrote: >> On Mon, Oct 26, 2009 at 1:47 PM, Michael Caisse >> <boost@...> wrote: >> >>> >>> struct path_result_type >>> { >>> tuple<std::string,bool> product; >>> }; >>> >>> BOOST_FUSION_ADAPT_STRUCT( >>> path_result_type, >>> (tuple<std::string,bool>, product) >>> ) >>> >>> and changing the path rule to be >>> >>> path %= ( (regex_search > ????) >>> | >>> (product_name > ???? ) ); >>> >>> where ???? is some eps like parser that consumes nothing but >>> produces a boolean attribute. >>> >>> So what should I be doing? >>> >> >> If you have a bool which is "is_regex", then the ???? after >> regex_search should be: attr(true) >> The ???? after product_name then would be: attr(false) >> >> > > Of course this works perfectly fine. If only I would > remember attr. > > Thanks OvermindDL1 ... I knew you would come through. I am just a user, figured out much of that as well. :) ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: Look mom! No semantic actions.On 10/26/09 15:10, OvermindDL1 wrote:
[snip] > On Mon, Oct 26, 2009 at 1:47 PM, Michael Caisse [snip] >> path_result_type could simply be a std::string. Or.... >> maybe I could do something like: >> >> >> struct path_result_type >> { >> std::string product; >> bool is_regex; >> }; >> >> BOOST_FUSION_ADAPT_STRUCT( >> path_result_type, >> (std::string, product) >> ) >> >> >> and then do some semantic action magic with the is_regex member. But I'm >> not sure how to access it from _val (not yet at least). >> >> Though that seems to still be old school. So what I was thinking was something >> more like: >> >> struct path_result_type >> { >> tuple<std::string,bool> product; >> }; >> >> BOOST_FUSION_ADAPT_STRUCT( >> path_result_type, >> (tuple<std::string,bool>, product) >> ) >> >> and changing the path rule to be >> >> path %= ( (regex_search > ????) >> | >> (product_name > ???? ) ); >> >> where ???? is some eps like parser that consumes nothing but >> produces a boolean attribute. >> >> So what should I be doing? > > If you have a bool which is "is_regex", then the ???? after > regex_search should be: attr(true) > The ???? after product_name then would be: attr(false) > What does attr(true) do? I'm guessing it's like eps except it sets an element in the "corresponding" attribute of of the lhs. In this case, the path_result_type::is_regex. Is that right. (I did scan the docs at: http://svn.boost.org/svn/boost/trunk/libs/spirit/doc/html/index.html but found no mention of "attr"). TIA. -Larry ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: Look mom! No semantic actions.Larry Evans wrote:
> On 10/26/09 15:10, OvermindDL1 wrote: > [snip] > >> On Mon, Oct 26, 2009 at 1:47 PM, Michael Caisse >> > [snip] > >>> path_result_type could simply be a std::string. Or.... >>> maybe I could do something like: >>> >>> >>> struct path_result_type >>> { >>> std::string product; >>> bool is_regex; >>> }; >>> >>> BOOST_FUSION_ADAPT_STRUCT( >>> path_result_type, >>> (std::string, product) >>> ) >>> >>> >>> and then do some semantic action magic with the is_regex member. But I'm >>> not sure how to access it from _val (not yet at least). >>> >>> Though that seems to still be old school. So what I was thinking was something >>> more like: >>> >>> struct path_result_type >>> { >>> tuple<std::string,bool> product; >>> }; >>> >>> BOOST_FUSION_ADAPT_STRUCT( >>> path_result_type, >>> (tuple<std::string,bool>, product) >>> ) >>> >>> and changing the path rule to be >>> >>> path %= ( (regex_search > ????) >>> | >>> (product_name > ???? ) ); >>> >>> where ???? is some eps like parser that consumes nothing but >>> produces a boolean attribute. >>> >>> So what should I be doing? >>> >> If you have a bool which is "is_regex", then the ???? after >> regex_search should be: attr(true) >> The ???? after product_name then would be: attr(false) >> >> > > What does attr(true) do? I'm guessing it's like eps except it > sets an element in the "corresponding" attribute of of the > lhs. In this case, the path_result_type::is_regex. Is that > right. (I did scan the docs at: > > http://svn.boost.org/svn/boost/trunk/libs/spirit/doc/html/index.html > > but found no mention of "attr"). > > TIA. > > -Larry > > > Larry - attr does exactly what I needed. Consumes nothing yet exposes an attribute. The docs are here: http://svn.boost.org/svn/boost/trunk/libs/spirit/doc/html/spirit/qi/reference/auxiliary/attr.html My final solution for the simple case actually looks like: typedef fusion::tuple<std::string, bool> product_name; - and - path %= ( (regex_search > attr(true)) | (product_name > attr(false)) ) ; HTH michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: Look mom! No semantic actions.> On 10/26/09 15:10, OvermindDL1 wrote:
> [snip] > > On Mon, Oct 26, 2009 at 1:47 PM, Michael Caisse > [snip] > >> path_result_type could simply be a std::string. Or.... > >> maybe I could do something like: > >> > >> > >> struct path_result_type > >> { > >> std::string product; > >> bool is_regex; > >> }; > >> > >> BOOST_FUSION_ADAPT_STRUCT( > >> path_result_type, > >> (std::string, product) > >> ) > >> > >> > >> and then do some semantic action magic with the is_regex member. But > I'm > >> not sure how to access it from _val (not yet at least). > >> > >> Though that seems to still be old school. So what I was thinking was > something > >> more like: > >> > >> struct path_result_type > >> { > >> tuple<std::string,bool> product; > >> }; > >> > >> BOOST_FUSION_ADAPT_STRUCT( > >> path_result_type, > >> (tuple<std::string,bool>, product) > >> ) > >> > >> and changing the path rule to be > >> > >> path %= ( (regex_search > ????) > >> | > >> (product_name > ???? ) ); > >> > >> where ???? is some eps like parser that consumes nothing but > >> produces a boolean attribute. > >> > >> So what should I be doing? > > > > If you have a bool which is "is_regex", then the ???? after > > regex_search should be: attr(true) > > The ???? after product_name then would be: attr(false) > > > > What does attr(true) do? I'm guessing it's like eps except it > sets an element in the "corresponding" attribute of of the > lhs. In this case, the path_result_type::is_regex. Is that > right. (I did scan the docs at: > > http://svn.boost.org/svn/boost/trunk/libs/spirit/doc/html/index.html > > but found no mention of "attr"). See here: http://tinyurl.com/yzqcu94, but you've already gotten the idea. Regards Hartmut ------------------- Meet me at BoostCon http://boostcon.com ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
another case for tagged variants (was Re: Look mom! No semantic actions.On 10/26/09 19:54, Michael Caisse wrote:
> Larry Evans wrote: >> On 10/26/09 15:10, OvermindDL1 wrote: >> [snip] >> >>> On Mon, Oct 26, 2009 at 1:47 PM, Michael Caisse >>> >> [snip] >> >>>> path_result_type could simply be a std::string. Or.... >>>> maybe I could do something like: >>>> >>>> >>>> struct path_result_type >>>> { >>>> std::string product; >>>> bool is_regex; >>>> }; >>>> >>>> BOOST_FUSION_ADAPT_STRUCT( >>>> path_result_type, >>>> (std::string, product) >>>> ) >>>> >>>> >>>> and then do some semantic action magic with the is_regex member. But I'm >>>> not sure how to access it from _val (not yet at least). >>>> >>>> Though that seems to still be old school. So what I was thinking was something >>>> more like: >>>> >>>> struct path_result_type >>>> { >>>> tuple<std::string,bool> product; >>>> }; >>>> >>>> BOOST_FUSION_ADAPT_STRUCT( >>>> path_result_type, >>>> (tuple<std::string,bool>, product) >>>> ) >>>> >>>> and changing the path rule to be >>>> >>>> path %= ( (regex_search > ????) >>>> | >>>> (product_name > ???? ) ); >>>> >>>> where ???? is some eps like parser that consumes nothing but >>>> produces a boolean attribute. >>>> >>>> So what should I be doing? >>>> >>> If you have a bool which is "is_regex", then the ???? after >>> regex_search should be: attr(true) >>> The ???? after product_name then would be: attr(false) >>> >>> >> What does attr(true) do? I'm guessing it's like eps except it >> sets an element in the "corresponding" attribute of of the >> lhs. In this case, the path_result_type::is_regex. Is that >> right. (I did scan the docs at: >> >> http://svn.boost.org/svn/boost/trunk/libs/spirit/doc/html/index.html >> >> but found no mention of "attr"). >> >> TIA. >> >> -Larry >> >> >> > > Larry - > > attr does exactly what I needed. Consumes nothing yet exposes an > attribute. The docs are here: > > http://svn.boost.org/svn/boost/trunk/libs/spirit/doc/html/spirit/qi/reference/auxiliary/attr.html > > My final solution for the simple case actually looks like: > > > typedef fusion::tuple<std::string, bool> product_name; > > - and - > > path %= ( > (regex_search > attr(true)) > | > (product_name > attr(false)) > ) ; > > > HTH > michael > > Thanks Michael. I just didn't know where to look. However, now I'm wondering about generalizing this use-case. For example, suppose that instead of having just a string, you also had some other type, e.g. int. IOW, instead of the above path, you had path %= ( regex_search | product_name | int_ ) Now, you can't use tuple<string,bool> because it doesn't contain int; however, neither can you use variant<string,string,int> because variant can't take duplicate types. However, instead of the current variant, why not use a truly "tagged" variant which can handle duplicate types by using the tag to indicate which type? Then there would be no need for the trailing: > attr(bool) Thoughts? -regards, Larry ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: another case for tagged variants (was Re: Look mom! No semantic actions.Larry Evans wrote:
> > Thanks Michael. I just didn't know where to look. > > However, now I'm wondering about generalizing this use-case. > For example, suppose that instead of having just a string, > you also had some other type, e.g. int. IOW, instead of the > above path, you had > > path %= ( regex_search > | product_name > | int_ > ) > > Now, you can't use tuple<string,bool> because it doesn't > contain int; however, neither can you use variant<string,string,int> > because variant can't take duplicate types. > > However, instead of the current variant, why not use a truly > "tagged" variant which can handle duplicate types by using > the tag to indicate which type? Then there would be no > need for the trailing: > > > attr(bool) > > Thoughts? > > -regards, > Larry > > > I think you ask a good question. I hope somebody has a great solution for the general problem... however you could: typedef tuple< variant< int, string >, int > rule_type; path %= ( ( int_ > attr( 0 ) ) | ( regex_search > attr( 1 ) ) | ( product_name > attr( 2 ) ) ); rule< Iterator, rule_type(), space_type > path; Anybody have the "right" way to do this? michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: Look mom! No semantic actions.Larry Evans wrote:
> What does attr(true) do? I'm guessing it's like eps except it > sets an element in the "corresponding" attribute of of the > lhs. In this case, the path_result_type::is_regex. Is that > right. (I did scan the docs at: > > http://svn.boost.org/svn/boost/trunk/libs/spirit/doc/html/index.html > > but found no mention of "attr"). Here: http://tinyurl.com/yzqcu94 Your guess is correct. Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: another case for tagged variants (was Re: Look mom! No semantic actions.On Mon, Oct 26, 2009 at 7:32 PM, Michael Caisse
<boost@...> wrote: > Larry Evans wrote: >> >> Thanks Michael. I just didn't know where to look. >> >> However, now I'm wondering about generalizing this use-case. >> For example, suppose that instead of having just a string, >> you also had some other type, e.g. int. IOW, instead of the >> above path, you had >> >> path %= ( regex_search >> | product_name >> | int_ >> ) >> >> Now, you can't use tuple<string,bool> because it doesn't >> contain int; however, neither can you use variant<string,string,int> >> because variant can't take duplicate types. >> >> However, instead of the current variant, why not use a truly >> "tagged" variant which can handle duplicate types by using >> the tag to indicate which type? Then there would be no >> need for the trailing: >> >> > attr(bool) >> >> Thoughts? >> >> -regards, >> Larry >> >> >> > > > I think you ask a good question. I hope somebody has a great > solution for the general problem... however you could: > > typedef tuple< variant< int, string >, int > rule_type; > > path %= ( ( int_ > attr( 0 ) ) > | > ( regex_search > attr( 1 ) ) > | > ( product_name > attr( 2 ) ) > ); > > > rule< Iterator, rule_type(), space_type > path; > > > Anybody have the "right" way to do this? I have actually played with this same idea. So often do I want to do something akin to this: variant<string, string, int, float, int> So I have to end up using tagged types and bloats my code elsewhere when reading it: struct string1 { string s; } struct string2 { string s; } And so forth, and use those instead, then I get problems where Spirit cannot set to a struct with a single element type for whatever reason, so I have to use semantic actions instead of auto-rules, and it just snowballs from there. If these two things were fixed, tagged variants and single tuple assignment, my whole grammars could become pure auto-rules. It would be wonderful if what had a variant that you could not assign directly to, but had to use a member function like: template<typename T> assignTo(T t, size_t position); or something. ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: another case for tagged variants (was Re: Look mom! No semantic actions.On Oct 26, 2009, at 9:32 PM, Michael Caisse wrote: > > > I think you ask a good question. I hope somebody has a great > solution for the general problem... however you could: > > typedef tuple< variant< int, string >, int > rule_type; > > path %= ( ( int_ > attr( 0 ) ) > | > ( regex_search > attr( 1 ) ) > | > ( product_name > attr( 2 ) ) > ); > > > rule< Iterator, rule_type(), space_type > path; > > > Anybody have the "right" way to do this? Note expetations here always succeed, so op >() should be op >>() [it is at least as fast as op > () ] I don't know of an another essentially different method. ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: another case for tagged variants (was Re: Look mom! No semantic actions.Carl Barron wrote:
> On Oct 26, 2009, at 9:32 PM, Michael Caisse wrote: > >> I think you ask a good question. I hope somebody has a great >> solution for the general problem... however you could: >> >> typedef tuple< variant< int, string >, int > rule_type; >> >> path %= ( ( int_ > attr( 0 ) ) >> | >> ( regex_search > attr( 1 ) ) >> | >> ( product_name > attr( 2 ) ) >> ); >> >> >> rule< Iterator, rule_type(), space_type > path; >> >> >> Anybody have the "right" way to do this? >> > > Note expetations here always succeed, so op >() should be op >>() > [it is at least as fast > as op > () ] > > I don't know of an another essentially different method. > > That makes sense that they should be the same for speed since attr always succeeds. Is there a subtle (to me) "bug" that I am missing by using > instead of >> ? Thanks - michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: another case for tagged variants (was Re: Look mom! No semantic actions.On 10/26/09 20:32, Michael Caisse wrote:
[snip] > > I think you ask a good question. I hope somebody has a great > solution for the general problem... however you could: > > typedef tuple< variant< int, string >, int > rule_type; > > path %= ( ( int_ > attr( 0 ) ) > | > ( regex_search > attr( 1 ) ) > | > ( product_name > attr( 2 ) ) > ); > > > rule< Iterator, rule_type(), space_type > path; > Yep, that'll work; however, what it does is simply provide a workaround for something that shouldn't have to be worked around. Also, it really wastes a little space. The variant already contains a tag (whose value is returned by variant<...>::which() ); yet, the workaround duplicates that tag with the 2nd element of the tuple. With a truly tagged variant, you wouldn't need the duplication nor would you need to suffix each element in the | with the > attr(tag) eps-like parser. -regards, Larry ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: another case for tagged variants (was Re: Look mom! No semantic actions.On Mon, Oct 26, 2009 at 8:57 PM, Michael Caisse
<boost@...> wrote: > Carl Barron wrote: >> On Oct 26, 2009, at 9:32 PM, Michael Caisse wrote: >> >>> I think you ask a good question. I hope somebody has a great >>> solution for the general problem... however you could: >>> >>> typedef tuple< variant< int, string >, int > rule_type; >>> >>> path %= ( ( int_ > attr( 0 ) ) >>> | >>> ( regex_search > attr( 1 ) ) >>> | >>> ( product_name > attr( 2 ) ) >>> ); >>> >>> >>> rule< Iterator, rule_type(), space_type > path; >>> >>> >>> Anybody have the "right" way to do this? >>> >> >> Note expetations here always succeed, so op >() should be op >>() >> [it is at least as fast >> as op > () ] >> >> I don't know of an another essentially different method. >> >> > Carl - > > That makes sense that they should be the same for speed since attr > always succeeds. Is there a subtle (to me) "bug" that I am missing by using > > instead of >> ? op> is a hair touch of a tiny bit slower then op>>. ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: another case for tagged variants (was Re: Look mom! No semantic actions.Larry Evans wrote:
> However, now I'm wondering about generalizing this use-case. > For example, suppose that instead of having just a string, > you also had some other type, e.g. int. IOW, instead of the > above path, you had > > path %= ( regex_search > | product_name > | int_ > ) > > Now, you can't use tuple<string,bool> because it doesn't > contain int; however, neither can you use variant<string,string,int> > because variant can't take duplicate types. > > However, instead of the current variant, why not use a truly > "tagged" variant which can handle duplicate types by using > the tag to indicate which type? Then there would be no > need for the trailing: > > > attr(bool) > > Thoughts? Larry, that's a very good observation. You have a good point. Let's think about this some more. Cheers, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: Look mom! No semantic actions.Michael Caisse wrote:
> path %= ( regex_search > | > product_name ); > > How about typedef regex_string std::string; typedef prodname_string std::string; rule<Iterator,regex_string()> regex_search; rule<Iterator, prodname_string()> product_name; rule<Iterator,variant<regex_string,prodname_string> path; ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: another case for tagged variants (was Re: Look mom! No semantic actions.On Oct 26, 2009, at 10:57 PM, Michael Caisse wrote: > Carl Barron wrote: >> On Oct 26, 2009, at 9:32 PM, Michael Caisse wrote: >> >>> I think you ask a good question. I hope somebody has a great >>> solution for the general problem... however you could: >>> >>> typedef tuple< variant< int, string >, int > rule_type; >>> >>> path %= ( ( int_ > attr( 0 ) ) >>> | >>> ( regex_search > attr( 1 ) ) >>> | >>> ( product_name > attr( 2 ) ) >>> ); >>> >>> >>> rule< Iterator, rule_type(), space_type > path; >>> >>> >>> Anybody have the "right" way to do this? >>> >> >> Note expetations here always succeed, so op >() should be op >>() >> [it is at least as fast >> as op > () ] >> >> I don't know of an another essentially different method. >> >> > Carl - > > That makes sense that they should be the same for speed since attr > always succeeds. Is there a subtle (to me) "bug" that I am missing > by using > > instead of >> ? Subtle bug? what about a = char_ > int_ | *(char_-'\n') (1) b = char_ >> int_ | *(char_ - '\n') (2) ? "a10" will cause a to fail to match while b would match. a > b means b MUST follow a. if not an error handler will be triggered. ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: another case for tagged variants (was Re: Look mom! No semantic actions.Carl Barron wrote:
> On Oct 26, 2009, at 10:57 PM, Michael Caisse wrote: > > >> Carl Barron wrote: >> >>> On Oct 26, 2009, at 9:32 PM, Michael Caisse wrote: >>> >>> >>> Note expetations here always succeed, so op >() should be op >>() >>> [it is at least as fast >>> as op > () ] >>> >>> I don't know of an another essentially different method. >>> >>> >>> >> Carl - >> >> That makes sense that they should be the same for speed since attr >> always succeeds. Is there a subtle (to me) "bug" that I am missing >> by using > >> instead of >> ? >> > > Subtle bug? what about > > a = char_ > int_ | *(char_-'\n') (1) > b = char_ >> int_ | *(char_ - '\n') (2) > ? > > "a10" will cause a to fail to match while b would match. > > a > b means b MUST follow a. if not an error handler will be > triggered. > > > > Right. I was wondering about the " > attr " which will always succeed. Thanks for the clarification. -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: Look mom! No semantic actions.Dainis Polis wrote:
> Michael Caisse wrote: >> path %= ( regex_search >> | >> product_name ); >> >> > How about > > typedef regex_string std::string; > > typedef prodname_string std::string; I think you git that reversed. > rule<Iterator,regex_string()> regex_search; > rule<Iterator, prodname_string()> product_name; > rule<Iterator,variant<regex_string,prodname_string> path; Won't work. The variant can't hold non-unique types. You cannot have: variant<string, string, string>. I think we really need a special tagged_variant for such cases as Larry hinted. That will give Spirit the /hint/ it needs where to store the successful *tagged* alternatives. Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |