[Spirit] Semantic actions (binary parser) - user error or bug?
Hi, I've come across some behaviour with semantic actions that seems strange. I'm not sure if this is intended or if it is indeed a bug. Please see the attached test case.
[Please do not mail me a copy of your followup]
boost-users@lists.boost.org spake the secret code
I've come across some behaviour with semantic actions that seems strange. I'm not sure if this is intended or if it is indeed a bug.
Seems perfectly normal to me. You need omit[] around stuff that you don't want to appear as part of the attribute for a rule. Since your rule's attribute is only a byte, including big_dword as part of the rule without omit would mean that its part of the attribute for the rule too and that doesn't match the layout of the test struct. -- "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/ Legalize Adulthood! http://legalizeadulthood.wordpress.com
Seems perfectly normal to me. You need omit[] around stuff that you don't want to appear as part of the attribute for a rule. Since your rule's attribute is only a byte, including big_dword as part of the rule without omit would mean that its part of the attribute for the rule too and that doesn't match the layout of the test struct.
Hi, What's wrong with the following code, and how can I fix it? The semantic actions seem to be inconsistent (or maybe I'm using them wrong). No omit, but no value? Thanks.
Seems perfectly normal to me. You need omit[] around stuff that you don't want to appear as part of the attribute for a rule. Since your rule's attribute is only a byte, including big_dword as part of the rule without omit would mean that its part of the attribute for the rule too and that doesn't match the layout of the test struct.
Hi,
What's wrong with the following code, and how can I fix it? The semantic actions seem to be inconsistent (or maybe I'm using them wrong). No omit, but no value?
Semantic actions in Karma are supposed to _supply_ the attribute value to generate output from. Therefore your start rule needs to be written as: start = big_dword >> big_dword[_1 = ref(temp)]; Regards Hartmut --------------- http://boost-spirit.com
2011/5/1 Hartmut Kaiser
Semantic actions in Karma are supposed to _supply_ the attribute value to generate output from. Therefore your start rule needs to be written as:
start = big_dword >> big_dword[_1 = ref(temp)];
I believe it was the Qi part (use %= instead): start %= big_dword >> big_dword [ref(temp) = _1]; Then the 2nd assertion fails at runtime, however: start %= big_dword >> big_dword; works fine...really strange to me... how can the action affect the attribute?
2011/5/1 Hartmut Kaiser
Semantic actions in Karma are supposed to _supply_ the attribute value to generate output from. Therefore your start rule needs to be written as: start = big_dword >> big_dword[_1 = ref(temp)];
I believe it was the Qi part (use %= instead):
start %= big_dword >> big_dword [ref(temp) = _1];
Doh! Sorry for that. I should have read your code more carefully. Regards Hartmut --------------- http://boost-spirit.com
participants (4)
-
Hartmut Kaiser
-
legalize+jeeves@mail.xmission.com
-
TONGARI
-
Vitaly Budovski