From 5b418916a83586912048212b955af4649ee22a99 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 5 Jan 2023 14:35:06 +0000 Subject: [PATCH] decoder: bootstrap Expression implementations --- decoder/expr_keyword.go | 40 ++++++++++++++++++ decoder/expr_list.go | 40 ++++++++++++++++++ decoder/expr_literal_type.go | 40 ++++++++++++++++++ decoder/expr_literal_value.go | 40 ++++++++++++++++++ decoder/expr_map.go | 40 ++++++++++++++++++ decoder/expr_object.go | 70 ++++++++++++++++++++++++++++++++ decoder/expr_one_of.go | 40 ++++++++++++++++++ decoder/expr_reference.go | 40 ++++++++++++++++++ decoder/expr_set.go | 40 ++++++++++++++++++ decoder/expr_tuple.go | 40 ++++++++++++++++++ decoder/expr_type_declaration.go | 40 ++++++++++++++++++ decoder/expr_unknown.go | 32 +++++++++++++++ decoder/expression.go | 28 ++++++++++++- decoder/expression_test.go | 15 +++++++ 14 files changed, 543 insertions(+), 2 deletions(-) create mode 100644 decoder/expr_keyword.go create mode 100644 decoder/expr_list.go create mode 100644 decoder/expr_literal_type.go create mode 100644 decoder/expr_literal_value.go create mode 100644 decoder/expr_map.go create mode 100644 decoder/expr_object.go create mode 100644 decoder/expr_one_of.go create mode 100644 decoder/expr_reference.go create mode 100644 decoder/expr_set.go create mode 100644 decoder/expr_tuple.go create mode 100644 decoder/expr_type_declaration.go create mode 100644 decoder/expr_unknown.go create mode 100644 decoder/expression_test.go diff --git a/decoder/expr_keyword.go b/decoder/expr_keyword.go new file mode 100644 index 00000000..1a06e2eb --- /dev/null +++ b/decoder/expr_keyword.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type Keyword struct { + expr hcl.Expression + cons schema.Keyword +} + +func (kw Keyword) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (kw Keyword) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (kw Keyword) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (kw Keyword) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (kw Keyword) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_list.go b/decoder/expr_list.go new file mode 100644 index 00000000..726aaf14 --- /dev/null +++ b/decoder/expr_list.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type List struct { + expr hcl.Expression + cons schema.List +} + +func (l List) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (l List) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (l List) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (l List) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (l List) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_literal_type.go b/decoder/expr_literal_type.go new file mode 100644 index 00000000..5597e0fc --- /dev/null +++ b/decoder/expr_literal_type.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type LiteralType struct { + expr hcl.Expression + cons schema.LiteralType +} + +func (lt LiteralType) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (lt LiteralType) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (lt LiteralType) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (lt LiteralType) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (lt LiteralType) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_literal_value.go b/decoder/expr_literal_value.go new file mode 100644 index 00000000..21c133a3 --- /dev/null +++ b/decoder/expr_literal_value.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type LiteralValue struct { + expr hcl.Expression + cons schema.LiteralValue +} + +func (lv LiteralValue) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (lv LiteralValue) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (lv LiteralValue) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (lv LiteralValue) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (lv LiteralValue) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_map.go b/decoder/expr_map.go new file mode 100644 index 00000000..5bc48a1e --- /dev/null +++ b/decoder/expr_map.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type Map struct { + expr hcl.Expression + cons schema.Map +} + +func (m Map) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (m Map) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (m Map) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (m Map) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (m Map) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_object.go b/decoder/expr_object.go new file mode 100644 index 00000000..d84d1e7b --- /dev/null +++ b/decoder/expr_object.go @@ -0,0 +1,70 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type Object struct { + expr hcl.Expression + cons schema.Object +} + +func (obj Object) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (obj Object) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (obj Object) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (obj Object) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (obj Object) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} + +type ObjectAttributes struct { + expr hcl.Expression + cons schema.ObjectAttributes +} + +func (oa ObjectAttributes) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (oa ObjectAttributes) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (oa ObjectAttributes) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (oa ObjectAttributes) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (oa ObjectAttributes) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_one_of.go b/decoder/expr_one_of.go new file mode 100644 index 00000000..5de7fe0a --- /dev/null +++ b/decoder/expr_one_of.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type OneOf struct { + expr hcl.Expression + cons schema.OneOf +} + +func (oo OneOf) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (oo OneOf) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (oo OneOf) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (oo OneOf) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (oo OneOf) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_reference.go b/decoder/expr_reference.go new file mode 100644 index 00000000..4b1f644a --- /dev/null +++ b/decoder/expr_reference.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type Reference struct { + expr hcl.Expression + cons schema.Reference +} + +func (ref Reference) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (ref Reference) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (ref Reference) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (ref Reference) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (ref Reference) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_set.go b/decoder/expr_set.go new file mode 100644 index 00000000..2db49539 --- /dev/null +++ b/decoder/expr_set.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type Set struct { + expr hcl.Expression + cons schema.Set +} + +func (s Set) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (s Set) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (s Set) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (s Set) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (s Set) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_tuple.go b/decoder/expr_tuple.go new file mode 100644 index 00000000..c4ecf8d2 --- /dev/null +++ b/decoder/expr_tuple.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type Tuple struct { + expr hcl.Expression + cons schema.Tuple +} + +func (t Tuple) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (t Tuple) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (t Tuple) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (t Tuple) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (t Tuple) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_type_declaration.go b/decoder/expr_type_declaration.go new file mode 100644 index 00000000..a6812cde --- /dev/null +++ b/decoder/expr_type_declaration.go @@ -0,0 +1,40 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type TypeDeclaration struct { + expr hcl.Expression + cons schema.TypeDeclaration +} + +func (td TypeDeclaration) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + // TODO + return nil +} + +func (td TypeDeclaration) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + // TODO + return nil +} + +func (td TypeDeclaration) SemanticTokens(ctx context.Context) []lang.SemanticToken { + // TODO + return nil +} + +func (td TypeDeclaration) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + // TODO + return nil +} + +func (td TypeDeclaration) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + // TODO + return nil +} diff --git a/decoder/expr_unknown.go b/decoder/expr_unknown.go new file mode 100644 index 00000000..d456227d --- /dev/null +++ b/decoder/expr_unknown.go @@ -0,0 +1,32 @@ +package decoder + +import ( + "context" + + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/reference" + "github.com/hashicorp/hcl-lang/schema" + "github.com/hashicorp/hcl/v2" +) + +type unknownExpression struct{} + +func (oo unknownExpression) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { + return []lang.Candidate{} +} + +func (oo unknownExpression) HoverAtPos(ctx context.Context, pos hcl.Pos) *lang.HoverData { + return nil +} + +func (oo unknownExpression) SemanticTokens(ctx context.Context) []lang.SemanticToken { + return []lang.SemanticToken{} +} + +func (oo unknownExpression) ReferenceOrigins(allowSelfRefs bool) reference.Origins { + return reference.Origins{} +} + +func (oo unknownExpression) ReferenceTargets(attrAddr *schema.AttributeAddrSchema) reference.Targets { + return reference.Targets{} +} diff --git a/decoder/expression.go b/decoder/expression.go index 8c6e9b6c..6559c472 100644 --- a/decoder/expression.go +++ b/decoder/expression.go @@ -20,6 +20,30 @@ type Expression interface { } func NewExpression(expr hcl.Expression, cons schema.Constraint) Expression { - // TODO - return nil + switch c := cons.(type) { + case schema.LiteralType: + return LiteralType{expr: expr, cons: c} + case schema.Reference: + return Reference{expr: expr, cons: c} + case schema.TypeDeclaration: + return TypeDeclaration{expr: expr, cons: c} + case schema.Keyword: + return Keyword{expr: expr, cons: c} + case schema.List: + return List{expr: expr, cons: c} + case schema.Set: + return Set{expr: expr, cons: c} + case schema.Tuple: + return Tuple{expr: expr, cons: c} + case schema.Object: + return Object{expr: expr, cons: c} + case schema.Map: + return Map{expr: expr, cons: c} + case schema.OneOf: + return OneOf{expr: expr, cons: c} + case schema.LiteralValue: + return LiteralValue{expr: expr, cons: c} + } + + return unknownExpression{} } diff --git a/decoder/expression_test.go b/decoder/expression_test.go new file mode 100644 index 00000000..e42331d3 --- /dev/null +++ b/decoder/expression_test.go @@ -0,0 +1,15 @@ +package decoder + +var ( + _ Expression = Keyword{} + _ Expression = List{} + _ Expression = LiteralType{} + _ Expression = LiteralValue{} + _ Expression = Map{} + _ Expression = ObjectAttributes{} + _ Expression = Object{} + _ Expression = Set{} + _ Expression = Reference{} + _ Expression = Tuple{} + _ Expression = TypeDeclaration{} +)