了解ABNF语法“ 0< pchar; gt;"

发布于 2025-02-08 23:01:24 字数 640 浏览 3 评论 0原文

rfc 3986

path-empty = 0<pchar>

假设pchar是定义的:

pchar = 'a' / 'b' / 'c'

path-empty匹配什么?如何匹配?

我已经阅读了 wikipedia> wikipedia abnf上的页面。我的猜测是与空字符串(Regex ^(?![\ s \ s]))匹配。如果是这样,为什么甚至引用pchar?在不引用其他规则的情况下,是否没有一种更简单的方法可以匹配ABNF语法中的空字符串?

如何将其翻译成Antlr4?

In RFC 3986, they defined the rule:

path-empty = 0<pchar>

For simplicity, let's assume pchar is defined:

pchar = 'a' / 'b' / 'c'

What does path-empty match and how is it matched?

I've read the Wikipedia page on ABNF. My guess is that matches the empty string (regex ^(?![\s\S])). If that is the case, why even reference pchar? Is there not a simpler way to match the empty string in ABNF syntax without referencing another rule?

How could this be translated to ANTLR4?

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

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

发布评论

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

评论(1

沙沙粒小 2025-02-15 23:01:24

是的,你是正确的。 path-empty派生空字符串。

在ABNF中,规则的右侧必须包含元素,它将是空格,新线和评论以外的任何东西。参见 rfc5234> rfc5234 ,第10页细绳。 path-empty = 0&lt; pchar&gt;是一种方法。它的意思是“ &lt; pchar&gt;的零零”。但是,path-empty =“”path-empty = 0pchar也可以工作。 ABNF并不定义一个是否比另一个优先。

注意,RFC3986规格使用prose-val,即>“” ,0pchar,或者只是&lt; empty String&gt;)。目前尚不清楚为什么,但是它具有相同的效果 - path-empty衍生了空字符串。但是,&lt; pchar&gt;pchar不同。散文价值是添加规则非正式描述的“最后手段”。

在antlr4中,该规则仅为path_empty:;。请注意,ANTLR具有不同的命名约定,该命名定义了Lexer和Parser之间的严格边界。 ABNF没有这种区别。实际上,该语法可以转换为单个Antlr Lexer语法,这是理解Antlr Lexers的力量的一种练习。

Yes, you are correct. path-empty derives the empty string.

In ABNF, the right-hand side of a rule must contain an element, which will be anything other than spaces, newlines, and comments. See rfc5234, page 10. Given this syntax, there are several ways to define the empty string. path-empty = 0<pchar> is one way. It means "exactly zero of <pchar>". But, path-empty = "" and path-empty = 0pchar would also work. ABNF does not define whether one is preferred over the other.

Note, the rfc3986 spec uses a prose-val, i.e., <pchar> instead of the "rulename" pchar (or even "", 0pchar, or just <empty string>). It's unclear why, but it has the same effect--path-empty derives the empty string. But, <pchar> is not the same as pchar. A prose value is a "last resort" way to add a non-formal description of the rule.

In Antlr4, the rule would just be path_empty : ;. Note, Antlr has a different naming convention that defines a strict boundary between lexer and parser. ABNF does not have this distinction. In fact, this grammar could be converted to a single Antlr lexer grammar, an exercise in understanding the power of Antlr lexers.

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