Files
QSfera/vendor/github.com/open-policy-agent/opa/internal/future/parser_opts.go
T
dependabot[bot]andGitHub 871fdd15d7 build(deps): bump github.com/open-policy-agent/opa from 1.1.0 to 1.2.0
Bumps [github.com/open-policy-agent/opa](https://github.com/open-policy-agent/opa) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/open-policy-agent/opa/releases)
- [Changelog](https://github.com/open-policy-agent/opa/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-policy-agent/opa/compare/v1.1.0...v1.2.0)

---
updated-dependencies:
- dependency-name: github.com/open-policy-agent/opa
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-17 17:29:55 +00:00

44 lines
1.3 KiB
Go

// Copyright 2021 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package future
import (
"errors"
"fmt"
"github.com/open-policy-agent/opa/v1/ast"
)
// ParserOptionsFromFutureImports transforms a slice of `ast.Import`s into the
// `ast.ParserOptions` that can be used to parse a statement according to the
// included "future.keywords" and "future.keywords.xyz" imports.
func ParserOptionsFromFutureImports(imports []*ast.Import) (ast.ParserOptions, error) {
popts := ast.ParserOptions{
FutureKeywords: []string{},
}
for _, imp := range imports {
path := imp.Path.Value.(ast.Ref)
if !ast.FutureRootDocument.Equal(path[0]) {
continue
}
if len(path) >= 2 {
if string(path[1].Value.(ast.String)) != "keywords" {
return popts, fmt.Errorf("unknown future import: %v", imp)
}
if len(path) == 2 {
// retun, one "future.keywords" import means we can disregard any others
return ast.ParserOptions{AllFutureKeywords: true}, nil
}
}
if len(path) == 3 {
if imp.Alias != "" {
return popts, errors.New("alias not supported")
}
popts.FutureKeywords = append(popts.FutureKeywords, string(path[2].Value.(ast.String)))
}
}
return popts, nil
}