boost-spirit

Parsing imperial values using boost spirit (qi)

て烟熏妆下的殇ゞ 提交于 2019-12-08 17:51:25
I'm a spirit beginner I'd like to parse an imperial string value into a struct using spirit. The input should accept following syntaxes: 5'3"1/2 5'1/2 3"1/2 the struct imp_constant looks like this, please note stream operator below, I'll print results as this operator does: struct imp_constant { explicit imp_constant(unsigned int feet=0 ,unsigned int inch=0 ,unsigned int fracn=0 ,unsigned int fracd=1) :feet_(feet),inches_(inch),fracn_(fracn),fracd_(fracd){} unsigned int feet_,inches_,fracn_,fracd_; }; std::ostream& operator<<(std::ostream& os, imp_constant const& cst) { if (cst.feet_) os <<

128 bit string to array using boost::spirit::*

牧云@^-^@ 提交于 2019-12-08 16:27:31
I am currently starting with boost::spirit::*. I try to parse a 128 bit string into a simple c array with corresponding size. I created a short test which does the job: boost::spirit::qi::int_parser< boost::uint8_t, 16, 2, 2 > uint8_hex; std::string src( "00112233445566778899aabbccddeeff" ); boost::uint8_t dst[ 16 ]; bool r; for( std::size_t i = 0; i < 16; ++i ) { r = boost::spirit::qi::parse( src.begin( ) + 2 * i, src.begin( ) + 2 * i + 2, uint8_hex, dst[ i ] ); } I have the feeling that this is not the smartest way to do it :) Any ideas how to define a rule so I can avoid the loop ? Update:

Boost Spirit grammar eol

浪子不回头ぞ 提交于 2019-12-08 13:43:30
I am trying to parse files of the following form: // comment bla bla [sectionname] key = value key2=value2 // comment key = value [anothersection] ... using the following code. Unfortunately, it reports the last eol as an error although all eols at the end should be accepted by: (*qi::eol > -(sectionGrammar > *(+qi::eol > sectionGrammar)) > *qi::eol), Besides I really don't know how to parse comments properly without taking the eol which is required for the next key-value pair which is the reason I didn't placed in in the Skipper (only ascii::blank). The last issue I have is that I don't know

boost spirit - improving error output

可紊 提交于 2019-12-08 12:25:21
问题 This question leads on from its predecessor here: decoding an http header value The Question: In my test assertion failure, I am printing out the following contents of error_message : Error! Expecting <alternative><media_type_no_parameters><media_type_with_parameters> in header value: "text/html garbage ; charset = \"ISO-8859-5\"" at position: 0 Which is unhelpful... What is the correct way to get a nice syntax error that says: Error! token_pair has invalid syntax here: text/html garbage ;

Boost spirit x3 example calculator (calc8, calc9) linker error

若如初见. 提交于 2019-12-08 08:28:23
问题 I'm very new with boost spirit (and with boost). Its very interesting library. I use qtcreator + MinGW 5.3. I simply add every source file from git_hub_calc8 into new project and add some boost library, but i got the following error trying to build (All other examples work fine) C:\Program Files\boost\boost\boost\spirit\home\x3\nonterminal\rule.hpp:113: ошибка: undefined reference to `bool client::parser::parse_rule<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char,

How to use boost spirit list operator with mandatory minimum amount of elements?

旧巷老猫 提交于 2019-12-08 08:09:53
问题 I would like to parse dot language (http://www.graphviz.org/content/dot-language). It's a graph definition language that defines nodes and connections between them. A typical statement looks like node1->node2->node3; . It would be nice to use a boost::spirit list operator % to make a list of nodes. A naive approach would be: edge_stmt %= ( node_or_subgraph(_r1) % (qi::eps(_r1) >> tok.diredgeop | tok.undiredgeop) ) >> -attr_list; _r1 indicates if this is directed or undirected graph, diredgeop

Discarding parsed result after semantic action

只谈情不闲聊 提交于 2019-12-08 08:06:05
问题 In Boost.Spirit one can read from a stream to a std::vector simply by doing: #include<vector> #include<boost/spirit/include/qi.hpp> namespace sqi = boost::spirit::qi; int main(){ std::string const v_str = "AA BB CC"; std::vector<std::string> v; auto it = begin(v_str); bool r = sqi::phrase_parse(it, end(v_str), (*sqi::lexeme[+sqi::char_("A-Z")]), sqi::space, v); assert( v.size() == 3 and v[2] == "CC" ); } However, it happens that I know the number of elements in advance because of the input

Error when compiling a grammar with debug activated

泄露秘密 提交于 2019-12-08 07:44:33
问题 I'm trying to debug a boost::spirit grammar that I want to use in a Visual Studio project: This is my code snippet: #include <boost/spirit/include/classic.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/adapt_struct.hpp> // This is pasted and copied from another header file namespace StateMachine { namespace Private { struct LuaParameterData { std::wstring name; std::wstring type; std::wstring unit; std::wstring cardinality; std::wstring value; }; } // namespace

How to avoid boost::phoenix when generating with boost::spirit::karma

百般思念 提交于 2019-12-08 07:44:25
问题 I'm a victim of error "LNK1179: invalid or corrupt file: duplicate COMDAT" and these sources lead me to believe that by not using phoenix I could avoid this error. (This is a follow-up to my previous question.) I want to replace boost::phoenix with something else. Maybe boost::bind but I don't see how I can give it access to karma::_val . The following code fails to compile on VC9 with error C2825: 'F': must be a class or namespace when followed by '::' #include <boost/config/warning_disable

Boost Karma: generate default text when boost::optional is unset

筅森魡賤 提交于 2019-12-08 05:37:56
问题 Consider the following program: using FooVariant = boost::variant<std::string, int>; using FooOptional = boost::optional<FooVariant>; template<typename OutputIt = boost::spirit::ostream_iterator> struct FooGenerator : boost::spirit::karma::grammar<OutputIt, FooOptional()> { FooGenerator() : FooGenerator::base_type(start_) { namespace bsk = boost::spirit::karma; foovar_ = bsk::auto_; start_ = -foovar_; } boost::spirit::karma::rule<OutputIt, FooVariant()> foovar_; boost::spirit::karma::rule