tags:

views:

2565

answers:

6

I've seen CSS parsers in other languages, and they don't look very complex (the grammar is remarkably simple). I want one in C# (er, .NET), but I can't seem to find one, and I'd rather not write one if I can reasonably avoid it. Does one exist?

+4  A: 

A quick search turned up this, but I've never used it: http://www.codeproject.com/KB/recipes/CSSParser.aspx

Jon Tackabury
+1  A: 

And a slightly slower search turns up this one: http://blog.dynamicprogrammer.com/2008/01/20/CSSParserClassInNET.aspx

mercator
+1  A: 

Here you can find another one especially for C# with sample source.

BloodySmartie
A: 

I wrote one, using the grammar specified in the CSS 2.1 spec. I have also released it now: for details, see http://www.modeltext.com/css/

ChrisW
Cool. Is it available for the rest of us to try/buy?
Jørn Schou-Rode
Send email: my gmail id is "cwellsx".
ChrisW
@Jørn It's available now.
ChrisW
+1  A: 

There is a CSS grammar file for GoldParser:

http://www.devincook.com/goldparser/grammars/index.htm

GoldParser is easy to include in a C# project, and generates an real LALR parser - not some regex hack.

LALR parser - not some regex Info on their site"GOLD grammars are based on Backus-Naur form and regular expressions"
Justin
Good point, regexs are cool. Rolling a parser by hand isn't
This is a very simplified version of the CSS grammar. Instead I ported the CSS reference grammer (from the CSS 2.1 spec) to work with the GOLD parser ... and I've written a C# assembly to implement the rest of it (use the parser output to compute the style for an element in a DOM, using rule specificity, inheritance, default values, etc.).
ChrisW
+1  A: 

Have you tried the one featured in JsonFx? It's written in C#, parses CSS3 syntax and is distributed under a MIT style license.

m0sa