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

https://github.com/mdm-code/scanner

Custom Go text token scanner implementation.
https://github.com/mdm-code/scanner

go golang scan scanner token tokenizer

Last synced: 5 months ago
JSON representation

Custom Go text token scanner implementation.

Awesome Lists containing this project

README

          



logo

Custom Go text token scanner implementation




Build status


Code coverage


MIT license


Go report card


Go package docs


Package `scanner` is a custom text scanner implementation. It has the same
idiomatic Go scanner programming interface, and it lets the client to freely
navigate the buffer. The scanner is also capable of peeking ahead of the
cursor. Read runes are rendered as tokens with additional information on their
position in the buffer. Consult the [package documentation](https://pkg.go.dev/github.com/mdm-code/scanner) or see
[Usage](#usage) to see how to use it.

## Installation

Use the following command to add the package to an existing project.

```sh
go get github.com/mdm-code/scanner
```

## Usage

Here is a snippet showing the basic usage of the scanner to read text as a stream
of tokens using the public API of the `scanner` package.

```go
package main

import (
"bufio"
"fmt"
"log"
"os"

"github.com/mdm-code/scanner"
)

func main() {
r := bufio.NewReader(os.Stdin)
s, err := scanner.New(r)
if err != nil {
log.Fatalln(err)
}
var ts []scanner.Token
for s.Scan() {
t := s.Token()
ts = append(ts, t)
}
fmt.Println(ts)
}
```

## Development

Consult [Makefile](Makefile) to see how to format, examine code with `go vet`,
run unit test, run code linter with `golint` in order to get test coverage and
check if the package builds all right.

Remember to install `golint` before you try to run tests and test the build:

```sh
go install golang.org/x/lint/golint@latest
```

## License

Copyright (c) 2023 Michał Adamczyk.

This project is licensed under the [MIT license](https://opensource.org/licenses/MIT).
See [LICENSE](LICENSE) for more details.