W3C XML 建议书用于呈现定义的语言

Language that W3C XML Recommendation uses to present definitions

我正在尝试阅读 W3C 对 XML 的推荐,但我发现自己对用于定义事物的语言(使用 ::= 符号的语言)感到有些困惑。

大多数时候这些定义看起来像正则表达式:

STag       ::=      '<' Name (S Attribute)* S? '>'

但我时不时会遇到一些奇怪的符号,例如:

Comment    ::=      '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'

Char - '-'是什么意思?匹配 Char 匹配的任何内容,不包括 '-'?

在哪里可以找到该语言的正式定义?我试图通过“::=”搜索,但 Google 只是忽略了它。 W3C 推荐本身没有关于此事的任何信息。

来自XML recommendation

The formal grammar of XML is given in this specification using a simple Extended Backus-Naur Form (EBNF) notation.

并解释:

'string' matches a literal string matching that given inside the single quotes.

它是 BNF(Backus Naur 形式)的众多变体之一 - 正如您所指出的,它与正则表达式有相似之处。

根据我的经验,"except" 运算符(“-”)有点不寻常。 (Char - '-') 表示 "Anything that matches Char and does not match '-'" - 即除连字符之外的任何字符。

XML 规范使用的 BNF 的特殊风格在规范的第 6 节中进行了描述:

https://www.w3.org/TR/REC-xml/#sec-notation