SonarQube 库中的 nextNot 函数究竟做了什么?

What does exactly the nextNot function do in SonarQube's library?

你可以在这里看到函数的定义:

* Creates parsing expression - "next not".
* During execution of this expression parser will execute sub-expression once.
* This expression succeeds only if sub-expression fails.
*
* @param e  sub-expression
* @throws IllegalArgumentException if given argument is not a parsing expression
*/
public final Object nextNot(Object e) {
return new NextNotExpression(convertToExpression(e));
}

如果我没理解错的话,如果看到对象e,就会失败

但是,我正在查看 Python 和 PRINT_EXP 的 SonarQube 语法是这样的:

b.rule(PRINT_STMT).is("print", b.nextNot("("), b.firstOf( 
  b.sequence(">>", TEST, b.optional(b.oneOrMore(",", TEST), b.optional(","))), 
  b.optional(TEST, b.zeroOrMore(",", TEST), b.optional(","))));

这是不是说看到括号就认为失败了? 因为在Python3.x中,print是一个函数。

nextNot是一种否定匹配。在您突出显示的示例中,当 print 后跟 (PRINT_STMT 不匹配。

在 Python 3 中对 print 函数的调用应该匹配 EXPRESSION_STMT.

注意:nextNot 是独立于 SonarQube 的 SSLR library 的一部分。