Where can I find Webkit's CSS grammar files? [closed]

寵の児 提交于 2019-12-08 14:24:02

问题


Unlike HTML, CSS is a context free grammar. Syntax grammar is usually described in BNF or EBNF notation.

According to Tali Garsiel's articke How Browsers Work, WebKit uses Flex and Bison parser generators to create parsers automatically from CSS grammar files.

As Webkit is an open source project, I would expect these grammar files can be found somewhere in its source code. I haven't been able to find it, though. Can anyone help me out here?


Note 1 :

I'm NOT asking how browsers parse/render CSS / how browsers read and interpret CSS!!

I know that already. In fact, it's explained pretty well in the aforementioned article How Browsers Work. So no, it's not a duplicate of that question.

What I'm looking for, is the specific CSS grammar files that Webkit uses to parse/render CSS, which I haven't been able to find anywhere.


Note 2 :

I'm also NOT asking anyone to recommend or find a book, tool, software library, tutorial or other off-site... at all.

I'm just asking for where to find some files that Webkit uses (or used) for parsing CSS, because I've been unable to find them myself.


Note 3 :

I'm asking this because I'm looking for a convenient way to parse CSS. I want to base this approach on the way a browser parses CSS (more specifically = by analysing how it is parsed by Webkit browsers).

So yes, this question really is a programming question and totally on topic here at Stack Overflow.


回答1:


The bison file (or at least, a version of it) is in the css directory as CSSGrammar.y.in. That file is preprocessed and then run through bison using a perl script.

Apparently the flex scanner was rewritten in 2011/12; see this webkit bug. The handbuilt scanner is part of CSSParser.cpp.

By looking back in the git history, you could find older versions. For example, in the safari-4-branch, I found the following bison and flex files.



来源:https://stackoverflow.com/questions/31721308/where-can-i-find-webkits-css-grammar-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!