编译错误使用调试语法激活时

编程入门 行业动态 更新时间:2024-10-26 02:36:44
本文介绍了编译错误使用调试语法激活时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图调试,我想在Visual Studio项目中使用一个boost ::精神的语法:这是我的code片断:

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 Private } // namespace StateMachine BOOST_FUSION_ADAPT_STRUCT( StateMachine::Private::LuaParameterData, (std::wstring, name) (std::wstring, type) (std::wstring, unit) (std::wstring, cardinality) (std::wstring, value) ) // From here original file continues namespace StateMachine { namespace Private { namespace qi = boost::spirit::qi; template<typename Iterator> struct LuaParameterDataParser : qi::grammar<Iterator, LuaParameterData(), qi::ascii::space_type> { LuaParameterDataParser() : LuaParameterDataParser::base_type(start) { quotedString %= qi::lexeme['"' >> +(qi::ascii::char_ - '"') >> '"']; start %= qi::lit("\"parameter\"") >> ':' >> '{' >> qi::lit("\"name\"" ) >> ':' >> quotedString >> ',' >> qi::lit("\"type\"" ) >> ':' >> quotedString >> ',' >> qi::lit("\"unit\"" ) >> ':' >> quotedString >> ',' >> qi::lit("\"cardinality\"") >> ':' >> quotedString >> ',' >> qi::lit("\"value\"" ) >> ':' >> quotedString >> '}' ; } qi::rule<Iterator, std::string(), qi::ascii::space_type> quotedString; qi::rule<Iterator, LuaParameterData(), qi::ascii::space_type> start; }; } // namespace Private } // namespace StateMachine BOOST_SPIRIT_DEBUG_RULE(StateMachine::Private::LuaParameterDataParser<std::string::const_iterator>::quotedString);

宏 BOOST_SPIRIT_DEBUG 在项目属性定义的。

当我编译它,我获得的最后一行下面的错误,我用 BOOST_SPIRIT_DEBUG_RULE :

When I compile it I obtain following errors in the last line where I use BOOST_SPIRIT_DEBUG_RULE :

错误C3484:语法错误:预期' - >'的返回类型之前

error C3484: syntax error: expected '->' before the return type

错误C2061:语法错误:标识符'register_node

error C2061: syntax error : identifier 'register_node'

我不知道我做了正确的事情。我想调试我的语法,但我只看到提示调试规则(这里和这里),所以我已经试过来适应我的code。

I don't know if I'm doing the right thing. I want to debug my grammar, but I've seen only hints for debugging rules (here and here) so I've tried to adapt my code.

我在做什么错的,什么我必须为了打印,当我使用这个语法与 phrase_parse ?

What I'm doing wrong and what I must do in order to print debugging information when I use this grammar with phrase_parse?

推荐答案

本场也不是一成不变的。

The field is not static.

另外你不是的显示的的的#define BOOST_SPIRIT_DEBUG 行(也许你在编译器命令行指定它)。

Also you're not showing the #define BOOST_SPIRIT_DEBUG line (perhaps you specify it at the compiler command line).

的典型的方法是使用BOOST_SPIRIT_DEBUG_NODES()例如

The typical approach is to use BOOST_SPIRIT_DEBUG_NODES() e.g.

注:

  • 删除经典包含
  • 任何特别的理由使用 wstring的?
  • drop the classic include
  • any particular reason to use wstring?

编译在Coliru

#define BOOST_SPIRIT_DEBUG #include <boost/fusion/include/io.hpp> //#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 Private } // namespace StateMachine BOOST_FUSION_ADAPT_STRUCT( StateMachine::Private::LuaParameterData, (std::wstring, name) (std::wstring, type) (std::wstring, unit) (std::wstring, cardinality) (std::wstring, value) ) namespace qi = boost::spirit::qi; // From here original file continues namespace StateMachine { namespace Private { template<typename Iterator> struct LuaParameterDataParser : qi::grammar<Iterator, LuaParameterData(), qi::ascii::space_type> { LuaParameterDataParser() : LuaParameterDataParser::base_type(start) { quotedString = qi::lexeme['"' >> +(qi::ascii::char_ - '"') >> '"']; start = qi::lit("\"parameter\"") >> ':' >> '{' >> qi::lit("\"name\"" ) >> ':' >> quotedString >> ',' >> qi::lit("\"type\"" ) >> ':' >> quotedString >> ',' >> qi::lit("\"unit\"" ) >> ':' >> quotedString >> ',' >> qi::lit("\"cardinality\"") >> ':' >> quotedString >> ',' >> qi::lit("\"value\"" ) >> ':' >> quotedString >> '}' ; BOOST_SPIRIT_DEBUG_NODES((start)(quotedString)); } qi::rule<Iterator, std::string(), qi::ascii::space_type> quotedString; qi::rule<Iterator, LuaParameterData(), qi::ascii::space_type> start; }; } // namespace Private } // namespace StateMachine int main() { using It = std::string::const_iterator; std::string const input = R"( "parameter" : { "name" : "name" , "type" : "type" , "unit" : "unit" , "cardinality" : "cardinality", "value" : "value" } )"; It f = input.begin(), l = input.end(); StateMachine::Private::LuaParameterDataParser<It> p; StateMachine::Private::LuaParameterData data; bool ok = qi::phrase_parse(f, l, p, qi::ascii::space, data); if (ok) { std::wcout << L"Parsed: \n"; std::wcout << L"\tname: " << data.name << L'\n'; std::wcout << L"\ttype: " << data.type << L'\n'; std::wcout << L"\tunit: " << data.unit << L'\n'; std::wcout << L"\tcardinality: " << data.cardinality << L'\n'; std::wcout << L"\tvalue: " << data.value << L'\n'; } else { std::wcout << L"Parse failure\n"; } if (f!=l) std::wcout << L"Remaining unparsed: '" << std::wstring(f,l) << L"'\n"; }

打印

<start> <try>\n "parameter"</try> <quotedString> <try> "name" , \n </try> <success> , \n </success> <attributes>[[n, a, m, e]]</attributes> </quotedString> <quotedString> <try> "type" , \n </try> <success> , \n </success> <attributes>[[t, y, p, e]]</attributes> </quotedString> <quotedString> <try> "unit" , \n </try> <success> , \n </success> <attributes>[[u, n, i, t]]</attributes> </quotedString> <quotedString> <try> "cardinality", \n </try> <success>, \n "valu</success> <attributes>[[c, a, r, d, i, n, a, l, i, t, y]]</attributes> </quotedString> <quotedString> <try> "value" \n </try> <success> \n }\n </success> <attributes>[[v, a, l, u, e]]</attributes> </quotedString> <success>\n </success> <attributes>[[[110, 97, 109, 101], [116, 121, 112, 101], [117, 110, 105, 116], [99, 97, 114, 100, 105, 110, 97, 108, 105, 116, 121], [118, 97, 108, 117, 101]]]</attributes> </start> Parsed: name: name type: type unit: unit cardinality: cardinality value: value

更多推荐

编译错误使用调试语法激活时

本文发布于:2023-11-25 17:32:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!