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

Improve JSON marshalling for more AST elements #302

Merged
merged 2 commits into from
Aug 10, 2020
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
71 changes: 68 additions & 3 deletions runtime/ast/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,25 @@ func (e *ConditionalExpression) EndPosition() Position {
return e.Else.EndPosition()
}

func (e *ConditionalExpression) MarshalJSON() ([]byte, error) {
type Alias ConditionalExpression
return json.Marshal(&struct {
Type string
Range
*Alias
}{
Type: "ConditionalExpression",
Range: NewRangeFromPositioned(e),
Alias: (*Alias)(e),
})
}

// UnaryExpression

type UnaryExpression struct {
Operation Operation
Expression Expression
StartPos Position
StartPos Position `json:"-"`
}

func (*UnaryExpression) isExpression() {}
Expand Down Expand Up @@ -634,6 +647,19 @@ func (e *UnaryExpression) EndPosition() Position {
return e.Expression.EndPosition()
}

func (e *UnaryExpression) MarshalJSON() ([]byte, error) {
type Alias UnaryExpression
return json.Marshal(&struct {
Type string
Range
*Alias
}{
Type: "UnaryExpression",
Range: NewRangeFromPositioned(e),
Alias: (*Alias)(e),
})
}

// BinaryExpression

type BinaryExpression struct {
Expand Down Expand Up @@ -669,6 +695,19 @@ func (e *BinaryExpression) EndPosition() Position {
return e.Right.EndPosition()
}

func (e *BinaryExpression) MarshalJSON() ([]byte, error) {
type Alias BinaryExpression
return json.Marshal(&struct {
Type string
Range
*Alias
}{
Type: "BinaryExpression",
Range: NewRangeFromPositioned(e),
Alias: (*Alias)(e),
})
}

// FunctionExpression

type FunctionExpression struct {
Expand Down Expand Up @@ -777,7 +816,7 @@ func (e *CreateExpression) EndPosition() Position {

type DestroyExpression struct {
Expression Expression
StartPos Position
StartPos Position `json:"-"`
}

func (*DestroyExpression) isExpression() {}
Expand Down Expand Up @@ -807,6 +846,19 @@ func (e *DestroyExpression) EndPosition() Position {
return e.Expression.EndPosition()
}

func (e *DestroyExpression) MarshalJSON() ([]byte, error) {
type Alias DestroyExpression
return json.Marshal(&struct {
Type string
Range
*Alias
}{
Type: "DestroyExpression",
Range: NewRangeFromPositioned(e),
Alias: (*Alias)(e),
})
}

// ReferenceExpression

type ReferenceExpression struct {
Expand Down Expand Up @@ -847,7 +899,7 @@ func (e *ReferenceExpression) EndPosition() Position {

type ForceExpression struct {
Expression Expression
EndPos Position
EndPos Position `json:"-"`
}

func (*ForceExpression) isExpression() {}
Expand All @@ -874,6 +926,19 @@ func (e *ForceExpression) EndPosition() Position {
return e.EndPos
}

func (e *ForceExpression) MarshalJSON() ([]byte, error) {
type Alias ForceExpression
return json.Marshal(&struct {
Type string
Range
*Alias
}{
Type: "ForceExpression",
Range: NewRangeFromPositioned(e),
Alias: (*Alias)(e),
})
}

// PathExpression

type PathExpression struct {
Expand Down
Loading