🚀
易于使用
简单的 API 用于将 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))
}
go get github.com/scagogogo/erlang-rebar-config-parser
Erlang 类型 | 示例 | Go 表示 |
---|---|---|
原子 | atom_name , 'quoted-atom' | Atom{Value: "atom_name", IsQuoted: false} |
字符串 | "hello world" | String{Value: "hello world"} |
整数 | 123 , -42 | Integer{Value: 123} |
浮点数 | 3.14 , -1.5e-3 | Float{Value: 3.14} |
元组 | {key, value} | Tuple{Elements: []Term{...}} |
列表 | [1, 2, 3] | List{Elements: []Term{...}} |