I have so much stuff to do and I've been feeling a little overwhelmed lately. Not depressed, because it's next to impossible to be depressed at a climate including 320 sunny days a year and a beach. So I thought why not drop everything and relax. I'm currently staying at home, enjoying my unused vacation days. So no work, no meetings, no nothing. I thought I should relax by taking on a task that requires some degree of concentration as opposed to just jumping from one task to the next.
The first step is a lexer scanner and I'm happy to share what I committed to github today. It's right here. I called it cssex (yep, cheesy but I didn't want to spend any time thinking of a proper name).
It's not doing much currently but it's a step. It takes a piece of CSS code and tokenizes it producing the following token types:
- white (spaces or tabs)
- line (new lines)
- identifier (could be anything, such as a property or value or font name)
- match (5 combinations of two operators used in attribute matching such as
- operator - such as
. # % *and so on
You can see a test page here and I'll be happy to hear any bug reports. The test page takes CSS, tokenizes it, then recreates the source from the tokens to compare that the original is reproducible. It also highlights the different tokens in different colors and finally dumps the types and values of the tokens (the complete dump is in
As you can see, I'm continuing with the cheesiness:
foreplay.htmlis the test page (instead of "playground")
penthouse.sh(instead of "suite") runs tests with the 213 CSS files from CSSZenGarden.com
sex.jsis the lexer itself which defines the global CSSEX object with two methods -
lex(source)and its opposite
So what's next is a proper parser validating those tokens produced by the lexer. Then the tools such as a minifier, highlighter, lint, and whatnot (for example something that will add automatically all -moz- and -o- and stuff to your