mirror of
https://github.com/google/go-jsonnet.git
synced 2025-08-08 15:27:13 +02:00
There is no reason for external users to directly depend on parser. It had a few random things exported as well, namely errors and "children" functions (helpers for AST traversal). It was easy to extract the errors package, but I needed to leave children in parser for now. The errors package was also made internal, but it's a candidate for making it public again potentially (if someone wants to display error messages just like us). For now it's probably too incomplete anyway. This change has a potential of breaking the existing users since we technically remove public APIs. These were not needed or even helpful for actually running Jsonnet code, but perhaps someone used them anyway.
24 lines
501 B
Go
24 lines
501 B
Go
package program
|
|
|
|
import (
|
|
"github.com/google/go-jsonnet/ast"
|
|
"github.com/google/go-jsonnet/internal/parser"
|
|
)
|
|
|
|
// SnippetToAST converts a Jsonnet code snippet to a desugared and analyzed AST.
|
|
func SnippetToAST(filename string, snippet string) (ast.Node, error) {
|
|
node, err := parser.SnippetToRawAST(filename, snippet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = desugarAST(&node)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = analyze(node)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return node, nil
|
|
}
|