python语法中`~`是什么意思

阿卜杜勒·尼亚斯总理

我正在阅读python 语法规范并找到以下语句,

for_stmt: 
    | 'for' star_targets 'in' ~ star_expressions ':' [TYPE_COMMENT] 块 [else_block]

~在这个语法规则什么意思?。语法中使用的其他符号(如&, !, |)已经记录在案,但没有记录~

所用的符号的混合物EBNFPEG特别地,&后面跟有符号、标记或括号的组表示正向前瞻(即需要匹配但不消耗),而!表示负前瞻(即需要匹配)。我们使用|分隔符来表示 PEG 的“有序选择”(按照/传统的 PEG 语法编写

.

想成为蝙蝠侠

它记录在PEP 617下的 Grammar Expressions 中:

~
Commit to the current alternative, even if it fails to parse.

rule_name: '(' ~ some_rule ')' | some_alt
In this example, if a left parenthesis is parsed, then the other alternative won’t be considered, even if some_rule or ‘)’ fail to be parsed.

~基本上表明,一旦你达到它,你就会陷入到具体的规则,如果解析失败不能移动到下一个规则。PEP 617 前面提到的| some_alt可以写在下一行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章