jonschlinkert / parse-comments

Parse JavaScript code comments. Works with block and line comments, and should work with CSS, LESS, SASS, or any language with the same comment formats.
https://github.com/jonschlinkert
MIT License
67 stars 23 forks source link

Suggest to enable use other comment strings except `/*` #16

Closed lyingdragon closed 4 years ago

lyingdragon commented 4 years ago

Hello, this project is really helpful for me. I suppose that it could be better to support any custom comment strings instead of fixed string /* because parse-comments aims to support any languages, I believe.

I'm working on source code based API doc generation. My project uses an in-house language which uses (* for comment blocks. I forked this and modified to handle it. It worked for me, but the reason why I didn't do PR is I ignored an original option allowSingleStar.

I'd appreciate if you officially support it.

tunnckoCore commented 4 years ago

That's cool. But as I remember it is using javascript parser under the hood.

ref: https://github.com/jonschlinkert/extract-comments/blob/master/package.json#L28-L31

So it won't be that easy to support general langs. Your in house language probably is similar to JS and that's why it is working.

lyingdragon commented 4 years ago

Thanks for reply. I suppose I misunderstood the phrase "Javascript and any language that uses the same format." Now I know that it's a javascript parser and could be no plan for other format of languages. So I'll continue to use my local repo for my project. As you said, the in-house language's comment block is almost same to js only except the start/end string of comment. No much modification needed for it. Thanks! 👍

tunnckoCore commented 4 years ago

Yea, probably should be better to be removed from the description :)

As you said, the in-house language's comment block is almost same to js

I meant that esprima parser successfully parses your language (otherwise this package would throw? hm, interesting), so it's something similar to js. But anyway ;]

@jonschlinkert might be open for "general purpose"? He is god and obsessed with parsers! :laughing:

lyingdragon commented 4 years ago

It is really helpful even though it doesn't support all languages. Inspiring by it, I figured out a way how improve my complex API docs generation using multi-languages. Thanks, @tunnckoCore and @jonschlinkert, god of parsers :)

jonschlinkert commented 4 years ago

@lyingdragon sorry for the late reply! FWIW, I was planning on updating this library, and extract-comments to support other languages. I already started going down this path with strip-comments, and as @tunnckoCore I really enjoy parsing lol (I don't think I deserve that high of praise but I appreciate it!).

If there is anything I can do to help or provide guidance I would be happy to.

might be open for "general purpose"?

Yes, I would definitely be interested. I think this would ideally be accomplished with two different parsers and/or tokenizers: one for very quickly extracting comments (and creating code context, like line numbers, etc), and one for actually parsing the comment so it can be used with documentation libs. The first step for me would be to refactor extract-comments to do something like what I did in strip-comments (even if we don't use that code here, it would be a useful exercise to figure out the API). Next, we'd do the comment parsing here. I'm open to suggestions and/or PRs on any of it.