c++ - 具有不同字符大小的 spirit::qi::grammar-name

标签 c++ boost grammar boost-spirit-qi

我正在用 spirit::qi 制作一个解析器,目标是让它兼容不同的字符大小。

template < typename Iterator >
struct grammar : qi::grammar < Iterator >
{
    grammar () : grammar::base_type ( file, alter_string_size_to < Iterator::value_type > ( _szFile ) )
    {

    }

    qi::rule < Iterator > file;
};

鉴于此

alter_string_size_to < Iterator::value_type > ( _szFile )

成功返回一个指向包含所需字符大小的 _szFile 的字符串的指针。

当我编译时

Iterator = std::wstring::const_iterator

我收到以下错误消息

cannot convert parameter 2 from 'unsigned short *' to 'const std::string &'

所以 .. grammar::base_type 只需要一个 const std::string & 作为第二个参数。 我的问题是,如何告诉 qi::grammar 期望一个字符串及其 Iterators value_type 大小?

提前致谢!

最佳答案

源码中定义如下:

    grammar(
        start_type const& start
      , std::string const& name_ = "unnamed-grammar")
    : proto::extends<terminal, base_type>(terminal::make(reference_(start)))
    , name_(name_)
    {}

    std::string name_;

所以你不能。正如文档中所述:

name is an optional string that gives the grammar its name, useful for debugging and error handling.

因此,您必须根据它进行自己的查找。

关于c++ - 具有不同字符大小的 spirit::qi::grammar-name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9042708/

相关文章:

c++ - 用 0 重写文件。我究竟做错了什么?

java - JSAPI : Central. createRecognizer 返回 null

compilation - 编译语法时出错

c++ - 指针数组和指向指针数组的指针

c++ - 我怎样才能并行化这个求解器代码

c++ - 在cygwin下 boost c++静态链接路径

python - python装饰器的奇怪语法规范

c++ - 为什么 Sprite 是wiz0;不等同于向导 wiz0();在我的代码中? C2228 错误

c++ - 防止解构宏中定义的匿名变量直到范围结束

c++ - Boost :asio? 的最佳文档