diff --git a/ast/annotation.go b/ast/annotation.go index eaa6713..218d2d3 100644 --- a/ast/annotation.go +++ b/ast/annotation.go @@ -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 diff --git a/ast/ast_test.go b/ast/ast_test.go index 53a0379..6398dd9 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -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) { diff --git a/ast/node.go b/ast/node.go index 8a9e804..6ffb9a4 100644 --- a/ast/node.go +++ b/ast/node.go @@ -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. // diff --git a/ast/operator.go b/ast/operator.go index 833f92a..5c80745 100644 --- a/ast/operator.go +++ b/ast/operator.go @@ -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" ) // ____ _ diff --git a/ast/policy.go b/ast/policy.go index be2ddc9..5ae8154 100644 --- a/ast/policy.go +++ b/ast/policy.go @@ -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 diff --git a/ast/policy_test.go b/ast/policy_test.go index 7e817ec..fbdc0ff 100644 --- a/ast/policy_test.go +++ b/ast/policy_test.go @@ -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) { diff --git a/ast/value.go b/ast/value.go index 3be1731..b2fbf05 100644 --- a/ast/value.go +++ b/ast/value.go @@ -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. diff --git a/ast/variable.go b/ast/variable.go index f12ce38..a378875 100644 --- a/ast/variable.go +++ b/ast/variable.go @@ -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()) diff --git a/internal/eval/compile.go b/internal/eval/compile.go index 74d403f..599c349 100644 --- a/internal/eval/compile.go +++ b/internal/eval/compile.go @@ -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 { diff --git a/internal/eval/compile_test.go b/internal/eval/compile_test.go index c73e8c2..6ebb89f 100644 --- a/internal/eval/compile_test.go +++ b/internal/eval/compile_test.go @@ -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) { diff --git a/internal/eval/convert.go b/internal/eval/convert.go index 7472c89..44f5bb1 100644 --- a/internal/eval/convert.go +++ b/internal/eval/convert.go @@ -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 { diff --git a/internal/eval/convert_test.go b/internal/eval/convert_test.go index 1868107..e73dd21 100644 --- a/internal/eval/convert_test.go +++ b/internal/eval/convert_test.go @@ -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) { diff --git a/internal/eval/fold.go b/internal/eval/fold.go index 9dc1d36..880834b 100644 --- a/internal/eval/fold.go +++ b/internal/eval/fold.go @@ -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. diff --git a/internal/eval/fold_test.go b/internal/eval/fold_test.go index 9230dab..0966717 100644 --- a/internal/eval/fold_test.go +++ b/internal/eval/fold_test.go @@ -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) { diff --git a/internal/eval/partial.go b/internal/eval/partial.go index 922eb1e..07106cd 100644 --- a/internal/eval/partial.go +++ b/internal/eval/partial.go @@ -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" diff --git a/internal/eval/partial_test.go b/internal/eval/partial_test.go index b2ab92c..0509c41 100644 --- a/internal/eval/partial_test.go +++ b/internal/eval/partial_test.go @@ -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) { diff --git a/internal/json/json_marshal.go b/internal/json/json_marshal.go index d8bc923..a4cf99d 100644 --- a/internal/json/json_marshal.go +++ b/internal/json/json_marshal.go @@ -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) { diff --git a/internal/json/json_test.go b/internal/json/json_test.go index 64c714e..ed1f12e 100644 --- a/internal/json/json_test.go +++ b/internal/json/json_test.go @@ -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) { diff --git a/internal/json/json_unmarshal.go b/internal/json/json_unmarshal.go index a5299a6..3f2cba8 100644 --- a/internal/json/json_unmarshal.go +++ b/internal/json/json_unmarshal.go @@ -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 { diff --git a/internal/parser/cedar_marshal.go b/internal/parser/cedar_marshal.go index cf39f7e..0957d53 100644 --- a/internal/parser/cedar_marshal.go +++ b/internal/parser/cedar_marshal.go @@ -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) { diff --git a/internal/parser/cedar_parse_test.go b/internal/parser/cedar_parse_test.go index 2859396..4b77c24 100644 --- a/internal/parser/cedar_parse_test.go +++ b/internal/parser/cedar_parse_test.go @@ -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) { diff --git a/internal/parser/cedar_tokenize.go b/internal/parser/cedar_tokenize.go index 1c634da..11bca61 100644 --- a/internal/parser/cedar_tokenize.go +++ b/internal/parser/cedar_tokenize.go @@ -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 diff --git a/internal/parser/cedar_unmarshal.go b/internal/parser/cedar_unmarshal.go index 1971b40..c255c37 100644 --- a/internal/parser/cedar_unmarshal.go +++ b/internal/parser/cedar_unmarshal.go @@ -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 { diff --git a/internal/parser/cedar_unmarshal_test.go b/internal/parser/cedar_unmarshal_test.go index a654638..5f349ac 100644 --- a/internal/parser/cedar_unmarshal_test.go +++ b/internal/parser/cedar_unmarshal_test.go @@ -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{ diff --git a/internal/parser/internal_test.go b/internal/parser/internal_test.go index 1079d1a..c4e3c84 100644 --- a/internal/parser/internal_test.go +++ b/internal/parser/internal_test.go @@ -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) { diff --git a/internal/parser/node.go b/internal/parser/node.go index 0e8dada..36e55b0 100644 --- a/internal/parser/node.go +++ b/internal/parser/node.go @@ -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 } diff --git a/internal/parser/policy.go b/internal/parser/policy.go index 1f3d1b4..b625cf1 100644 --- a/internal/parser/policy.go +++ b/internal/parser/policy.go @@ -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 diff --git a/policy.go b/policy.go index b9fc039..152b714 100644 --- a/policy.go +++ b/policy.go @@ -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. diff --git a/policy_list.go b/policy_list.go index 225dec1..835d170 100644 --- a/policy_list.go +++ b/policy_list.go @@ -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 diff --git a/policy_set.go b/policy_set.go index fad8420..2695c4b 100644 --- a/policy_set.go +++ b/policy_set.go @@ -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 diff --git a/internal/ast/annotation.go b/x/exp/ast/annotation.go similarity index 100% rename from internal/ast/annotation.go rename to x/exp/ast/annotation.go diff --git a/internal/ast/ast_test.go b/x/exp/ast/ast_test.go similarity index 99% rename from internal/ast/ast_test.go rename to x/exp/ast/ast_test.go index fbce2c8..b599849 100644 --- a/internal/ast/ast_test.go +++ b/x/exp/ast/ast_test.go @@ -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 diff --git a/x/exp/ast/doc.go b/x/exp/ast/doc.go new file mode 100644 index 0000000..8475cd1 --- /dev/null +++ b/x/exp/ast/doc.go @@ -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 diff --git a/internal/ast/internal_test.go b/x/exp/ast/internal_test.go similarity index 100% rename from internal/ast/internal_test.go rename to x/exp/ast/internal_test.go diff --git a/internal/ast/node.go b/x/exp/ast/node.go similarity index 100% rename from internal/ast/node.go rename to x/exp/ast/node.go diff --git a/internal/ast/operator.go b/x/exp/ast/operator.go similarity index 100% rename from internal/ast/operator.go rename to x/exp/ast/operator.go diff --git a/internal/ast/policy.go b/x/exp/ast/policy.go similarity index 100% rename from internal/ast/policy.go rename to x/exp/ast/policy.go diff --git a/internal/ast/scope.go b/x/exp/ast/scope.go similarity index 100% rename from internal/ast/scope.go rename to x/exp/ast/scope.go diff --git a/internal/ast/value.go b/x/exp/ast/value.go similarity index 100% rename from internal/ast/value.go rename to x/exp/ast/value.go diff --git a/internal/ast/variable.go b/x/exp/ast/variable.go similarity index 100% rename from internal/ast/variable.go rename to x/exp/ast/variable.go diff --git a/x/exp/batch/batch.go b/x/exp/batch/batch.go index d65e36c..9ae0216 100644 --- a/x/exp/batch/batch.go +++ b/x/exp/batch/batch.go @@ -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. diff --git a/x/exp/batch/batch_test.go b/x/exp/batch/batch_test.go index aad2d94..47adbb2 100644 --- a/x/exp/batch/batch_test.go +++ b/x/exp/batch/batch_test.go @@ -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) {