Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/exp/ast: move internal ast into the x/exp package #70

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ast/annotation.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ast

import (
"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

type Annotations ast.Annotations
Expand Down
2 changes: 1 addition & 1 deletion ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"time"

"github.com/cedar-policy/cedar-go/ast"
internalast "github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestASTByTable(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ast/node.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ast

import "github.com/cedar-policy/cedar-go/internal/ast"
import "github.com/cedar-policy/cedar-go/x/exp/ast"

// Node is a wrapper type for all the Cedar language operators. See the [Cedar operators documentation] for details.
//
Expand Down
2 changes: 1 addition & 1 deletion ast/operator.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ast

import (
"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

// ____ _
Expand Down
2 changes: 1 addition & 1 deletion ast/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ package ast
import (
"bytes"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/json"
"github.com/cedar-policy/cedar-go/internal/parser"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

type Policy ast.Policy
Expand Down
2 changes: 1 addition & 1 deletion ast/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"testing"

"github.com/cedar-policy/cedar-go/ast"
internalast "github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestPolicy_MarshalJSON(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ast/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"net/netip"
"time"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

// Boolean creates a value node containing a Boolean.
Expand Down
2 changes: 1 addition & 1 deletion ast/variable.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ast

import "github.com/cedar-policy/cedar-go/internal/ast"
import "github.com/cedar-policy/cedar-go/x/exp/ast"

func Principal() Node {
return wrapNode(ast.Principal())
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package eval
import (
"fmt"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

type BoolEvaler struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestCompile(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package eval
import (
"fmt"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/consts"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func toEval(n ast.IsNode) Evaler {
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestToEval(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/fold.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"slices"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

// foldPolicy takes in a given policy and attempts as much constant folding as possible.
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/fold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestFoldNode(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/partial.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"slices"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/mapset"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

const variableEntityType = "__cedar::variable"
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/partial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"testing"
"time"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestPartialScopeEval(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/json/json_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func (s *scopeJSON) FromNode(src ast.IsScopeNode) {
Expand Down
2 changes: 1 addition & 1 deletion internal/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"net/netip"
"testing"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestUnmarshalJSON(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/json/json_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"fmt"
"strings"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/consts"
"github.com/cedar-policy/cedar-go/internal/extensions"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

type isPrincipalResourceScopeNode interface {
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/cedar_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"fmt"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/consts"
"github.com/cedar-policy/cedar-go/internal/extensions"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func (p *Policy) MarshalCedar(buf *bytes.Buffer) {
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/cedar_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"testing"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/parser"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestParse(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/cedar_tokenize.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strings"
"unicode/utf8"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/rust"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

//go:generate moq -pkg parser -fmt goimports -out tokenize_mocks_test.go . reader
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/cedar_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"strconv"
"strings"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/consts"
"github.com/cedar-policy/cedar-go/internal/extensions"
"github.com/cedar-policy/cedar-go/internal/mapset"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func (p *PolicySlice) UnmarshalCedar(b []byte) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/cedar_unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"strings"
"testing"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/parser"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

var johnny = types.EntityUID{
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package parser
import (
"testing"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestScopeToNode(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package parser
import (
"bytes"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

type NodeTypeIf struct{ ast.NodeTypeIfThenElse }
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/policy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package parser

import "github.com/cedar-policy/cedar-go/internal/ast"
import "github.com/cedar-policy/cedar-go/x/exp/ast"

type PolicySlice []*Policy
type Policy ast.Policy
2 changes: 1 addition & 1 deletion policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"

"github.com/cedar-policy/cedar-go/ast"
internalast "github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/eval"
"github.com/cedar-policy/cedar-go/internal/json"
"github.com/cedar-policy/cedar-go/internal/parser"
"github.com/cedar-policy/cedar-go/types"
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
)

// A Policy is the parsed form of a single Cedar language policy statement.
Expand Down
2 changes: 1 addition & 1 deletion policy_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"fmt"

internalast "github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/parser"
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
)

// PolicyList represents a list of un-named Policy's. Cedar documents, unlike the PolicySet form, don't have a means of
Expand Down
2 changes: 1 addition & 1 deletion policy_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"maps"
"slices"

internalast "github.com/cedar-policy/cedar-go/internal/ast"
internaljson "github.com/cedar-policy/cedar-go/internal/json"
"github.com/cedar-policy/cedar-go/types"
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
)

type PolicyID = types.PolicyID
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/ast/ast_test.go → x/exp/ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

// These tests serve mostly as examples of how to translate from Cedar text into programmatic AST construction. They
Expand Down
21 changes: 21 additions & 0 deletions x/exp/ast/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
The AST package exposes the internal AST used within cedar-go. This AST is
subject to change. The AST is most useful for analyzing existing policies
created by the Cedar / JSON parser or created using the external AST. The
external AST is a type definition of the internal AST, so you can cast from the
external to internal types.

Example:

import (
"github.com/cedar-policy/cedar-go/ast"
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
)

func main() {
policy := ast.Permit()
internal := (*internalast.Policy)(policy)
_ = internal
}
*/
package ast
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion x/exp/batch/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"slices"

"github.com/cedar-policy/cedar-go"
"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/consts"
"github.com/cedar-policy/cedar-go/internal/eval"
"github.com/cedar-policy/cedar-go/internal/mapset"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

// Ignore returns a value that should be ignored during batch evaluation.
Expand Down
2 changes: 1 addition & 1 deletion x/exp/batch/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

"github.com/cedar-policy/cedar-go"
publicast "github.com/cedar-policy/cedar-go/ast"
"github.com/cedar-policy/cedar-go/internal/ast"
"github.com/cedar-policy/cedar-go/internal/mapset"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
"github.com/cedar-policy/cedar-go/x/exp/ast"
)

func TestBatch(t *testing.T) {
Expand Down