https://github.com/durudex/go-polylang
Implementation of the Polylang language in Go.
https://github.com/durudex/go-polylang
go parser polylang
Last synced: 5 months ago
JSON representation
Implementation of the Polylang language in Go.
- Host: GitHub
- URL: https://github.com/durudex/go-polylang
- Owner: durudex
- License: mit
- Created: 2023-01-03T14:21:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-31T20:59:17.000Z (about 3 years ago)
- Last Synced: 2025-11-22T18:15:54.635Z (7 months ago)
- Topics: go, parser, polylang
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# `go-polylang`
Implementation of the [Polylang](https://github.com/polybase/polylang) in Go programming language.
## Setup
To get the [`go-polylang`](https://github.com/durudex/go-polylang) module, you need to have or install [Go version >= 1.19](https://go.dev/dl/). To check your current version of Go, use the `go version` command.
**The command to get the module:**
```bash
go get github.com/durudex/go-polylang@latest
```
## Parser
You can use the [`parser`](https://pkg.go.dev/github.com/durudex/go-polylang/parser) package to parse your code. It can be used follow:
### Parsing files
To parse a file or directory of files, you can use the [`parser.Parse()`](https://pkg.go.dev/github.com/durudex/go-polylang/parser#Parse) function by passing the required file or directory path to its arguments.
```go
import "github.com/durudex/go-polylang/parser"
func main() {
ast, err := parser.Parse("filename.polylang")
if err != nil { /* ... */ }
}
```
### Custom parser
Currently, we are using the [`participle`](github.com/alecthomas/participle) library for code parsing. However, you can create your own parser by configuring it to meet your specific needs.
```go
import (
"github.com/durudex/go-polylang"
"github.com/durudex/go-polylang/ast"
"github.com/alecthomas/participle/v2"
)
func main() {
parser := participle.MustBuild[ast.Program](
participle.Lexer(polylang.Lexer),
)
// ...
}
```
> **Note:**
> If you want to use all the features of the library, you can use our ready-made variable [`Must`](https://pkg.go.dev/github.com/durudex/go-polylang/parser#Must), which contains all of the necessary settings for using the library.
## Metadata
To starting using [metadata](https://pkg.go.dev/github.com/durudex/go-polylang/metadata), you need to install the module.
> **Note:**
> The data of the metadata that you want to parse must be JSON.
**The command to get the module:**
```
go get github.com/durudex/go-polylang/metadata@latest
```
### Parsing Metadata
```go
import "github.com/durudex/go-polylang/metadata"
func main() {
rawJsonData := []byte("...")
root, err := metadata.Parse(rawJsonData)
if err != nil { /* ... */ }
// ...
}
```
### Parsing Metadata File
```go
import "github.com/durudex/go-polylang/metadata"
func main() {
root, err := metadata.ParseFile("path/to/file.json")
if err != nil { /* ... */ }
// ...
}
```
## License
Copyright © 2022-2023 [Durudex](https://github.com/durudex). Released under the MIT license.