How Firefox builds its CSS tokenizer

Here's a little excerpt taken from the nsCSSScanner.cpp library of the Firefox source code. Notice of the CSS lexical table is build token by token.

void
 nsCSSScanner::BuildLexTable()
 {
   gLexTableSetup = PR_TRUE;
 
   PRUint8* lt = gLexTable;
   int i;
   lt[CSS_ESCAPE] = START_IDENT;
   lt['-'] |= IS_IDENT;
   lt['_'] |= IS_IDENT | START_IDENT;
   lt[' '] |= IS_WHITESPACE;   // space
   lt['\t'] |= IS_WHITESPACE;  // horizontal tab
   lt['\r'] |= IS_WHITESPACE;  // carriage return
   lt['\n'] |= IS_WHITESPACE;  // line feed
   lt['\f'] |= IS_WHITESPACE;  // form feed
   for (i = 161; i <= 255; i++) {
     lt[i] |= IS_IDENT | START_IDENT;
   }
   for (i = '0'; i <= '9'; i++) {
     lt[i] |= IS_DIGIT | IS_HEX_DIGIT | IS_IDENT;
   }
   for (i = 'A'; i <= 'Z'; i++) {
     if ((i >= 'A') && (i <= 'F')) {
       lt[i] |= IS_HEX_DIGIT;
       lt[i+32] |= IS_HEX_DIGIT;
     }
     lt[i] |= IS_IDENT | START_IDENT;
     lt[i+32] |= IS_IDENT | START_IDENT;
  }
}

Firefox 3.6 source code: part 2

Some major changes at first glance:

  1. nsSpaceManager's gone. The SpaceManager handled CSS floats
  2. html.css now includes also style rules for the HTML 5 video element
  3. new headers and classes for handling the newly supported CSS features (such as media queries; see /layout/style)

Documentation is still obsolete, but new test cases have been added (all taken from Bugzilla reports.

Firefox 3.6 source code: part 1

After receiving an email from Boris Zbarky where he said that some components of Gecko are no longer available (allowing me to correct some wrong ideas about Gecko), I decided to download the latest version of the source code to keep me up to date. You can find everything at ftp.mozilla.org (anonymous login). I've just finished to download it and, due to the enormous amount of files and libraries, I'll need a lot of spare time to look through it! Anyway, I'll let you know.