https://github.com/mishamyrt/compars
📄 Fast comment parser
https://github.com/mishamyrt/compars
comments golang parser pure-function
Last synced: 4 months ago
JSON representation
📄 Fast comment parser
- Host: GitHub
- URL: https://github.com/mishamyrt/compars
- Owner: mishamyrt
- License: mit
- Created: 2021-03-08T21:51:01.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-18T13:48:43.000Z (about 4 years ago)
- Last Synced: 2025-07-17T05:37:24.957Z (5 months ago)
- Topics: comments, golang, parser, pure-function
- Language: Go
- Homepage:
- Size: 65.4 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Compars [](https://github.com/mishamyrt/compars/tags)[](https://github.com/mishamyrt/compars/actions/workflows/qa.yaml)[](https://codeclimate.com/github/mishamyrt/compars/maintainability)

Parser of comments in source code. Supports multiple languages through dictionaries. The library contains a pure `Parse` function that returns found comments and their positions
## Features
* Mutli–language
* Pure functions
* Memory–frendly
## Usage
The function needs to pass a `*bufio.Scanner` and a structure of `CommentSymbolSet`. The set can be obtained from the `GetSetByExtension` function, which takes a file extension. The available extensions may be found in the [extensions.go](./pkg/symbols/extensions.go) file.
```go
package main
import (
"github.com/mishamyrt/compars/v1"
"github.com/mishamyrt/compars/v1/pkg/symbols"
)
func main() {
file, _ := os.Open(path)
set, _ := symbols.GetSetByExtension(".go")
comments := compars.Parse(file, set)
fmt.Printf("%d comments are found", len(comments))
}
```
The result is represented by an array of comment structures.
```go
// CommentSymbolSet is language-specific symbol set
type CommentSymbolSet struct {
Inline string
MultilineStart string
MultilineEnd string
}
```
## Documentation
Documentation about Compars commands and libraries can be found at usual [godoc.org](https://godoc.org/github.com/mishamyrt/compars).
## License
[MIT](./LICENSE).