I’m pleased to announce the first release of OCaml-css, a library to parse and print CSS. It can also expand namespaces and perform computations on property values.
Parsing uses Angstrom to dynamically choose the parser when encountering a property declaration. Not all properties are handled yet but the parser can be extended by defining additional properties. Some shorthand properties are handled too. Some @rules are not handled by now, they are parsed and returned as strings, with a warning in log.
I had made a first attempt using regular lexer and menhir too, but css values have so many syntaxes and keywords that the value type became ridiculously complicated. Moreover, when looking at a property’s value, only a subset of the whole value type was really valid. Using Angstrom’s parser combinators is a far better approach IMHO: this ensures that only values that make sense are returned by the parser. And it can be extended by the library’s user.
Yes, I parse the values as strings and have a parser combinator which does similarly to your approach with Angstrong. I should probably spend some time refactoring to actually use ansgstrong!
That is crazy cool, where I can follow/know more about all of this? I see you are not using Github and following the development of those tools make it a little hard for me, do you plan to have mirrors?