An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Compars [![release](https://img.shields.io/github/v/tag/mishamyrt/compars?sort=semver)](https://github.com/mishamyrt/compars/tags)[![Quality assurance](https://github.com/mishamyrt/compars/actions/workflows/qa.yaml/badge.svg)](https://github.com/mishamyrt/compars/actions/workflows/qa.yaml)[![Maintainability](https://api.codeclimate.com/v1/badges/96ab89e362487fda5926/maintainability)](https://codeclimate.com/github/mishamyrt/compars/maintainability)

Logo

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).