Skip to content

durudex/go-polylang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-polylang

Implementation of the Polylang in Go programming language.

Setup

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

Parser

You can use the 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() 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 { /* ... */ }
}

Custom parser

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.

Metadata

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

Parsing Metadata

import "github.com/durudex/go-polylang/metadata"

func main() {
    rawJsonData := []byte("...")

    root, err := metadata.Parse(rawJsonData)
    if err != nil { /* ... */ }

    // ...
}

Parsing Metadata File

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. Released under the MIT license.