stil4m / elm-syntax

Elm syntax in Elm
MIT License
94 stars 28 forks source link

Collect documentation comments for declarations while parsing #218

Closed jfmengels closed 4 months ago

jfmengels commented 4 months ago

Currently, all comments are collected in the state. This includes -- xyz and {- xyz -} comments, but also {-| xyz -} comments that are used for declaration comments (top-level declarations only, it's a syntax error anywhere else, probably worth turning into a parsing error).

Then, in the post-processing done in Elm.Processing, we get the list of comments from the file, then we loop through the declarations and attach the comment to the declaration. This is wasteful, and we should be able to get rid of this post-processing step.

For context, removing this post-processing step was the main purpose for the pratt-parser branch, because re-balancing the tree based around the use of operators was also done here. Now that that is gone, I think we should do the next step. And at that point, I hope we can see a performance improvement over the non-pratt-parser version.

Note: port declarations can't have a documentation comment in the current v7 API, so they should be ignored. We'll want to do that later in the v8 branch where that field has been added.

cc @jiegillet I already had a go at it but was unsuccessful so far. Would you like to have a look at this?

jiegillet commented 4 months ago

With pleasure :)

jfmengels commented 4 months ago

Fixed in #219