boost.spirit用户手册翻译(29):转义字符分析器

Escape Character Parser

转义字符分析器


The Escape Character Parser is a utility parser, which parses escaped character sequences used in C/C++, LEX or Perl regular expressions. Combined with the confix_p utility parser, it is useful for parsing C/C++ strings containing double quotes and other escaped characters:

转义字符分析器属于工具分析器,用于分析C/C++、LEX或Perl正则表达式中的转移字符串。将之与confix_p工具分析器共同使用,在分析C/C++中由引号引起的字符串方面很有用。

    confix_p('"', *c_escape_ch_p, '"')

There are two different types of the Escape Character Parser: c_escape_ch_p, which parses C/C++ escaped character sequences and lex_escape_ch_p, which parses LEX style escaped character sequences. The following table shows the valid character sequences understood by these utility parsers.

有两种不同的转义字符分析器:c_escape_ch_p,分析C/C++转移字符串,和lex_escape_ch_p,分析LEX风格的转移字符串。下面的表格说明了这些工具分析器所能有效识别的转移字符串。

Summary of valid escaped character sequences


有效转移字符串集
c_escape_ch_p

/b, /t, /n, /f, /r, //, /", /', /xHH, /OOO
where: H is some hexadecimal digit (0..9, a..f, A..F) and O is some octal digit (0..7)

这里H是二进制数字(0..9, a..f, A..F)而O是八进制数(0..7)

lex_escape_ch_p

all C/C++ escaped character sequences as described above and additionally any other character, which follows a backslash

上面的所有C/C++转移字符串,以及紧随反斜线的任意字符

If there is a semantic action attached directly to the Escape Character Parser, all valid escaped characters are converted to their character equivalent (i.e. a backslash followed by a 'r' is converted to '/r'), which is fed to the attached actor. The number of hexadecimal or octal digits parsed depends on the size of one input character. An overflow will be detected and will generate a non-match. lex_escape_ch_p will strip the leading backslash for all character sequences which are not listed as valid C/C++ escape sequences when passing the unescaped character to an attached action.

如果有语义动作挂接在转移字符分析器上,被传递给挂接的动作器的所有的有效转义字符将被转换成与之等价的实际字符(比如一个反斜线后面跟着一个''将被转换为'/r')。所分析出的十六进制或者八进制数值的个数将取决于输入字符的尺寸。而溢出将被检测到并且引发一个匹配失败。 lex_escape_ch_p在分析尚未分析的字符并传递给语义动作时,对所有带反斜线但不是C/C++中有效的转移字符串的字符串,将忽略开头的反斜线。

Please note though, that if there is a semantic action attached to an outermost parser (for instance as in (*c_escape_ch_p)[some_actor], where the action is attached to the kleene star generated parser) no conversion takes place at the moment, but nevertheless the escaped characters are parsed correctly. This limitation will be removed in a future version of the library.

请注意,如果语义动作挂接在最外围的分析器上(比如类似(*c_escape_ch_p)[some_actor],语义动作挂接在克林星分析器上)将不会产生字符的转换,取而代之的是直接把字符串传递给语义动作。这个限制在以后的版本中将被清除。



Powered by Zoundry

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值