-4

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.

Community
  • 1
  • 1
John Slegers
  • 45,213
  • 22
  • 199
  • 169
  • possible duplicate of [How do browsers parse/render CSS?](http://stackoverflow.com/questions/5605368/how-do-browsers-parse-render-css) – Anwar Jul 30 '15 at 10:42
  • @Zeratops : It's not a duplicate of http://stackoverflow.com/questions/5605368/how-do-browsers-parse-render-css. It's a much more specific & much more technical question that hasn't been answered by that question and for which I can't find an answer anywhere else either. – John Slegers Jul 30 '15 at 10:50
  • I really don't understand why this question is getting so many downvotes or why it has been closed. – John Slegers May 02 '16 at 22:02

1 Answers1

2

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.

rici
  • 234,347
  • 28
  • 237
  • 341