如何更改解析器的内部字符类型?

发布于 2024-08-15 17:16:06 字数 592 浏览 4 评论 0原文

我已经使用spirit classic有一段时间了,最​​近开始学习 v2。两者都易于使用且功能强大,足以处理中等解析 问题。

在那些有精神经典和ascii字符的田园日子里, 这项工作只是将 EBNF 调整为 LL 形式。但最后,我必须 处理 i18n。

我的想法实在是太粗俗了。制作一个迭代的前向迭代器 任何编码的输入文本字节流。迭代器处理 这些编码转换工作并向解析器提供 utf16/32 代码 单元(迭代器可以通过 iconv 或 icu4c 轻松实现)。

代码单元的类型应该是解析器处理的内部char类型。 但读完文档后,我只能找到几个 原始迭代器模板有一个显式的 char_t 参数。做 这意味着我必须重新表述那些数字、指令、扫描仪和 ETC。?

我还查看了 v2 文档。它提供了一种命名空间方式 一切都是一致的,但仍然没有太多关于如何明确地 更改内部字符类型。我再次搜索了邮件列表 存档,但似乎那些 unicode 和其他编码相关的帖子是 仍然悬而未决。有人告诉我精神仍然有效 通过那些具有不同编码的文件。所以我测试了解析器 使用不同编码但内容相同的文件。多个MBCS 编码的文件通过了测试,随便一些utf8文件也通过了。 但其他编码大多数时候都会失败。

I've been using spirit classic for quite a while and recently start learning
v2. Both are easy to use and powerful enough to handle moderate parsing
issue.

In those idyllic days with the spirit classic and ascii characters,
the job is simply adapting an EBNF to LL form. But finally, I have to
deal with the i18n.

My thought is really crude. Make a forward iterator which iterates
over the input text byte stream of any encoding. The iterator handles
these encoding conversion job and feeds the parser with utf16/32 code
unit(the iterator could be easily implemented by either iconv or icu4c).

The type of code unit should be the internal char type processed by parser.
But after reading through the doc, I could find only several
primitive, iterator templates have a explicit char_t parameter. Does
that mean I have to reformulate those numerics, directives, scanners,and
etc.?

I also checked out the v2 doc. It offers a namespace way to make
everything consistent, but still not too much about how to explicitly
change the internal char type. Again, I searched the mailing list
archive, but seems those unicode and other encoding related post is
still up in the air. Some one told me that spirit could still work
through those files with different encoding. So I tested the parser
using files with different encoding but same content. Several MBCS
encoded files passed the test, and casually some utf8 file also passed.
But other encoding failed most of the time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜点 2024-08-22 17:16:06

我怀疑您已经找到 char_
字符编码命名空间,来自 Boost Spirit 网站。

最后一页包含有用的注释

“我们为 Spirit 将支持的每个字符集都有一个命名空间。其中包括 ascii、iso8859_1、standard 和 standard_wide(以及将来的 unicode)。”

换句话说,boostspirit 目前并不真正支持 unicode。它在他们的待办事项清单上。

同时,您可以尝试像这样的笨拙解决方法:

my_tag_ = lit("<") >> byte_ >> lit(">");

它将匹配恰好出现在尖括号之间的任何二进制字符串,前提是您不使用任何与字符集相关的过滤器。

I suspect you have already found char_
and character encoding namespace from the Boost Spirit web site.

The last page includes the helpful comment

"We have a namespace for each character set Spirit will be supporting. That includes ascii, iso8859_1, standard and standard_wide (and in the future, unicode)."

In other words boost spirit doesn't really support unicode at the moment. It's on their TODO list.

In the mean time you could try a kludgy workaround like this:

my_tag_ = lit("<") >> byte_ >> lit(">");

which will match any binary string which happens to appear between angle brackets, providing you don't use any charset dependant filter on it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文