shapesecurity / shift-parser-js

ECMAScript parser that produces a Shift format AST
http://shift-ast.org/parser.html
Apache License 2.0
249 stars 28 forks source link

Generate AST with comments #352

Closed simondel closed 6 years ago

simondel commented 7 years ago

When I parse the following code on the online parser I don't get any comments in the output:

// Hello world!
/* good morning */

How can I add the comments to the AST?

bakkot commented 7 years ago

You can't. Comments aren't usually included in an AST; the parser discards them.

We'd like to think about how best to represent concrete syntax too, at some point, but I don't think we have a good model for that right now. It's pretty tricky to do well.

michaelficarra commented 7 years ago

Comments will never be attached to the AST because there's no good way to choose which node to associate a comment with. But I can imagine the parse-with-location function also producing a list of comments with their positions.

bakkot commented 6 years ago

Fixed by #365.