Parsing Jade code

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Parsing Jade code

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:11 pm

by Allistar >> Tue, 18 Sep 2007 4:49:42 GMT

Hi all,
Has anyone done any research or implemented a lex/yacc style parsing system on Jade code? I wish to implement a system that will give me the equivalent of a parse tree for Jade code so I can walk through it an automatically detect bugs and non adherence to development standards. Think of this as like a LINT tool. Rather than parsing the Jade code myself (using standard String manipulation routines) I'd like to implement a proper parser so it is more flexible.

I have looked at the JadeMetadataAnalyzer class but that only reports on feature usage and a small set of statements (like "if" and "return"). I would like the full parse tree, including assignments, comments, variable names etc.

Doing a bit of poking around in the Jade internals I have discovered that the JadeMethod class has two binaries on them: one called "code" and one called "symbolTable" - reverse engineering this is proving difficult. (And it's undocumented, and hence probably unsafe to rely on it).

Does anyone have any suggestions or experience to share with this goal?

Thanks,
Allistar.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Parsing Jade code

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:11 pm

by Allistar >> Thu, 27 Sep 2007 21:42:33 GMT

I've ended up implementing a lexical analyser and parser in Jade which constructs a full AST (abstract syntax tree) of Jade source. This allows us to walk the AST that represents a methods a do a lot of automated checking (from the mundane like "are the variables names sensibly" to the bug hunting like "have all created iterators been deleted in the epilog"). The hardest part was implementing an expression parser that fully honours operator precedence - but more often than not Google comes to the rescue). --
A.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Parsing Jade code

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:11 pm

by Scott >> Fri, 28 Sep 2007 4:38:50 GMT

any plan you methods be open source for others make use it same way?

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Parsing Jade code

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:11 pm

by Allistar >> Sat, 29 Sep 2007 8:41:47 GMT
any plan you methods be open source for others make use it same way?

This has been done as "work for hire" for a client, so essentially it belongs to them. A form of it may appear in the future for public use.
--
A.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 9 guests

cron