相关疑难解决方法(0)

提升精神船长问题

我对提升精神队长有困难.

我需要解析一个这样的文件:

ROW int
int [int, int]
int [int, int]
...
Run Code Online (Sandbox Code Playgroud)

只有在第一个int之后添加'_'时,我能够毫无问题地解析它(感谢stackoverflow;).

事实上,我认为船长在第一个int之后吃了行尾,所以第一个和第二个(在第二行)看起来只有一个int.我不明白如何保持eol但是吃空间.我找到了使用自定义解析器的示例,如此处和此处.

我尝试了qi :: blank,自定义解析器,单一规则点亮('')无论我使用什么队长,空间和eol总是吃.

我的语法是:

一行:

struct rowType
{
    unsigned int number;
    std::list<unsigned int> list;
};
Run Code Online (Sandbox Code Playgroud)

存储在结构中的完整问题:

struct problemType
{
    unsigned int ROW;
    std::vector<rowType> rows;
};
Run Code Online (Sandbox Code Playgroud)

行解析器:

template<typename Iterator>
struct row_parser : qi::grammar<Iterator, rowType(), qi::space_type>
{
    row_parser() : row_parser::base_type(start)
    {

        list  = '[' >> -(qi::int_ % ',') >> ']';
        start = qi::int_ >> list;
    }

    qi::rule<Iterator, rowType(), qi::space_type> start;
    qi::rule<Iterator, std::list<unsigned int>(), qi::space_type> list; …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-spirit boost-spirit-qi

7
推荐指数
1
解决办法
4094
查看次数

使用Boost.Spirit编译一个简单的解析器

我正在攻击的一个简单的骨架实用程序的一部分我有一个语法来触发文本中的替换.我认为这是一种很好的方式来适应Boost.Spirit,但模板错误是一种独特的喜悦.

以下是完整的代码:

#include <iostream>
#include <iterator>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>

namespace bsq = boost::spirit::qi;

namespace {
template<typename Iterator>
struct skel_grammar : public bsq::grammar<Iterator> {
    skel_grammar();

private:
    bsq::rule<Iterator> macro_b;
    bsq::rule<Iterator> macro_e;
    bsq::rule<Iterator, bsq::ascii::space_type> id;
    bsq::rule<Iterator> macro;
    bsq::rule<Iterator> text;
    bsq::rule<Iterator> start;
};

template<typename Iterator>
skel_grammar<Iterator>::skel_grammar() : skel_grammar::base_type(start)
{
    text = bsq::no_skip[+(bsq::char_ - macro_b)[bsq::_val += bsq::_1]];
    macro_b = bsq::lit("<<");
    macro_e = bsq::lit(">>");
    macro %= macro_b >> id >> macro_e;
    id %= -(bsq::ascii::alpha | bsq::char_('_'))
        >> +(bsq::ascii::alnum | bsq::char_('_'));
    start = *(text | macro); …
Run Code Online (Sandbox Code Playgroud)

c++ boost-spirit

6
推荐指数
1
解决办法
1286
查看次数

用提升精神解析逃脱的弦乐

我正在使用Spirit 2.4,我想要解析这样的结构:

文字{text_field};

关键是text_field是一个带有符号'{','}'和'\'的转义字符串.我想使用qi为此创建一个解析器.我一直在尝试这个:

using boost::spirit::standard::char_;
using boost::spirit::standard::string;
using qi::lexeme;
using qi::lit;

qi::rule< IteratorT, std::string(), ascii::space_type > text;
qi::rule< IteratorT, std::string(), ascii::space_type > content;
qi::rule< IteratorT, std::string(), ascii::space_type > escChar;


text %= 
  lit( "Text" ) >> '{' >>
    content >>
  "};"
  ;

content %= lexeme[ +( +(char_ - ( lit( '\\' ) | '}' ) )  >> escChar ) ];

escChar %= string( "\\\\" ) 
  | string( "\\{" ) 
  | string( "\\}" );
Run Code Online (Sandbox Code Playgroud)

但是甚至没有编译.任何的想法?

c++ boost boost-spirit boost-spirit-qi

5
推荐指数
1
解决办法
2641
查看次数

使用boost :: spirit解析引用的字符串

我想解析一个句子,其中一些字符串可能不加引号,"引用"或"引用".下面的代码几乎可以工作 - 但它无法匹配收尾报价.我猜这是因为qq参考.修改在代码中被注释,修改引用"引用"或"引用"也解析并帮助显示原始问题与结束引用.该代码还描述了确切的语法.

要完全清楚:不带引号的字符串解析.引用的字符串'hello'将解析打开的引号',所有字符 hello,但然后无法解析最终引用'.

我做了另一次尝试,类似于boost教程中的开始/结束标记匹配,但没有成功.

template <typename Iterator>
struct test_parser : qi::grammar<Iterator, dectest::Test(), ascii::space_type>
{
    test_parser()
        :
    test_parser::base_type(test, "test")
    {
        using qi::fail;
        using qi::on_error;
        using qi::lit;
        using qi::lexeme;
        using ascii::char_;
        using qi::repeat;
        using namespace qi::labels;
        using boost::phoenix::construct;
        using boost::phoenix::at_c;
        using boost::phoenix::push_back;
        using boost::phoenix::val;
        using boost::phoenix::ref;
        using qi::space;

        char qq;          

        arrow = lit("->");

        open_quote = (char_('\'') | char_('"')) [ref(qq) = _1];  // Remember what the opening quote was
        close_quote = lit(val(qq)); …
Run Code Online (Sandbox Code Playgroud)

c++ parsing boost boost-spirit boost-spirit-qi

5
推荐指数
1
解决办法
6174
查看次数

提升精神在服务器应用程序上实现小型单行DSL

如果之前已经回答过这个问题,请道歉.

我想在我工作的服务器应用程序中插入一个小型DSL.语法很简单,即使在这个早期阶段,我也很难过.我无法理解如何在精神上构建语法.

以下是我要测试的语法示例:

WHERE [not] <condition> [ and | or <condition> ] <command> [parameters]
Run Code Online (Sandbox Code Playgroud)

WHERE子句将通过测试内部存储上的命名属性来从内部存储中选择多个对象.然后将所选对象的矢量作为输入传递给命令对象.

我想对每个对象执行两种可能的测试:

<property> = "value"
Run Code Online (Sandbox Code Playgroud)

和

<property> like <regexp>
Run Code Online (Sandbox Code Playgroud)

还有2个命令:

print <propertyName> [, <propertyName> [...]]
Run Code Online (Sandbox Code Playgroud)

和

set <propertyName> = "value" [, <propertyName> = "value" [...] ]
Run Code Online (Sandbox Code Playgroud)

所以语法的例子是:

where currency like "GBP|USD" set logging = 1, logfile = "myfile"
Run Code Online (Sandbox Code Playgroud)

和

where not status = "ok" print ident, errorMessage
Run Code Online (Sandbox Code Playgroud)

我知道这是一个很大的问题,但我想知道是否有任何精神专家可以在几秒钟内完成这个语法?我解析LIKE和=,但在尝试将它与AND,OR和NOT混合时卡住了.对我来说,问题是在思考精神如何解决这个问题时不知道从哪里开始.

c++ dsl boost boost-spirit boost-spirit-qi

2
推荐指数
1
解决办法
968
查看次数

标签 统计

boost-spirit ×5

c++ ×5

boost ×4

boost-spirit-qi ×4

dsl ×1

parsing ×1