Skip to content

Commit 28f0dd2

Browse files
committed
More name mucking
1 parent 448e3ee commit 28f0dd2

File tree

15 files changed

+133
-131
lines changed

15 files changed

+133
-131
lines changed

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ linters:
3636
- stdlib
3737
- generic
3838
- spec\.JSONPathValue
39-
- spec\.FunctionExprArg
39+
- spec\.FuncExprArg
4040
- spec\.Selector
4141
- spec\.BasicExpr
4242
- spec\.CompVal

parser/parse.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func (p *parser) parseBasicExpr() (spec.BasicExpr, error) {
410410

411411
// parseFunctionFilterExpr parses a [BasicExpr] (basic-expr) that starts with
412412
// ident, which must be an identifier token that's expected to be the name of
413-
// a function. The return value will be either a [FunctionExpr]
413+
// a function. The return value will be either a [spec.FuncExpr]
414414
// (function-expr), if the function return value is a logical (boolean) value.
415415
// Otherwise it will be a [ComparisonExpr] (comparison-expr), as long as the
416416
// function call is compared to another expression. Any other configuration
@@ -522,8 +522,8 @@ func (p *parser) parseFunction(tok token) (*spec.FuncExpr, error) {
522522
// parseFunctionArgs parses the comma-delimited arguments to a function from
523523
// lex. Arguments may be one of literal, filter-query (including
524524
// singular-query), logical-expr, or function-expr.
525-
func (p *parser) parseFunctionArgs() ([]spec.FunctionExprArg, error) {
526-
res := []spec.FunctionExprArg{}
525+
func (p *parser) parseFunctionArgs() ([]spec.FuncExprArg, error) {
526+
res := []spec.FuncExprArg{}
527527
lex := p.lex
528528
for {
529529
switch tok := p.lex.scan(); tok.tok {

parser/parse_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func TestParseFilter(t *testing.T) {
200200
_ = reg.Register(
201201
"__true",
202202
spec.ArgLogical,
203-
func([]spec.FunctionExprArg) error { return nil },
203+
func([]spec.FuncExprArg) error { return nil },
204204
func([]spec.JSONPathValue) spec.JSONPathValue {
205205
return spec.LogicalTrue
206206
},
@@ -439,7 +439,7 @@ func TestParseFilter(t *testing.T) {
439439
),
440440
)),
441441
},
442-
// FunctionExpr
442+
// FuncExpr
443443
{
444444
name: "function_current",
445445
query: "__true(@)",
@@ -562,7 +562,7 @@ func TestParseFilter(t *testing.T) {
562562
name: "function_no_args",
563563
query: `__true()`,
564564
filter: spec.Filter(spec.And(
565-
spec.Function(trueFunc, []spec.FunctionExprArg{}...),
565+
spec.Function(trueFunc, []spec.FuncExprArg{}...),
566566
)),
567567
},
568568
// ComparisonExpr
@@ -632,7 +632,7 @@ func TestParseFilter(t *testing.T) {
632632
name: "not_function",
633633
query: `!__true()`,
634634
filter: spec.Filter(spec.And(
635-
spec.NotFunction(spec.Function(trueFunc, []spec.FunctionExprArg{}...)),
635+
spec.NotFunction(spec.Function(trueFunc, []spec.FuncExprArg{}...)),
636636
)),
637637
},
638638
{

path_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func ExampleParser_functionExtension() {
270270
// validateFirstArgs validates that a single argument is passed to the first()
271271
// function, and that it can be converted to [spec.FuncNodes], so that first()
272272
// can return the first node. It's called by the parser.
273-
func validateFirstArgs(fea []spec.FunctionExprArg) error {
273+
func validateFirstArgs(fea []spec.FuncExprArg) error {
274274
if len(fea) != 1 {
275275
return fmt.Errorf("expected 1 argument but found %v", len(fea))
276276
}

registry/funcs.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// checkLengthArgs checks the argument expressions to length() and returns an
1414
// error if there is not exactly one expression that results in a
1515
// [spec.FuncValue]-compatible value.
16-
func checkLengthArgs(fea []spec.FunctionExprArg) error {
16+
func checkLengthArgs(fea []spec.FuncExprArg) error {
1717
if len(fea) != 1 {
1818
return fmt.Errorf("expected 1 argument but found %v", len(fea))
1919
}
@@ -58,7 +58,7 @@ func lengthFunc(jv []spec.JSONPathValue) spec.JSONPathValue {
5858
// checkCountArgs checks the argument expressions to count() and returns an
5959
// error if there is not exactly one expression that results in a
6060
// [spec.FuncNodes]-compatible value.
61-
func checkCountArgs(fea []spec.FunctionExprArg) error {
61+
func checkCountArgs(fea []spec.FuncExprArg) error {
6262
if len(fea) != 1 {
6363
return fmt.Errorf("expected 1 argument but found %v", len(fea))
6464
}
@@ -82,7 +82,7 @@ func countFunc(jv []spec.JSONPathValue) spec.JSONPathValue {
8282
// checkValueArgs checks the argument expressions to value() and returns an
8383
// error if there is not exactly one expression that results in a
8484
// [spec.FuncNodes]-compatible value.
85-
func checkValueArgs(fea []spec.FunctionExprArg) error {
85+
func checkValueArgs(fea []spec.FuncExprArg) error {
8686
if len(fea) != 1 {
8787
return fmt.Errorf("expected 1 argument but found %v", len(fea))
8888
}
@@ -111,7 +111,7 @@ func valueFunc(jv []spec.JSONPathValue) spec.JSONPathValue {
111111
// checkMatchArgs checks the argument expressions to match() and returns an
112112
// error if there are not exactly two expressions that result in
113113
// [spec.FuncValue]-compatible values.
114-
func checkMatchArgs(fea []spec.FunctionExprArg) error {
114+
func checkMatchArgs(fea []spec.FuncExprArg) error {
115115
const matchArgLen = 2
116116
if len(fea) != matchArgLen {
117117
return fmt.Errorf("expected 2 arguments but found %v", len(fea))
@@ -146,7 +146,7 @@ func matchFunc(jv []spec.JSONPathValue) spec.JSONPathValue {
146146
// checkSearchArgs checks the argument expressions to search() and returns an
147147
// error if there are not exactly two expressions that result in
148148
// [spec.FuncValue]-compatible values.
149-
func checkSearchArgs(fea []spec.FunctionExprArg) error {
149+
func checkSearchArgs(fea []spec.FuncExprArg) error {
150150
const searchArgLen = 2
151151
if len(fea) != searchArgLen {
152152
return fmt.Errorf("expected 2 arguments but found %v", len(fea))

registry/funcs_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,41 +125,41 @@ func TestCheckSingularFuncArgs(t *testing.T) {
125125

126126
for _, tc := range []struct {
127127
name string
128-
expr []spec.FunctionExprArg
128+
expr []spec.FuncExprArg
129129
err string
130130
lengthErr string
131131
countErr string
132132
valueErr string
133133
}{
134134
{
135135
name: "no_args",
136-
expr: []spec.FunctionExprArg{},
136+
expr: []spec.FuncExprArg{},
137137
err: "expected 1 argument but found 0",
138138
},
139139
{
140140
name: "two_args",
141-
expr: []spec.FunctionExprArg{spec.Literal(nil), spec.Literal(nil)},
141+
expr: []spec.FuncExprArg{spec.Literal(nil), spec.Literal(nil)},
142142
err: "expected 1 argument but found 2",
143143
},
144144
{
145145
name: "literal_string",
146-
expr: []spec.FunctionExprArg{spec.Literal(nil)},
146+
expr: []spec.FuncExprArg{spec.Literal(nil)},
147147
countErr: "cannot convert argument to PathNodes",
148148
valueErr: "cannot convert argument to PathNodes",
149149
},
150150
{
151151
name: "singular_query",
152-
expr: []spec.FunctionExprArg{spec.SingularQuery(false, nil)},
152+
expr: []spec.FuncExprArg{spec.SingularQuery(false, nil)},
153153
},
154154
{
155155
name: "nodes_query",
156-
expr: []spec.FunctionExprArg{spec.NodesQuery(
156+
expr: []spec.FuncExprArg{spec.NodesQuery(
157157
spec.Query(true, spec.Child(spec.Name("x"))),
158158
)},
159159
},
160160
{
161161
name: "logical_func_expr",
162-
expr: []spec.FunctionExprArg{spec.Function(reg.Get("match"),
162+
expr: []spec.FuncExprArg{spec.Function(reg.Get("match"),
163163
spec.NodesQuery(
164164
spec.Query(true, spec.Child(spec.Name("x"))),
165165
),
@@ -171,7 +171,7 @@ func TestCheckSingularFuncArgs(t *testing.T) {
171171
},
172172
{
173173
name: "logical_or",
174-
expr: []spec.FunctionExprArg{spec.LogicalOr{}},
174+
expr: []spec.FuncExprArg{spec.LogicalOr{}},
175175
lengthErr: "cannot convert argument to ValueType",
176176
countErr: "cannot convert argument to PathNodes",
177177
valueErr: "cannot convert argument to PathNodes",
@@ -222,59 +222,59 @@ func TestCheckRegexFuncArgs(t *testing.T) {
222222

223223
for _, tc := range []struct {
224224
name string
225-
expr []spec.FunctionExprArg
225+
expr []spec.FuncExprArg
226226
err string
227227
}{
228228
{
229229
name: "no_args",
230-
expr: []spec.FunctionExprArg{},
230+
expr: []spec.FuncExprArg{},
231231
err: "expected 2 arguments but found 0",
232232
},
233233
{
234234
name: "one_arg",
235-
expr: []spec.FunctionExprArg{spec.Literal("hi")},
235+
expr: []spec.FuncExprArg{spec.Literal("hi")},
236236
err: "expected 2 arguments but found 1",
237237
},
238238
{
239239
name: "three_args",
240-
expr: []spec.FunctionExprArg{spec.Literal("hi"), spec.Literal("hi"), spec.Literal("hi")},
240+
expr: []spec.FuncExprArg{spec.Literal("hi"), spec.Literal("hi"), spec.Literal("hi")},
241241
err: "expected 2 arguments but found 3",
242242
},
243243
{
244244
name: "logical_or_1",
245-
expr: []spec.FunctionExprArg{&spec.LogicalOr{}, spec.Literal("hi")},
245+
expr: []spec.FuncExprArg{&spec.LogicalOr{}, spec.Literal("hi")},
246246
err: "cannot convert argument 1 to PathNodes",
247247
},
248248
{
249249
name: "logical_or_2",
250-
expr: []spec.FunctionExprArg{spec.Literal("hi"), spec.LogicalOr{}},
250+
expr: []spec.FuncExprArg{spec.Literal("hi"), spec.LogicalOr{}},
251251
err: "cannot convert argument 2 to PathNodes",
252252
},
253253
{
254254
name: "singular_query_literal",
255-
expr: []spec.FunctionExprArg{&spec.SingularQueryExpr{}, spec.Literal("hi")},
255+
expr: []spec.FuncExprArg{&spec.SingularQueryExpr{}, spec.Literal("hi")},
256256
},
257257
{
258258
name: "literal_singular_query",
259-
expr: []spec.FunctionExprArg{spec.Literal("hi"), &spec.SingularQueryExpr{}},
259+
expr: []spec.FuncExprArg{spec.Literal("hi"), &spec.SingularQueryExpr{}},
260260
},
261261
{
262262
name: "nodes_query_1",
263-
expr: []spec.FunctionExprArg{
263+
expr: []spec.FuncExprArg{
264264
spec.NodesQuery(spec.Query(true, spec.Child(spec.Name("x")))),
265265
spec.Literal("hi"),
266266
},
267267
},
268268
{
269269
name: "nodes_query_2",
270-
expr: []spec.FunctionExprArg{
270+
expr: []spec.FuncExprArg{
271271
spec.Literal("hi"),
272272
spec.NodesQuery(spec.Query(true, spec.Child(spec.Name("x")))),
273273
},
274274
},
275275
{
276276
name: "func_expr_1",
277-
expr: []spec.FunctionExprArg{
277+
expr: []spec.FuncExprArg{
278278
spec.Function(
279279
reg.Get("match"),
280280
spec.NodesQuery(spec.Query(true, spec.Child(spec.Name("x")))),
@@ -286,7 +286,7 @@ func TestCheckRegexFuncArgs(t *testing.T) {
286286
},
287287
{
288288
name: "func_expr_2",
289-
expr: []spec.FunctionExprArg{
289+
expr: []spec.FuncExprArg{
290290
spec.Literal("hi"),
291291
spec.Function(
292292
reg.Get("match"),

registry/registry.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func New() *Registry {
7272

7373
// Validator functions validate that the args expressions to a function can be
7474
// processed by the function.
75-
type Validator func(args []spec.FunctionExprArg) error
75+
type Validator func(args []spec.FuncExprArg) error
7676

7777
// Evaluator functions execute a function against the values returned by args.
7878
type Evaluator func(args []spec.JSONPathValue) spec.JSONPathValue
@@ -130,7 +130,7 @@ type Function struct {
130130

131131
// validator executes at parse time to validate that all the args to
132132
// the function are compatible with the function.
133-
validator func(args []spec.FunctionExprArg) error
133+
validator func(args []spec.FuncExprArg) error
134134

135135
// evaluator executes the function against args and returns the result of
136136
// type ResultType.
@@ -148,7 +148,7 @@ type Function struct {
148148
func NewFunction(
149149
name string,
150150
resultType spec.ArgType,
151-
validator func(args []spec.FunctionExprArg) error,
151+
validator func(args []spec.FuncExprArg) error,
152152
evaluator func(args []spec.JSONPathValue,
153153
) spec.JSONPathValue,
154154
) *Function {
@@ -169,12 +169,6 @@ func (f *Function) Evaluate(args []spec.JSONPathValue) spec.JSONPathValue {
169169

170170
// Validate executes at parse time to validate that all the args to the
171171
// function are compatible with the function.
172-
func (f *Function) Validate(args []spec.FunctionExprArg) error {
172+
func (f *Function) Validate(args []spec.FuncExprArg) error {
173173
return f.validator((args))
174174
}
175-
176-
// type Function interface {
177-
// Evaluate(args []JSONPathValue) JSONPathValue
178-
// ResultType() FuncType
179-
// Name() string
180-
// }

registry/registry_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Example() {
3030
// validateFirstArgs validates that a single argument is passed to the first()
3131
// function, and that it can be converted to [spec.FuncNodes], so that first()
3232
// can return the first node. It's called by the parser.
33-
func validateFirstArgs(fea []spec.FunctionExprArg) error {
33+
func validateFirstArgs(fea []spec.FuncExprArg) error {
3434
if len(fea) != 1 {
3535
return fmt.Errorf("expected 1 argument but found %v", len(fea))
3636
}

registry/registry_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,43 @@ func TestRegistry(t *testing.T) {
1717
for _, tc := range []struct {
1818
name string
1919
rType spec.ArgType
20-
expr []spec.FunctionExprArg
20+
expr []spec.FuncExprArg
2121
args []spec.JSONPathValue
2222
exp any
2323
}{
2424
// RFC 9535-defined functions.
2525
{
2626
name: "length",
2727
rType: spec.ArgValue,
28-
expr: []spec.FunctionExprArg{spec.Literal("foo")},
28+
expr: []spec.FuncExprArg{spec.Literal("foo")},
2929
args: []spec.JSONPathValue{spec.Value("foo")},
3030
exp: spec.Value(3),
3131
},
3232
{
3333
name: "count",
3434
rType: spec.ArgValue,
35-
expr: []spec.FunctionExprArg{&spec.SingularQueryExpr{}},
35+
expr: []spec.FuncExprArg{&spec.SingularQueryExpr{}},
3636
args: []spec.JSONPathValue{spec.Nodes(1, 2)},
3737
exp: spec.Value(2),
3838
},
3939
{
4040
name: "value",
4141
rType: spec.ArgValue,
42-
expr: []spec.FunctionExprArg{&spec.SingularQueryExpr{}},
42+
expr: []spec.FuncExprArg{&spec.SingularQueryExpr{}},
4343
args: []spec.JSONPathValue{spec.Nodes(42)},
4444
exp: spec.Value(42),
4545
},
4646
{
4747
name: "match",
4848
rType: spec.ArgLogical,
49-
expr: []spec.FunctionExprArg{spec.Literal("foo"), spec.Literal(".*")},
49+
expr: []spec.FuncExprArg{spec.Literal("foo"), spec.Literal(".*")},
5050
args: []spec.JSONPathValue{spec.Value("foo"), spec.Value(".*")},
5151
exp: spec.LogicalTrue,
5252
},
5353
{
5454
name: "search",
5555
rType: spec.ArgLogical,
56-
expr: []spec.FunctionExprArg{spec.Literal("foo"), spec.Literal(".")},
56+
expr: []spec.FuncExprArg{spec.Literal("foo"), spec.Literal(".")},
5757
args: []spec.JSONPathValue{spec.Value("foo"), spec.Value(".")},
5858
exp: spec.LogicalTrue,
5959
},
@@ -90,13 +90,13 @@ func TestRegisterErr(t *testing.T) {
9090
},
9191
{
9292
name: "nil_evaluator",
93-
valid: func([]spec.FunctionExprArg) error { return nil },
93+
valid: func([]spec.FuncExprArg) error { return nil },
9494
err: "register: evaluator is nil",
9595
},
9696
{
9797
name: "existing_func",
9898
fnName: "length",
99-
valid: func([]spec.FunctionExprArg) error { return nil },
99+
valid: func([]spec.FuncExprArg) error { return nil },
100100
eval: func([]spec.JSONPathValue) spec.JSONPathValue { return spec.Value(42) },
101101
err: "register: Register called twice for function length",
102102
},
@@ -125,7 +125,7 @@ func TestFunction(t *testing.T) {
125125
name: "valid_err_value",
126126
fn: NewFunction(
127127
"xyz", spec.ArgValue,
128-
func([]spec.FunctionExprArg) error { return errors.New("oops") },
128+
func([]spec.FuncExprArg) error { return errors.New("oops") },
129129
func([]spec.JSONPathValue) spec.JSONPathValue { return spec.Value(42) },
130130
),
131131
args: []spec.JSONPathValue{},
@@ -136,7 +136,7 @@ func TestFunction(t *testing.T) {
136136
name: "no_valid_err_nodes",
137137
fn: NewFunction(
138138
"abc", spec.ArgNodes,
139-
func([]spec.FunctionExprArg) error { return nil },
139+
func([]spec.FuncExprArg) error { return nil },
140140
func([]spec.JSONPathValue) spec.JSONPathValue { return spec.Nodes("hi") },
141141
),
142142
args: []spec.JSONPathValue{},

0 commit comments

Comments
 (0)