简体   繁体   English

W3C XML建议书用来表示定义的语言

[英]Language that W3C XML Recommendation uses to present definitions

I am trying to read W3C recommendation for XML, and I found myself a bit puzzled by the language used to define things, the one that uses ::= notation. 我试图阅读W3C关于XML的建议,但我发现自己对用于定义事物的语言感到困惑,该语言使用::=表示法。

Most of the time those definitions look like regular expressions: 大多数时候,这些定义看起来像正则表达式:

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

But from time to time I come across strange notation, like the following: 但是我有时会遇到奇怪的符号,如下所示:

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

What does Char - '-' mean? Char - '-'是什么意思? Match anything that Char matches excluding '-' ? 匹配Char匹配的所有内容,但不包括'-'吗?

Where can I find formal definition of that language? 在哪里可以找到该语言的正式定义? I tried to search via "::=" but Google just ignores it. 我尝试通过“ :: =”进行搜索,但Google忽略了它。 The W3C recommendation itself doesn't have any information on the matter. W3C建议本身对此没有任何信息。

It's one of very many variants of BNF (Backus Naur Form) - which as you point out has similarities to regular expressions. 它是BNF(Backus Naur Form)的许多变体之一-正如您所指出的,它与正则表达式相似。

The "except" operator ("-") is a little unusual, in my experience. 根据我的经验,“ except”运算符(“-”)有点不寻常。 (Char - '-') means "Anything that matches Char and does not match '-'" - that is, any character except a hyphen. (Char - '-')意思是“与Char匹配但与'-'不匹配的任何字符”,即除连字符以外的任何字符。

The particular flavour of BNF that the XML specification uses is described in section 6 of the spec: XML规范使用的BNF的特殊风格在规范的第6节中进行了描述:

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

From the XML recommendation : XML建议

The formal grammar of XML is given in this specification using a simple Extended Backus-Naur Form (EBNF) notation. 本规范中使用简单的扩展Backus-Naur形式(EBNF)表示法给出了XML的正式语法。

and explains: 并说明:

'string' matches a literal string matching that given inside the single quotes. 'string'匹配与单引号内给出的文字字符串匹配的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM