2

I am trying the Second Answer of this question. The parsing itself works fine, but after uncommenting the #define BOOST_SPIRIT_DEBUG on the first line, the BOOST_SPIRIT_DEBUG output still does not appear anywhere.

When I add these 3 lines below to the main(), I am seeing all 3 lines appear in my terminal. However, I don't see any parser debug lines. What is missing?

std::cout << "Hello cout" << std::endl;
std::cerr << "Hello cerr" << std::endl;
BOOST_SPIRIT_DEBUG_OUT << "Hello boost spirit debug out" << std::endl;

Probably worth mentioning I am using Qt Creator.

sehe
  • 374,641
  • 47
  • 450
  • 633
dev0
  • 72
  • 5

1 Answers1

1

I cannot reproduce this:

Live On Coliru

#define BOOST_SPIRIT_DEBUG
#include <boost/spirit/include/qi.hpp>

int main() {
    std::cout << "Hello cout" << std::endl;
    std::cerr << "Hello cerr" << std::endl;
    BOOST_SPIRIT_DEBUG_OUT << "Hello boost spirit debug out" << std::endl;
}

Prints

Hello cout
Hello cerr
Hello boost spirit debug out

So all the usual culprits are:

  • build out of date
  • running a different binary than the one built
  • precompiled headers ruining your day? That would [in any compiler I know of] lead to a warning when you include anything before the precompiled header include, but noting it just in case.

Here's that linked second answer demo Live On Coliru with debug output (or without):

<expr_>
  <try>-99</try>
  <function_call_>
    <try>-99</try>
    <fail/>
  </function_call_>
  <value_>
    <try>-99</try>
    <success></success>
    <attributes>[-99]</attributes>
  </value_>
  <success></success>
  <attributes>[-99]</attributes>
</expr_>
input:  -99
eval:   -99

<expr_>
  <try>'string'</try>
  <function_call_>
    <try>'string'</try>
    <fail/>
  </function_call_>
  <value_>
    <try>'string'</try>
    <string_>
      <try>'string'</try>
      <success></success>
      <attributes>[[s, t, r, i, n, g]]</attributes>
    </string_>
    <success></success>
    <attributes>[[s, t, r, i, n, g]]</attributes>
  </value_>
  <success></success>
  <attributes>[[s, t, r, i, n, g]]</attributes>
</expr_>
input:  'string'
eval:   string

<expr_>
  <try>AnswerToLTUAE()</try>
  <function_call_>
    <try>AnswerToLTUAE()</try>
    <success></success>
    <attributes>[42]</attributes>
  </function_call_>
  <success></success>
  <attributes>[42]</attributes>
</expr_>
input:  AnswerToLTUAE()
eval:   42

<expr_>
  <try>ReverseString('strin</try>
  <function_call_>
    <try>ReverseString('strin</try>
    <expr_>
      <try>'string')</try>
      <function_call_>
        <try>'string')</try>
        <fail/>
      </function_call_>
      <value_>
        <try>'string')</try>
        <string_>
          <try>'string')</try>
          <success>)</success>
          <attributes>[[s, t, r, i, n, g]]</attributes>
        </string_>
        <success>)</success>
        <attributes>[[s, t, r, i, n, g]]</attributes>
      </value_>
      <success>)</success>
      <attributes>[[s, t, r, i, n, g]]</attributes>
    </expr_>
    <success></success>
    <attributes>[[g, n, i, r, t, s]]</attributes>
  </function_call_>
  <success></success>
  <attributes>[[g, n, i, r, t, s]]</attributes>
</expr_>
input:  ReverseString('string')
eval:   gnirts

<expr_>
  <try>Concatenate('string'</try>
  <function_call_>
    <try>Concatenate('string'</try>
    <expr_>
      <try>'string', 987)</try>
      <function_call_>
        <try>'string', 987)</try>
        <fail/>
      </function_call_>
      <value_>
        <try>'string', 987)</try>
        <string_>
          <try>'string', 987)</try>
          <success>, 987)</success>
          <attributes>[[s, t, r, i, n, g]]</attributes>
        </string_>
        <success>, 987)</success>
        <attributes>[[s, t, r, i, n, g]]</attributes>
      </value_>
      <success>, 987)</success>
      <attributes>[[s, t, r, i, n, g]]</attributes>
    </expr_>
    <expr_>
      <try> 987)</try>
      <function_call_>
        <try> 987)</try>
        <fail/>
      </function_call_>
      <value_>
        <try> 987)</try>
        <success>)</success>
        <attributes>[987]</attributes>
      </value_>
      <success>)</success>
      <attributes>[987]</attributes>
    </expr_>
    <success></success>
    <attributes>[[s, t, r, i, n, g, 9, 8, 7]]</attributes>
  </function_call_>
  <success></success>
  <attributes>[[s, t, r, i, n, g, 9, 8, 7]]</attributes>
</expr_>
input:  Concatenate('string', 987)
eval:   string987

<expr_>
  <try>Concatenate('The Ans</try>
  <function_call_>
    <try>Concatenate('The Ans</try>
    <expr_>
      <try>'The Answer Is ', An</try>
      <function_call_>
        <try>'The Answer Is ', An</try>
        <fail/>
      </function_call_>
      <value_>
        <try>'The Answer Is ', An</try>
        <string_>
          <try>'The Answer Is ', An</try>
          <success>, AnswerToLTUAE())</success>
          <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  ]]</attributes>
        </string_>
        <success>, AnswerToLTUAE())</success>
        <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  ]]</attributes>
      </value_>
      <success>, AnswerToLTUAE())</success>
      <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  ]]</attributes>
    </expr_>
    <expr_>
      <try> AnswerToLTUAE())</try>
      <function_call_>
        <try> AnswerToLTUAE())</try>
        <success>)</success>
        <attributes>[42]</attributes>
      </function_call_>
      <success>)</success>
      <attributes>[42]</attributes>
    </expr_>
    <success></success>
    <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  , 4, 2]]</attributes>
  </function_call_>
  <success></success>
  <attributes>[[T, h, e,  , A, n, s, w, e, r,  , I, s,  , 4, 2]]</attributes>
</expr_>
input:  Concatenate('The Answer Is ', AnswerToLTUAE())
eval:   The Answer Is 42
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thank you for your feedback @sehe. I will have to try a few other things. – dev0 Aug 18 '20 at 16:17
  • 1
    I found that there was another header file also doing #define BOOST_SPIRIT_DEBUG, and for some reason my system gets confused if there is more than one #define BOOST_SPIRIT_DEBUG. I am now using one "master" #define BOOST_SPIRIT_DEBUG and everything works fine. Sorry for not providing the entire code, this project is rather big. Thanks again! – dev0 Aug 18 '20 at 17:24