-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parsing upcoming
let-expression
(#66)
* Fixed mismatched pretty printed parens Signed-off-by: Springcomp <[email protected]> * [lexical-scoping] Parsing let-expression. Signed-off-by: Springcomp <[email protected]> * [lexical-scoping] Refactor comma-separated lists. Signed-off-by: Springcomp <[email protected]> * [lexical-scoping] 'let' and 'in' should be valid identifiers as well. Signed-off-by: Springcomp <[email protected]> * [lexical-scoping] Fixed file is not 'gofumpt' ed Signed-off-by: Springcomp <[email protected]> * [lexical-scoping] Refactored tests. Signed-off-by: Springcomp <[email protected]> * [lexical-scoping] Ensure sustained code coverage. Signed-off-by: Springcomp <[email protected]> * lexing Signed-off-by: Charles-Edouard Brétéché <[email protected]> * interpreter Signed-off-by: Charles-Edouard Brétéché <[email protected]> * error Signed-off-by: Charles-Edouard Brétéché <[email protected]> * fix Signed-off-by: Charles-Edouard Brétéché <[email protected]> * Re-introduced tests that now succeed. Signed-off-by: Springcomp <[email protected]> * Include compliance tests. Signed-off-by: Springcomp <[email protected]> * let() is deprecated. Signed-off-by: Springcomp <[email protected]> * unit tests Signed-off-by: Charles-Edouard Brétéché <[email protected]> --------- Signed-off-by: Springcomp <[email protected]> Signed-off-by: Charles-Edouard Brétéché <[email protected]> Co-authored-by: Charles-Edouard Brétéché <[email protected]>
- Loading branch information
1 parent
7d8d162
commit 4a4bfbf
Showing
14 changed files
with
532 additions
and
54 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
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
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,37 @@ | ||
package binding | ||
|
||
import "fmt" | ||
|
||
// Bindings stores let expression bindings by name. | ||
type Bindings interface { | ||
// Get returns the value bound for a given name. | ||
Get(string) (interface{}, error) | ||
// Register registers a value associated with a given name, it returns a new binding | ||
Register(string, interface{}) Bindings | ||
} | ||
|
||
type bindings struct { | ||
values map[string]interface{} | ||
} | ||
|
||
func NewBindings() Bindings { | ||
return bindings{} | ||
} | ||
|
||
func (b bindings) Get(name string) (interface{}, error) { | ||
if value, ok := b.values[name]; ok { | ||
return value, nil | ||
} | ||
return nil, fmt.Errorf("variable not defined: %s", name) | ||
} | ||
|
||
func (b bindings) Register(name string, value interface{}) Bindings { | ||
values := map[string]interface{}{} | ||
for k, v := range b.values { | ||
values[k] = v | ||
} | ||
values[name] = value | ||
return bindings{ | ||
values: values, | ||
} | ||
} |
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,143 @@ | ||
package binding | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewBindings(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want Bindings | ||
}{{ | ||
want: bindings{}, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := NewBindings(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("NewBindings() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_bindings_Get(t *testing.T) { | ||
type fields struct { | ||
values map[string]interface{} | ||
} | ||
type args struct { | ||
name string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want interface{} | ||
wantErr bool | ||
}{{ | ||
fields: fields{ | ||
values: nil, | ||
}, | ||
args: args{ | ||
name: "$root", | ||
}, | ||
wantErr: true, | ||
}, { | ||
fields: fields{ | ||
values: map[string]interface{}{}, | ||
}, | ||
args: args{ | ||
name: "$root", | ||
}, | ||
wantErr: true, | ||
}, { | ||
fields: fields{ | ||
values: map[string]interface{}{ | ||
"$root": 42.0, | ||
}, | ||
}, | ||
args: args{ | ||
name: "$root", | ||
}, | ||
want: 42.0, | ||
}, { | ||
fields: fields{ | ||
values: map[string]interface{}{ | ||
"$foot": 42.0, | ||
}, | ||
}, | ||
args: args{ | ||
name: "$root", | ||
}, | ||
wantErr: true, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
b := bindings{ | ||
values: tt.fields.values, | ||
} | ||
got, err := b.Get(tt.args.name) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("bindings.Get() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("bindings.Get() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_bindings_Register(t *testing.T) { | ||
type fields struct { | ||
values map[string]interface{} | ||
} | ||
type args struct { | ||
name string | ||
value interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want Bindings | ||
}{{ | ||
fields: fields{ | ||
values: nil, | ||
}, | ||
args: args{ | ||
name: "$root", | ||
value: 42.0, | ||
}, | ||
want: bindings{ | ||
values: map[string]interface{}{ | ||
"$root": 42.0, | ||
}, | ||
}, | ||
}, { | ||
fields: fields{ | ||
values: map[string]interface{}{ | ||
"$root": 21.0, | ||
}, | ||
}, | ||
args: args{ | ||
name: "$root", | ||
value: 42.0, | ||
}, | ||
want: bindings{ | ||
values: map[string]interface{}{ | ||
"$root": 42.0, | ||
}, | ||
}, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
b := bindings{ | ||
values: tt.fields.values, | ||
} | ||
if got := b.Register(tt.args.name, tt.args.value); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("bindings.Register() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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.
Oops, something went wrong.