Skip to content

Erlang Rebar 配置解析器用于解析 Erlang rebar 配置文件的 Go 库

轻松解析、访问和格式化 Erlang rebar.config 文件

快速示例

go
package main

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

func main() {
    // 解析 rebar.config 文件
    config, err := parser.ParseFile("path/to/rebar.config")
    if err != nil {
        log.Fatalf("解析配置失败: %v", err)
    }
    
    // 获取并打印依赖项
    deps, ok := config.GetDeps()
    if ok && len(deps) > 0 {
        if depsList, ok := deps[0].(parser.List); ok {
            fmt.Printf("找到 %d 个依赖项\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("- 依赖项: %s\n", atom.Value)
                    }
                }
            }
        }
    }
    
    // 格式化并打印配置,使用美观的缩进
    fmt.Println("\n格式化的配置:")
    fmt.Println(config.Format(2))
}

安装

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

特性

  • 解析 rebar.config 文件为结构化的 Go 对象
  • 支持所有常见的 Erlang 术语类型(元组、列表、原子、字符串、数字)
  • 辅助方法轻松访问常见配置元素
  • 完全支持嵌套数据结构
  • 正确处理注释和空白字符
  • 美化输出支持可配置缩进
  • 比较功能检查术语相等性
  • 持续集成通过 GitHub Actions
  • 全面的文档提供中英文示例
  • 98% 测试覆盖率包含全面的边缘情况测试

支持的 Erlang 术语类型

Erlang 类型示例Go 表示
原子atom_name, 'quoted-atom'Atom{Value: "atom_name", IsQuoted: false}
字符串"hello world"String{Value: "hello world"}
整数123, -42Integer{Value: 123}
浮点数3.14, -1.5e-3Float{Value: 3.14}
元组{key, value}Tuple{Elements: []Term{...}}
列表[1, 2, 3]List{Elements: []Term{...}}

Released under the MIT License.