了解ABNF语法“ 0< pchar; gt;"
在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你是正确的。
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 = ""
andpath-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 aspchar
. 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.