Re: Boost Spirit X3 Symbol table parser segfaults when in a separate compilation unit

Seth <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 28-04-17 13:36, Sigbjørn Lund Olsen wrote:
> I have made a small project which shows what I am trying to achieve and is
> available here: https://github.com/sigbjornlo/spirit_fruit_mcve
I think the problem has been resolved in the X3 develop branch

> My questions:
> - Why does moving the symbol parser to a separate compilation unit cause a
> segmentation fault in this case?
As the analysis confirmed, the symbol table has nothing to do with it.
The expectation point is triggering the use of a `nullptr` rule-name.
That's fixed in https://github.com/boostorg/spirit/pull/229

You should be able to verify this by e.g. replacing the fruit rule with
something like `lexeme["Apples"] >> attr(FRUIT::APPLES) |
lexeme["Oranges"] >> attr(FRUIT::ORANGES)`.

> - What is the "correct" way of making a symbol table reusable in multiple
> parsers? (In the MCVE I obviously only use the fruit parser in one other
> parser, but in my full project I want to use it in several other parsers.

Your way is correct. In order to alleviate SIOF issues, I strongly
suggest making the fruit grammar factory return by reference:
https://github.com/sigbjornlo/spirit_fruit_mcve/pull/1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.