boost-spirit-x3

Parsing CSS with Boost.Spirit X3

我与影子孤独终老i 提交于 2021-01-29 06:23:04
问题 I'm attempting to write a (partial) CSS parser using Boost.Spirit X3. I have the (very) basic setup working: const auto declaration_block_def = '{' >> +declaration >> '}'; const auto declaration_def = property >> ':' >> value >> ';'; const auto property_def = +(char_ - ":"); const auto value_def = +(char_ - ";"); Here value is just a simple string parser, and property a symbol table of all the CSS property names to an enum listing all the properties. But now I wonder if I couldn't in some way

spirit x3 cannot propagate attributes of type optional<vector>

六月ゝ 毕业季﹏ 提交于 2020-01-24 15:48:47
问题 A simple parser as on Coliru. The parser -(+x3::alpha) should be able to propagate an attribute of type boost::optional<std::string> as Qi does. But it does not compile. std::string const input = "abc"; boost::optional<std::string> attr; if(x3::parse(boost::begin(input),boost::end(input), -(+x3::alpha), attr)) { std::cout<<"match!"<<std::endl; } else { std::cout<<"NOT match!"<<std::endl; } 回答1: I don't think the normative claim "should be able [...] as Qi does" cuts wood. X3 is not an

Boost Spirit x3 conditional (ternary) operator parser (follow up question)

核能气质少年 提交于 2020-01-23 17:27:13
问题 This question is a follow up question for the one in Boost Spirit x3 conditional (ternary) operator parser The original question context did not show (my bad!) the ast attributes and the answer therefore could not take all the moving parts into account. This question now shows how the ast attributes looks like and how the ast is used to evaluate the expression with a symbol table. The follow up question is therefore that how the correctly spelled ternary conditional should change the ast

Boost.x3: attribute accumulates between alternatives

你离开我真会死。 提交于 2020-01-10 03:15:30
问题 I have a parser for parsing an Identifier like foo, bar, baz and one for parsing also nested identifiers like foo::bar, foo::bar.baz, foo::bar.baz.baham They both parse into the same ast struct, which looks like this: struct identifier : x3::position_tagged{ std::vector <std::string> namespaces; std::vector <std::string> classes; std::string identifier; }; The parser for an identifier looks like this: #define VEC_ATR x3::attr(std::vector<std::string>({})) //ugly hack auto const identifier_def

x3 linker error with separate TU

怎甘沉沦 提交于 2020-01-02 10:20:02
问题 As my parser grows I separated some rules into different translation units (TU) and the linker problem rises. After weeks of several try&errors without success I reduced my ~50 rules to the (hopefully) minimal example presented here. I've read the related linking errors while separate parser using boost spirit x3 and checked, that I use at the context typedef iso8859_1::space_type and that I invoke iso8859_1::space later on. Also I don't let the compiler deduce the iterator_type. The linker

x3 linker error with separate TU

◇◆丶佛笑我妖孽 提交于 2020-01-02 10:19:10
问题 As my parser grows I separated some rules into different translation units (TU) and the linker problem rises. After weeks of several try&errors without success I reduced my ~50 rules to the (hopefully) minimal example presented here. I've read the related linking errors while separate parser using boost spirit x3 and checked, that I use at the context typedef iso8859_1::space_type and that I invoke iso8859_1::space later on. Also I don't let the compiler deduce the iterator_type. The linker

Boost Spirit x3 not compiling

北慕城南 提交于 2020-01-01 19:30:49
问题 I'm following the x3 documentation on the boost website, and I've tried to augment the example on how to organize code with the stuff explained in the annotations example that comes after. I'm having the following error when compiling the project (either with g++ or MSVC): error: no matching function for call to 'boost::spirit::x3::unused_type::get()' In the first line of function on_success in the following code: // tag used to get the position cache from the context struct annotate_position

Getting into boost spirit; Qi or X3?

烂漫一生 提交于 2019-12-31 02:41:19
问题 I was making an interpreter for a small personal project with a friend; we started implementing all the classes and general structure in which the code would be translated to then execute just to postpone the actual parsing code into these structures. Now we have to build the parser, and after some search I found posts and people all over the place speaking about spirit Qi and spirit X3 as if they were (i think they are) 2 different ways of making a parser, but no-one saying the difference,

Getting into boost spirit; Qi or X3?

ぃ、小莉子 提交于 2019-12-31 02:41:07
问题 I was making an interpreter for a small personal project with a friend; we started implementing all the classes and general structure in which the code would be translated to then execute just to postpone the actual parsing code into these structures. Now we have to build the parser, and after some search I found posts and people all over the place speaking about spirit Qi and spirit X3 as if they were (i think they are) 2 different ways of making a parser, but no-one saying the difference,

boost::spirit::x3 attribute compatibility rules, intuition or code?

余生长醉 提交于 2019-12-29 07:19:09
问题 Is there a document somewhere which describes how various spirit::x3 rule definition operations affect attribute compatibility? I was surprised when: x3::lexeme[ x3::alpha > *(x3::alnum | x3::char_('_')) ] could not be moved into a fusion-adapted struct: struct Name { std::string value; }; For the time being, I got rid of the first mandatory alphabetical character, but I would still like to express a rule which defines that the name string must begin with a letter. Is this one of those