Skip to content

Erlang Rebar Config ParserA Go library for parsing Erlang rebar configuration files

Parse, access, and format Erlang rebar.config files with ease

Quick Example

go
package main

import (
    "fmt"
    "log"
    
    "github.com/scagogogo/erlang-rebar-config-parser/pkg/parser"
)

func main() {
    // Parse a rebar.config file
    config, err := parser.ParseFile("path/to/rebar.config")
    if err != nil {
        log.Fatalf("Failed to parse config: %v", err)
    }
    
    // Get and print dependencies
    deps, ok := config.GetDeps()
    if ok && len(deps) > 0 {
        if depsList, ok := deps[0].(parser.List); ok {
            fmt.Printf("Found %d dependencies\n", len(depsList.Elements))
            
            for _, dep := range depsList.Elements {
                if tuple, ok := dep.(parser.Tuple); ok && len(tuple.Elements) >= 2 {
                    if atom, ok := tuple.Elements[0].(parser.Atom); ok {
                        fmt.Printf("- Dependency: %s\n", atom.Value)
                    }
                }
            }
        }
    }
    
    // Format and print the config with nice indentation
    fmt.Println("\nFormatted config:")
    fmt.Println(config.Format(2))
}

Installation

bash
go get github.com/scagogogo/erlang-rebar-config-parser

Features

  • Parse rebar.config files into structured Go objects
  • Support for all common Erlang term types (tuples, lists, atoms, strings, numbers)
  • Helper methods to easily access common configuration elements
  • Full support for nested data structures
  • Handle comments and whitespace correctly
  • Pretty-printing with configurable indentation
  • Compare functionality to check term equality
  • Continuous Integration via GitHub Actions
  • Comprehensive documentation with examples in English and Chinese
  • 98% test coverage with comprehensive edge case testing

Supported Erlang Term Types

Erlang TypeExampleGo Representation
Atomsatom_name, 'quoted-atom'Atom{Value: "atom_name", IsQuoted: false}
Strings"hello world"String{Value: "hello world"}
Integers123, -42Integer{Value: 123}
Floats3.14, -1.5e-3Float{Value: 3.14}
Tuples{key, value}Tuple{Elements: []Term{...}}
Lists[1, 2, 3]List{Elements: []Term{...}}

Released under the MIT License.