Implementation of the Polylang in Go programming language.
To get the go-polylang
module, you need to have or install Go version >= 1.19. To check your current version of Go, use the go version
command.
The command to get the module:
go get github.com/durudex/go-polylang@latest
You can use the parser
package to parse your code. It can be used follow:
To parse a file or directory of files, you can use the parser.Parse()
function by passing the required file or directory path to its arguments.
import "github.com/durudex/go-polylang/parser"
func main() {
ast, err := parser.Parse("filename.polylang")
if err != nil { /* ... */ }
}
Currently, we are using the participle
library for code parsing. However, you can create your own parser by configuring it to meet your specific needs.
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
, which contains all of the necessary settings for using the library.
To starting using 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
import "github.com/durudex/go-polylang/metadata"
func main() {
rawJsonData := []byte("...")
root, err := metadata.Parse(rawJsonData)
if err != nil { /* ... */ }
// ...
}
import "github.com/durudex/go-polylang/metadata"
func main() {
root, err := metadata.ParseFile("path/to/file.json")
if err != nil { /* ... */ }
// ...
}
Copyright © 2022-2023 Durudex. Released under the MIT license.