CSSParser
South Ural State University / December 2001
Goals
- Parse designer‑provided CSS so the WYSIWYG editor could present only approved styles in a dropdown, helping end users apply consistent, visually coherent formatting.
- Provide a structured representation of CSS1 and CSS2 stylesheets that the editor could interpret and manipulate.
- Ensure accurate and standards‑compliant parsing of selectors, properties, and rules as the CSS specifications evolved.
- Integrate cleanly with the in‑house CMS so the editor could rely on a stable DOM representation generated by the parser.
The parser was implemented in C++, at a time when robust, browser‑like parsing libraries simply didn’t exist for Windows developers. Modern DOM implementations were still years away, so I designed and exposed my own Document Object Model interface, giving our application a structured, tree‑based representation of the input data that felt similar to what contemporary browsers provide today. To build the core of the parser, I used YACC (Yet Another Compiler Compiler), which generated the parsing logic from a formal grammar specification. This resulted in a clean separation between two major components: a grammar written in a Backus–Naur Form–style notation, defining the syntactic rules of the language, and a lexical analyzer responsible for tokenizing the raw input stream. Together, these pieces formed a fully custom parsing pipeline tailored to our domain. Because our main application was written in Visual Basic and running in a classic ASP environment, the parser needed to be accessible through COM. I packaged the entire system as a COM/ActiveX component, complete with type libraries and automation‑friendly interfaces, so it could be instantiated directly from VB code. This allowed the legacy ASP application to work with a sophisticated C++ parsing engine as if it were a native part of the platform, bridging two very different technologies in a way that was both seamless and maintainable.
Outcomes
- The WYSIWYG editor was able to present only designer‑approved styles, which kept user‑generated content visually consistent and prevented accidental “off‑brand” formatting.
- End users could apply styles confidently through a simple dropdown, while the underlying system reliably mapped those selections back to the correct CSS rules.
- The CMS produced cleaner, more uniform pages because the parser enforced a structured interpretation of the stylesheet rather than relying on ad‑hoc string handling.
- As CSS1 and CSS2 features were added, the editor automatically benefited from the expanded parsing capabilities without requiring changes to the rest of the application.
- The centralized DOM representation made it easier for other CMS components to inspect, validate, or transform style information, improving maintainability across the system.