Skip to content

Commit d92e2ec

Browse files
committed
Make conf top-level package
1 parent 16e2929 commit d92e2ec

File tree

14 files changed

+67
-58
lines changed

14 files changed

+67
-58
lines changed

checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"reflect"
66

77
"github.com/antonmedv/expr/ast"
8+
"github.com/antonmedv/expr/conf"
89
"github.com/antonmedv/expr/file"
9-
"github.com/antonmedv/expr/internal/conf"
1010
"github.com/antonmedv/expr/parser"
1111
)
1212

checker/checker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/antonmedv/expr"
1010
"github.com/antonmedv/expr/checker"
11-
"github.com/antonmedv/expr/internal/conf"
11+
"github.com/antonmedv/expr/conf"
1212
"github.com/antonmedv/expr/parser"
1313
"github.com/stretchr/testify/assert"
1414
)

compiler/compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"reflect"
88

99
"github.com/antonmedv/expr/ast"
10+
"github.com/antonmedv/expr/conf"
1011
"github.com/antonmedv/expr/file"
11-
"github.com/antonmedv/expr/internal/conf"
1212
"github.com/antonmedv/expr/parser"
1313
. "github.com/antonmedv/expr/vm"
1414
)

compiler/compiler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77

88
"github.com/antonmedv/expr/compiler"
9-
"github.com/antonmedv/expr/internal/conf"
9+
"github.com/antonmedv/expr/conf"
1010
"github.com/antonmedv/expr/parser"
1111
"github.com/antonmedv/expr/vm"
1212
"github.com/stretchr/testify/assert"

compiler/patcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package compiler
22

33
import (
44
"github.com/antonmedv/expr/ast"
5-
"github.com/antonmedv/expr/internal/conf"
5+
"github.com/antonmedv/expr/conf"
66
)
77

88
type operatorPatcher struct {

internal/conf/config.go renamed to conf/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package conf
22

33
import (
44
"fmt"
5+
"reflect"
6+
57
"github.com/antonmedv/expr/ast"
68
"github.com/antonmedv/expr/vm"
7-
"reflect"
89
)
910

1011
type Config struct {
File renamed without changes.
File renamed without changes.

docgen/docgen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"regexp"
66
"strings"
77

8-
"github.com/antonmedv/expr/internal/conf"
8+
"github.com/antonmedv/expr/conf"
99
)
1010

1111
// Kind can be any of array, map, struct, func, string, int, float, bool or any.

expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/antonmedv/expr/checker"
1010
"github.com/antonmedv/expr/compiler"
11-
"github.com/antonmedv/expr/internal/conf"
11+
"github.com/antonmedv/expr/conf"
1212
"github.com/antonmedv/expr/optimizer"
1313
"github.com/antonmedv/expr/parser"
1414
"github.com/antonmedv/expr/vm"

expr_test.go

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,48 @@ func ExampleAllowUndefinedVariables_zero_value_functions() {
373373
// Output: [foo bar]
374374
}
375375

376+
func ExamplePatch() {
377+
/*
378+
type patcher struct{}
379+
380+
func (p *patcher) Enter(_ *ast.Node) {}
381+
func (p *patcher) Exit(node *ast.Node) {
382+
switch n := (*node).(type) {
383+
case *ast.PropertyNode:
384+
ast.Patch(node, &ast.FunctionNode{
385+
Name: "get",
386+
Arguments: []ast.Node{n.Node, &ast.StringNode{Value: n.Property}},
387+
})
388+
}
389+
}
390+
*/
391+
392+
program, err := expr.Compile(
393+
`greet.you.world + "!"`,
394+
expr.Patch(&patcher{}),
395+
)
396+
if err != nil {
397+
fmt.Printf("%v", err)
398+
return
399+
}
400+
401+
env := map[string]interface{}{
402+
"greet": "Hello",
403+
"get": func(a, b string) string {
404+
return a + ", " + b
405+
},
406+
}
407+
408+
output, err := expr.Run(program, env)
409+
if err != nil {
410+
fmt.Printf("%v", err)
411+
return
412+
}
413+
fmt.Printf("%v", output)
414+
415+
// Output : Hello, you, world!
416+
}
417+
376418
func TestOperator_struct(t *testing.T) {
377419
env := &mockEnv{
378420
BirthDay: time.Date(2017, time.October, 23, 18, 30, 0, 0, time.UTC),
@@ -944,53 +986,6 @@ func TestConstExpr_error_no_env(t *testing.T) {
944986
require.Equal(t, "no environment for const expression: divide", err.Error())
945987
}
946988

947-
func TestPatch(t *testing.T) {
948-
env := map[string]interface{}{
949-
"x": map[string]interface{}{
950-
"foo": map[string]interface{}{
951-
"bar": "hello",
952-
},
953-
},
954-
}
955-
956-
program, err := expr.Compile(
957-
`x.foo.bar`,
958-
expr.Env(env),
959-
expr.Patch(&patcher{}),
960-
)
961-
require.NoError(t, err)
962-
963-
env = map[string]interface{}{
964-
"x": map[string]interface{}{
965-
"Foo": func() interface{} {
966-
return map[string]interface{}{
967-
"Bar": func() string {
968-
return "patched"
969-
},
970-
}
971-
},
972-
},
973-
}
974-
975-
out, err := expr.Run(program, env)
976-
require.NoError(t, err)
977-
require.Equal(t, "patched", out)
978-
}
979-
980-
type patcher struct {
981-
}
982-
983-
func (p *patcher) Enter(_ *ast.Node) {}
984-
func (p *patcher) Exit(node *ast.Node) {
985-
switch n := (*node).(type) {
986-
case *ast.PropertyNode:
987-
ast.Patch(node, &ast.MethodNode{
988-
Node: n.Node,
989-
Method: strings.Title(n.Property),
990-
})
991-
}
992-
}
993-
994989
//
995990
// Mock types
996991
//
@@ -1118,3 +1113,16 @@ type is struct{}
11181113
func (is) Nil(a interface{}) bool {
11191114
return a == nil
11201115
}
1116+
1117+
type patcher struct{}
1118+
1119+
func (p *patcher) Enter(_ *ast.Node) {}
1120+
func (p *patcher) Exit(node *ast.Node) {
1121+
switch n := (*node).(type) {
1122+
case *ast.PropertyNode:
1123+
ast.Patch(node, &ast.FunctionNode{
1124+
Name: "get",
1125+
Arguments: []ast.Node{n.Node, &ast.StringNode{Value: n.Property}},
1126+
})
1127+
}
1128+
}

optimizer/optimizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package optimizer
22

33
import (
44
. "github.com/antonmedv/expr/ast"
5-
"github.com/antonmedv/expr/internal/conf"
5+
"github.com/antonmedv/expr/conf"
66
)
77

88
func Optimize(node *Node, config *conf.Config) error {

optimizer/optimizer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/antonmedv/expr/ast"
88
"github.com/antonmedv/expr/checker"
9-
"github.com/antonmedv/expr/internal/conf"
9+
"github.com/antonmedv/expr/conf"
1010
"github.com/antonmedv/expr/optimizer"
1111
"github.com/antonmedv/expr/parser"
1212
"github.com/stretchr/testify/assert"

vm/vm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/antonmedv/expr/checker"
99
"github.com/antonmedv/expr/compiler"
10-
"github.com/antonmedv/expr/internal/conf"
10+
"github.com/antonmedv/expr/conf"
1111
"github.com/antonmedv/expr/parser"
1212
"github.com/antonmedv/expr/vm"
1313
"github.com/stretchr/testify/require"

0 commit comments

Comments
 (0)