Skip to content

Commit 9d338bc

Browse files
authored
Merge pull request #70 from strongdm/move-ast-to-exp
x/exp/ast: move internal ast into the x/exp package
2 parents ccfb96b + a73ca75 commit 9d338bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+54
-33
lines changed

ast/annotation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package ast
22

33
import (
4-
"github.com/cedar-policy/cedar-go/internal/ast"
54
"github.com/cedar-policy/cedar-go/types"
5+
"github.com/cedar-policy/cedar-go/x/exp/ast"
66
)
77

88
type Annotations ast.Annotations

ast/ast_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"time"
77

88
"github.com/cedar-policy/cedar-go/ast"
9-
internalast "github.com/cedar-policy/cedar-go/internal/ast"
109
"github.com/cedar-policy/cedar-go/internal/testutil"
1110
"github.com/cedar-policy/cedar-go/types"
11+
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
1212
)
1313

1414
func TestASTByTable(t *testing.T) {

ast/node.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ast
22

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

55
// Node is a wrapper type for all the Cedar language operators. See the [Cedar operators documentation] for details.
66
//

ast/operator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package ast
22

33
import (
4-
"github.com/cedar-policy/cedar-go/internal/ast"
54
"github.com/cedar-policy/cedar-go/types"
5+
"github.com/cedar-policy/cedar-go/x/exp/ast"
66
)
77

88
// ____ _

ast/policy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ package ast
99
import (
1010
"bytes"
1111

12-
"github.com/cedar-policy/cedar-go/internal/ast"
1312
"github.com/cedar-policy/cedar-go/internal/json"
1413
"github.com/cedar-policy/cedar-go/internal/parser"
14+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1515
)
1616

1717
type Policy ast.Policy

ast/policy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"testing"
55

66
"github.com/cedar-policy/cedar-go/ast"
7-
internalast "github.com/cedar-policy/cedar-go/internal/ast"
87
"github.com/cedar-policy/cedar-go/internal/testutil"
98
"github.com/cedar-policy/cedar-go/types"
9+
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
1010
)
1111

1212
func TestPolicy_MarshalJSON(t *testing.T) {

ast/value.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"net/netip"
55
"time"
66

7-
"github.com/cedar-policy/cedar-go/internal/ast"
87
"github.com/cedar-policy/cedar-go/types"
8+
"github.com/cedar-policy/cedar-go/x/exp/ast"
99
)
1010

1111
// Boolean creates a value node containing a Boolean.

ast/variable.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ast
22

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

55
func Principal() Node {
66
return wrapNode(ast.Principal())

internal/eval/compile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package eval
33
import (
44
"fmt"
55

6-
"github.com/cedar-policy/cedar-go/internal/ast"
76
"github.com/cedar-policy/cedar-go/types"
7+
"github.com/cedar-policy/cedar-go/x/exp/ast"
88
)
99

1010
type BoolEvaler struct {

internal/eval/compile_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/cedar-policy/cedar-go/internal/ast"
87
"github.com/cedar-policy/cedar-go/internal/testutil"
98
"github.com/cedar-policy/cedar-go/types"
9+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1010
)
1111

1212
func TestCompile(t *testing.T) {

internal/eval/convert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package eval
33
import (
44
"fmt"
55

6-
"github.com/cedar-policy/cedar-go/internal/ast"
76
"github.com/cedar-policy/cedar-go/internal/consts"
87
"github.com/cedar-policy/cedar-go/types"
8+
"github.com/cedar-policy/cedar-go/x/exp/ast"
99
)
1010

1111
func toEval(n ast.IsNode) Evaler {

internal/eval/convert_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/cedar-policy/cedar-go/internal/ast"
98
"github.com/cedar-policy/cedar-go/internal/testutil"
109
"github.com/cedar-policy/cedar-go/types"
10+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1111
)
1212

1313
func TestToEval(t *testing.T) {

internal/eval/fold.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"slices"
66

7-
"github.com/cedar-policy/cedar-go/internal/ast"
87
"github.com/cedar-policy/cedar-go/types"
8+
"github.com/cedar-policy/cedar-go/x/exp/ast"
99
)
1010

1111
// foldPolicy takes in a given policy and attempts as much constant folding as possible.

internal/eval/fold_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/cedar-policy/cedar-go/internal/ast"
98
"github.com/cedar-policy/cedar-go/internal/testutil"
109
"github.com/cedar-policy/cedar-go/types"
10+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1111
)
1212

1313
func TestFoldNode(t *testing.T) {

internal/eval/partial.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"fmt"
66
"slices"
77

8-
"github.com/cedar-policy/cedar-go/internal/ast"
98
"github.com/cedar-policy/cedar-go/internal/mapset"
109
"github.com/cedar-policy/cedar-go/types"
10+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1111
)
1212

1313
const variableEntityType = "__cedar::variable"

internal/eval/partial_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/cedar-policy/cedar-go/internal/ast"
1110
"github.com/cedar-policy/cedar-go/internal/testutil"
1211
"github.com/cedar-policy/cedar-go/types"
12+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1313
)
1414

1515
func TestPartialScopeEval(t *testing.T) {

internal/json/json_marshal.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"encoding/json"
55
"fmt"
66

7-
"github.com/cedar-policy/cedar-go/internal/ast"
87
"github.com/cedar-policy/cedar-go/types"
8+
"github.com/cedar-policy/cedar-go/x/exp/ast"
99
)
1010

1111
func (s *scopeJSON) FromNode(src ast.IsScopeNode) {

internal/json/json_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"net/netip"
66
"testing"
77

8-
"github.com/cedar-policy/cedar-go/internal/ast"
98
"github.com/cedar-policy/cedar-go/internal/testutil"
109
"github.com/cedar-policy/cedar-go/types"
10+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1111
)
1212

1313
func TestUnmarshalJSON(t *testing.T) {

internal/json/json_unmarshal.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"fmt"
77
"strings"
88

9-
"github.com/cedar-policy/cedar-go/internal/ast"
109
"github.com/cedar-policy/cedar-go/internal/consts"
1110
"github.com/cedar-policy/cedar-go/internal/extensions"
1211
"github.com/cedar-policy/cedar-go/types"
12+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1313
)
1414

1515
type isPrincipalResourceScopeNode interface {

internal/parser/cedar_marshal.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"bytes"
55
"fmt"
66

7-
"github.com/cedar-policy/cedar-go/internal/ast"
87
"github.com/cedar-policy/cedar-go/internal/consts"
98
"github.com/cedar-policy/cedar-go/internal/extensions"
9+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1010
)
1111

1212
func (p *Policy) MarshalCedar(buf *bytes.Buffer) {

internal/parser/cedar_parse_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"bytes"
55
"testing"
66

7-
"github.com/cedar-policy/cedar-go/internal/ast"
87
"github.com/cedar-policy/cedar-go/internal/parser"
98
"github.com/cedar-policy/cedar-go/internal/testutil"
9+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1010
)
1111

1212
func TestParse(t *testing.T) {

internal/parser/cedar_tokenize.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"strings"
1010
"unicode/utf8"
1111

12-
"github.com/cedar-policy/cedar-go/internal/ast"
1312
"github.com/cedar-policy/cedar-go/internal/rust"
13+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1414
)
1515

1616
//go:generate moq -pkg parser -fmt goimports -out tokenize_mocks_test.go . reader

internal/parser/cedar_unmarshal.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"strconv"
66
"strings"
77

8-
"github.com/cedar-policy/cedar-go/internal/ast"
98
"github.com/cedar-policy/cedar-go/internal/consts"
109
"github.com/cedar-policy/cedar-go/internal/extensions"
1110
"github.com/cedar-policy/cedar-go/internal/mapset"
1211
"github.com/cedar-policy/cedar-go/types"
12+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1313
)
1414

1515
func (p *PolicySlice) UnmarshalCedar(b []byte) error {

internal/parser/cedar_unmarshal_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"strings"
66
"testing"
77

8-
"github.com/cedar-policy/cedar-go/internal/ast"
98
"github.com/cedar-policy/cedar-go/internal/parser"
109
"github.com/cedar-policy/cedar-go/internal/testutil"
1110
"github.com/cedar-policy/cedar-go/types"
11+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1212
)
1313

1414
var johnny = types.EntityUID{

internal/parser/internal_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package parser
33
import (
44
"testing"
55

6-
"github.com/cedar-policy/cedar-go/internal/ast"
76
"github.com/cedar-policy/cedar-go/internal/testutil"
7+
"github.com/cedar-policy/cedar-go/x/exp/ast"
88
)
99

1010
func TestScopeToNode(t *testing.T) {

internal/parser/node.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package parser
33
import (
44
"bytes"
55

6-
"github.com/cedar-policy/cedar-go/internal/ast"
6+
"github.com/cedar-policy/cedar-go/x/exp/ast"
77
)
88

99
type NodeTypeIf struct{ ast.NodeTypeIfThenElse }

internal/parser/policy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package parser
22

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

55
type PolicySlice []*Policy
66
type Policy ast.Policy

policy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"bytes"
55

66
"github.com/cedar-policy/cedar-go/ast"
7-
internalast "github.com/cedar-policy/cedar-go/internal/ast"
87
"github.com/cedar-policy/cedar-go/internal/eval"
98
"github.com/cedar-policy/cedar-go/internal/json"
109
"github.com/cedar-policy/cedar-go/internal/parser"
1110
"github.com/cedar-policy/cedar-go/types"
11+
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
1212
)
1313

1414
// A Policy is the parsed form of a single Cedar language policy statement.

policy_list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"bytes"
55
"fmt"
66

7-
internalast "github.com/cedar-policy/cedar-go/internal/ast"
87
"github.com/cedar-policy/cedar-go/internal/parser"
8+
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
99
)
1010

1111
// PolicyList represents a list of un-named Policy's. Cedar documents, unlike the PolicySet form, don't have a means of

policy_set.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"maps"
99
"slices"
1010

11-
internalast "github.com/cedar-policy/cedar-go/internal/ast"
1211
internaljson "github.com/cedar-policy/cedar-go/internal/json"
1312
"github.com/cedar-policy/cedar-go/types"
13+
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
1414
)
1515

1616
type PolicyID = types.PolicyID
File renamed without changes.

internal/ast/ast_test.go x/exp/ast/ast_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/cedar-policy/cedar-go/internal/ast"
98
"github.com/cedar-policy/cedar-go/internal/testutil"
109
"github.com/cedar-policy/cedar-go/types"
10+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1111
)
1212

1313
// These tests serve mostly as examples of how to translate from Cedar text into programmatic AST construction. They

x/exp/ast/doc.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
The AST package exposes the internal AST used within cedar-go. This AST is
3+
subject to change. The AST is most useful for analyzing existing policies
4+
created by the Cedar / JSON parser or created using the external AST. The
5+
external AST is a type definition of the internal AST, so you can cast from the
6+
external to internal types.
7+
8+
Example:
9+
10+
import (
11+
"github.com/cedar-policy/cedar-go/ast"
12+
internalast "github.com/cedar-policy/cedar-go/x/exp/ast"
13+
)
14+
15+
func main() {
16+
policy := ast.Permit()
17+
internal := (*internalast.Policy)(policy)
18+
_ = internal
19+
}
20+
*/
21+
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.

x/exp/batch/batch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
"slices"
1515

1616
"github.com/cedar-policy/cedar-go"
17-
"github.com/cedar-policy/cedar-go/internal/ast"
1817
"github.com/cedar-policy/cedar-go/internal/consts"
1918
"github.com/cedar-policy/cedar-go/internal/eval"
2019
"github.com/cedar-policy/cedar-go/internal/mapset"
2120
"github.com/cedar-policy/cedar-go/types"
21+
"github.com/cedar-policy/cedar-go/x/exp/ast"
2222
)
2323

2424
// Ignore returns a value that should be ignored during batch evaluation.

x/exp/batch/batch_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99

1010
"github.com/cedar-policy/cedar-go"
1111
publicast "github.com/cedar-policy/cedar-go/ast"
12-
"github.com/cedar-policy/cedar-go/internal/ast"
1312
"github.com/cedar-policy/cedar-go/internal/mapset"
1413
"github.com/cedar-policy/cedar-go/internal/testutil"
1514
"github.com/cedar-policy/cedar-go/types"
15+
"github.com/cedar-policy/cedar-go/x/exp/ast"
1616
)
1717

1818
func TestBatch(t *testing.T) {

0 commit comments

Comments
 (0)