From: Kugelman, J. <jku...@pr...> - 2005-05-03 20:54:00
|
Micah Dubinko wrote: >=20 > One of my initial thoughts was to maybe use Lex/Yacc and port the > resulting C code to JS, but upon reflection I don't think this is a > great idea. Even the simplest grammar produces 30-40k of code, and it > would be tedious to track changes. The CSS3 Selectors spec includes a > full grammar, but still... >=20 > Do any of you know of a similar parser-generator that targets JS? >=20 > For CSS3, looking at what's out there already, I found >=20 > http://simon.incutio.com/js/getElementsBySelector.js >=20 > A nice demo, but would take much work to get up to commercial quality. > For example, the tokenizer just splits on space, so selectors like a>b > won't work. Also this code gives no indication as to licensing. This seems small enough that we could reproduce it ourselves if licensing is a no go. Writing a better tokenizer would be no problem though. We could easily reuse much of the code we wrote for the XPath tokenizer. > http://markpasc.org/lj/200304/htmlp.py > > Python, but not too hard to port to JS. Haven't looked at too much. MIT > license. This is an HTML parser, no? > http://dean.edwards.name/my/cssQuery.js.html >=20 > Dean Edwards' IE7 code. Nicely structured, extensible, and surprisingly > compact. Liberal licensing--attribution required and nothing else. This > is a strong possibility to use in ff. Yes, this project is impressive.=20 > http://cvs.sourceforge.net/viewcvs.py/ugo/deng2/com/mozquito/deng/css/ > > From the UGO and DENG projects. GPL license. Another possibility. Seeing as Stefano Debenedetti has been tentatively working with us, this is a strong candidate. I've just invited him to join the mailing list, so hopefully he can give us his opinion. ... Given the relatively small sizes of all of these implementations, perhaps it won't be such a big deal to write our own if we have to. One advantage to doing so would be that a lot of parsing code already exists for the XPath engine, so reusing the XPath code could lead to a lot less code overall than having a separate parser for CSS. Ultimately, my main concern is getting all of the rules for cascading rules 100% correct. FYI, the activity level around here should be ramping up quite a bit soon. We've unfortunately been temporarily distracted by other projects, but that is coming to a close. John |