-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support serialization of Go types to arr.ai Values
Sometimes for performance it is preferable to construct data structures in Go, then load them into arr.ai for processing. This is currently possible to an extent with numbers, strings and dictionaries via `rel.NewValue(interface{})`, but custom structs, arrays, pointers, etc. are unsupported. This PR adds support for them. Changes proposed in this pull request: - Extend `rel.NewValue` to serialize Go types, such as structs, slices and pointers. - Change `rel.NewValue` to serialize slices to arrays by default. - Interpret `` `unordered:"true"` `` tag on struct fields as hint to serialize to a slice to set instead. Checklist: - [x] Added related tests - [x] Made corresponding changes to the documentation
- Loading branch information
Showing
10 changed files
with
228 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
id: exprs | ||
title: Expressions | ||
--- | ||
|
||
Arr.ai expressions are combinations of syntax which can be evaluated to produce some value. All arr.ai programs are expressions, and every [value](./values.md) and operation in a program is an expression. | ||
|
||
## Implementation | ||
|
||
Each expression is a type defined in the `rel` package, and implements the `Expr` interface: | ||
|
||
```go | ||
type Expr interface { | ||
// All exprs can be serialized to strings with the String() method. | ||
fmt.Stringer | ||
|
||
// Eval evaluates the expr in a given scope. | ||
Eval(ctx context.Context, local Scope) (Value, error) | ||
|
||
// Source returns the Scanner that locates the expression in a source file. | ||
Source() parser.Scanner | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
id: grammar | ||
title: Grammar | ||
--- | ||
|
||
The grammar specifies which sequences of characters are valid arr.ai programs and which are not. Adding new syntax to arr.ai requires a change to the grammar (but don't forget that [macros](../lang/macros.md) may be able to solve your problem more easily). | ||
|
||
The arr.ai grammar is defined using [ωBNF](https://github.com/arr-ai/wbnf) in [arrai.wbnf](https://github.com/arr-ai/arrai/blob/master/syntax/arrai.wbnf). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
id: overview | ||
title: Developing arr.ai | ||
--- | ||
|
||
If you want to make changes to the arr.ai language itself, this section is for your. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
id: values | ||
title: Values | ||
--- | ||
|
||
Arr.ai values numbers, tuples, sets, and various other structures built on top of them. Values are [expressions](./exprs.md) that simply evaluate to themselves. | ||
|
||
## Implementation | ||
|
||
Each value is a type defined in the `rel` package, and implements the `Value` interface (which extends the `Expr` interface). | ||
|
||
Constructing new Value instances from Go values can be done with `rel.NewValue(interface{})`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.