// Package parser implements utilities for parsing River configuration files.1package parser23import (4"github.com/grafana/agent/pkg/river/ast"5"github.com/grafana/agent/pkg/river/token"6)78// ParseFile parses an entire River configuration file. The data parameter9// should hold the file contents to parse, while the filename parameter is used10// for reporting errors.11//12// If an error was encountered during parsing, the returned AST will be nil and13// err will be an diag.Diagnostics all the errors encountered during parsing.14func ParseFile(filename string, data []byte) (*ast.File, error) {15p := newParser(filename, data)1617f := p.ParseFile()18if len(p.diags) > 0 {19return nil, p.diags20}21return f, nil22}2324// ParseExpression parses a single River expression from expr.25//26// If an error was encountered during parsing, the returned expression will be27// nil and err will be an ErrorList with all the errors encountered during28// parsing.29func ParseExpression(expr string) (ast.Expr, error) {30p := newParser("", []byte(expr))3132e := p.ParseExpression()3334// If the current token is not a TERMINATOR then the parsing did not complete35// in full and there are still parts of the string left unparsed.36p.expect(token.TERMINATOR)3738if len(p.diags) > 0 {39return nil, p.diags40}41return e, nil42}434445