https://github.com/hua1995116/common-comment-parser
A universal comment parser (supports more than 30 languages)
https://github.com/hua1995116/common-comment-parser
comment-parser parser
Last synced: 4 months ago
JSON representation
A universal comment parser (supports more than 30 languages)
- Host: GitHub
- URL: https://github.com/hua1995116/common-comment-parser
- Owner: hua1995116
- License: mit
- Created: 2020-05-03T15:09:11.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-10T15:07:26.000Z (about 5 years ago)
- Last Synced: 2025-02-03T20:50:20.609Z (5 months ago)
- Topics: comment-parser, parser
- Language: TypeScript
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# common-comment-parser
A universal comment parser (supports more than 30 languages)
# Usage
```bash
npm install common-comment-parser
``````javascript
import parser from 'common-comment-parser';const context = `// line1
const cc = 111;
/*
block1
*/
console.log(222);console.log(11); /* block2 */ const c = 111; /* block3 */ console.log(111); // line2
const aaa = 111; // line3
const ddd = `//ddd//ddd//dddd`;
const eee = '//eee//eee//eee';
const fff = "//ddd//ddd//dddd";const dd = `\`ddddd//dddd`;
const ee = '\'ddddd//dddd';
const ff = "\"ddddd//dddd";
`const ext = 'js';
console.log(parser(context, ext));
// [
{
"type": "CommentLine",
"value": " line1",
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 9
}
}
},
{
"type": "CommentBlock",
"value": "\nblock1\n",
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 6,
"column": 1
}
}
},
{
"type": "CommentBlock",
"value": " block2 ",
"loc": {
"start": {
"line": 9,
"column": 19
},
"end": {
"line": 9,
"column": 27
}
}
},
{
"type": "CommentBlock",
"value": " block3 ",
"loc": {
"start": {
"line": 9,
"column": 47
},
"end": {
"line": 9,
"column": 55
}
}
},
{
"type": "CommentLine",
"value": " line2",
"loc": {
"start": {
"line": 9,
"column": 78
},
"end": {
"line": 9,
"column": 84
}
}
},
{
"type": "CommentLine",
"value": " line3",
"loc": {
"start": {
"line": 12,
"column": 19
},
"end": {
"line": 12,
"column": 25
}
}
}
]
```**parser(context, ext)**
- context: What needs to be parsed
- ext: File extension
# AST
```javascript
commentsAST {
type: string;
value: string;
loc: {
start: {
line: number,
column: number
},
end: {
line: number,
column: number
}
}
}
```# License
MIT
Copyright (c) 2019 蓝色的秋风