Reusing KHTMLs CSS parser for a KDevelop language plugin

Maksim Orlovich maksim at
Wed Oct 21 21:38:18 BST 2009


> Alternatively to the above, are there maybe KHTML APIs I can use that give
>  me a low-level analysis of a given CSS file? I'd need e.g. a list of rule
>  definitions, imports, charset statements, together with line numbers where
>  they occur. That should actually be enough to build a DUChain.

That exists already --- DOM level 2 CSS is exported to C++, see the header 
files dom/css_*.h. It may not be perfect though, since CSS parsing is freaky, 
and very much non-uniform --- pretty much every property requires special 
parsing code to get right; and so you only get an accurate model for things 
KHTML supports; so for example properties with other vendor prefixes would not 
get much info. Also a lot of other implementations like Gecko simply chose to 
ignore parts of DOM2 CSS, so some methods may not have had much real-life 

There is no line number info, though; and I am not sure def/use is the right 
abstraction, either --- CSS is pattern matched, after all, in a fairly complex 

> Note that most of the above could be applied to other languages as well,
>  most notably JavaScript/ECMA Script and XML/HTML/XHTML.

HTML/XML DOM is public as well. ES AST is way too tied to the implementation 
to be made public, and getting useful dataflow for that abomination of the 
language is borderline impossible (though I suppose kdevelop can afford to be 
unsound?); however it may be possible to abstract something via KJSAPI


More information about the kde-core-devel mailing list