On 12/16/13, 10:46 AM, Jeff Walden wrote:
On 12/16/2013 01:17 PM, Gregory Szorc wrote:
Does SpiderMonkey expose documentation blocks to the AST? If not, should it?

No, and probably not.  Comments are not tokens, so they're not in the AST.  
Right now SpiderMonkey pretty much just throws them away (except to the extent 
the comment includes a line break, in which case /*\n*/ and similar represent a 
line break for semicolon-insertion rules).  And it'd be really unfortunate to 
have to include them -- then things like a DoWhileNode would have to be gunked 
up a bunch to store information like in |do { } /* fnord */ while /* quoi */ 
(true);|.

Maybe there's some sort of intelligent exposure that could nonetheless be done. 
 But I doubt it's a good idea to build it atop a parser designed for executing 
code, and not for exactly faithfully representing it.

Perhaps Reflect.parse() could grow a new option to expose "comment" nodes or could attach comment metadata to specific node types? This API is SpiderMonkey proprietary (implying we can do what we want with it) right?

FWIW, someone could build a comment parser on top of Reflect.parse(). But you'd have to scan the lines before each node and parse out comment blocks. Seems much more robust, easier (over the long run), and more beneficial to have the forward-scanning parser in the engine just do it. Perhaps someone should build a proof-of-concept docs parser on top of Reflect.parse()?
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to