Re: X3 employee example with semantic actions
Larry Evans <[email protected]> Sun, 3 Jun 2018 12:01:04 -0500
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 05/30/2018 04:50 PM, Henri Menke wrote:
>
>
> On 31/05/18 03:16, Maarten Verhage wrote:
>> Dear people,
>>
>>
>>
>> What would help me in understanding Spirit better is when I can
>> clearly see
>> how the parsed attributes are stored into the data structure. So, I’m
>> aiming
>> for semantic actions to do the work.
>
> It is much easier than that. Just add
>
> #define BOOST_SPIRIT_DEBUG
>
> before including any Spirit headers. Then in the grammar of the
> employee example you add
>
> BOOST_SPIRIT_DEBUG_NODE(quoted_string);
> BOOST_SPIRIT_DEBUG_NODE(start);
>
> This will make Spirit print the AST in XML. Here is a shortened version
> of the output I got (the first line is my input):
>
> employee{50, "Simpson", "Homer", 1500.00}
> <start>
> <try>employee{50, "Simpso</try>
> <quoted_string>
> <try> "Simpson", "Homer",</try>
> <success>, "Homer", 1500.00}</success>
> <attributes>[[S, i, m, p, s, o, n]]</attributes>
> </quoted_string>
> <quoted_string>
> <try> "Homer", 1500.00}</try>
> <success>, 1500.00}</success>
> <attributes>[[H, o, m, e, r]]</attributes>
> </quoted_string>
> <success></success>
> <attributes>[[50, [S, i, m, p, s, o, n], [H, o, m, e, r],
> 1500]]</attributes>
> </start>
> -------------------------
> Parsing succeeded
> got: [50, Simpson, Homer, 1500]
>
[snip]
I was having trouble with this. I was getting error about
BOOST_SPIRIT_DEBUG_NODE not being defined:
x3-employee-beg_end_attr_actions.cpp:94:9: error: unknown type name
'BOOST_SPIRIT_DEBUG_NODE'
BOOST_SPIRIT_DEBUG_NODE(employee);
^
1 error generated.
So, grep'ed for that macro and found:
-*- mode: compilation; default-directory:
"~/prog_dev/boost/releases/ro/boost_1_67_0/boost/spirit/" -*-
Compilation started at Sun Jun 3 11:55:24
find . -name \*.hpp -exec grep BOOST_SPIRIT_DEBUG_NODE {} \; -ls
#if !defined(BOOST_SPIRIT_DEBUG_NODE)
#define BOOST_SPIRIT_DEBUG_NODE(r) \
#endif // !defined(BOOST_SPIRIT_DEBUG_NODE)
9313117 16 -rw-rw-r-- 1 evansl evansl 6710 Apr 11 08:49
./home/classic/debug.hpp
#if !defined(BOOST_SPIRIT_DEBUG_NODE_HPP)
#define BOOST_SPIRIT_DEBUG_NODE_HPP
#endif // !defined(BOOST_SPIRIT_DEBUG_NODE_HPP)
9313015 20 -rw-rw-r-- 1 evansl evansl 10152 Apr 11 08:49
./home/classic/debug/debug_node.hpp
#if !defined(BOOST_SPIRIT_DEBUG_NODE)
#define BOOST_SPIRIT_DEBUG_NODE(r)
#endif // !defined(BOOST_SPIRIT_DEBUG_NODE)
9313016 12 -rw-rw-r-- 1 evansl evansl 2957 Apr 11 08:49
./home/classic/debug/minimal.hpp
#if !defined(BOOST_SPIRIT_DEBUG_NODE)
#define BOOST_SPIRIT_DEBUG_NODE(r) r.name(#r); debug(r)
#define BOOST_SPIRIT_DEBUG_NODE(r) r.name(#r);
9313177 16 -rw-rw-r-- 1 evansl evansl 4313 Apr 11 08:49
./home/karma/nonterminal/debug_handler.hpp
#if !defined(BOOST_SPIRIT_DEBUG_NODE)
#define BOOST_SPIRIT_DEBUG_NODE(r) r.name(#r); debug(r)
#define BOOST_SPIRIT_DEBUG_NODE(r) r.name(#r)
#define BOOST_SPIRIT_DEBUG_NODE_A(r, _, name)
\
BOOST_SPIRIT_DEBUG_NODE(name);
\
#define BOOST_SPIRIT_DEBUG_NODES(seq)
\
BOOST_PP_SEQ_FOR_EACH(BOOST_SPIRIT_DEBUG_NODE_A, _, seq)
\
9313319 16 -rw-rw-r-- 1 evansl evansl 4719 Apr 11 08:49
./home/qi/nonterminal/debug_handler.hpp
Compilation finished at Sun Jun 3 11:55:25
So it appears that only works for classic or karma but not for x3?
-regards,
Larry
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general