的作用是什么? W3C CSS 规范的标记化部分中的意思是什么?

发布于 2024-12-23 05:50:38 字数 782 浏览 7 评论 0原文

自从我使用 cssparser 的糟糕经历以来,我给自己设定了一个任务:使用 Parboiled 在 Java 中实现 CSS 解析器。我已经涵盖了所有颜色规范,但当然我需要所有其余的...

所以,我去寻找 CSS 规范并在 W3C 网站。我现在正在为所有“原子”编写规则,但在 本节

UNICODE-RANGE   u\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?

令我不安的部分是[0-9a-f?]中的问号。

段落标题表明这里使用的正则表达式是 Lex 风格的。 ? 在字符类中没有特殊含义(感谢@scizzo 的确认)。那么,这是 W3C 规范中的拼写错误,还是 ? 在 Unicode 范围内确实允许?如果是的话,这意味着什么?

总结:我有我的答案。然而,该规范是错误的:“问号 unicode 范围”只能是单独的。鉴于上述正则表达式,该表达式将被允许,但显然是非法的:u+4??-733f

Ever since my awful experience with cssparser, I have set myself the task of implementing a CSS parser in Java using Parboiled. I already have all color specification covered, but of course I need all the rest...

So, I went to look for the CSS specification and found it on the W3C website. I am now in the process of writing rules for all "atoms", but found something disturbing in this section:

UNICODE-RANGE   u\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?

The part that disturbs me is the question mark in [0-9a-f?].

The paragraph heading says the regular expressions used here are Lex-style. The ? has no special meaning in a character class (thanks @scizzo for the confirmation). So, is this a typo in the W3C specification, or is ? really allowed in a Unicode range? If yes, what does it mean?

Wrap up: I have my answer. However, the specification is wrong: a "question mark unicode range" can only be by itself. Given the above regex, this expression would be allowed whereas it is clearly illegal: u+4??-733f

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

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

发布评论

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

评论(1

逆光下的微笑 2024-12-30 05:50:38

是的,这是一个字面上的问号。 来自 Flex 文档

请注意,在字符类内部,所有正则表达式运算符都失去了除转义之外的特殊含义
('\') 和字符类运算符 '-'、']' 和 at
课程开始,“^”。

现在,根据 W3C,? 可以用作一种通配符

? 字符表示“任何数字值”(例如 U+4??)

Yup, that's a literal question mark. From the Flex documentation:

Note that inside of a character class, all regular expression operators lose their special meaning except escape
('\') and the character class operators, '-', ']', and, at
the beginning of the class, '^'.

Now, according to the W3C, ? can be used as a kind of wildcard:

? characters imply 'any digit value' (e.g. U+4??)

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