Skip to content

Commit c651310

Browse files
fix: Remove unused code and simplify type assertions
Co-Authored-By: [email protected] <[email protected]>
1 parent a53f0e4 commit c651310

File tree

3 files changed

+4
-94
lines changed

3 files changed

+4
-94
lines changed

jparse/crossref.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (n CrossReferenceNode) Evaluate(ctx *Context) (interface{}, error) {
5858
itemCtx = itemCtx.WithVariable(varNode.Name, item)
5959

6060
// If there's a predicate after the variable, evaluate it
61-
if pred, ok := varNode.Next.(Node); ok {
61+
if pred := varNode.Next; pred != nil {
6262
predCtx := itemCtx.WithInput(item)
6363
result, err := pred.Evaluate(predCtx)
6464
if err != nil {
@@ -133,7 +133,7 @@ func (n CrossReferenceNode) Evaluate(ctx *Context) (interface{}, error) {
133133
rhsCtx = rhsCtx.WithVariable(varNode.Name, lhs)
134134

135135
// If there's a predicate after the variable, evaluate it
136-
if pred, ok := varNode.Next.(Node); ok {
136+
if pred := varNode.Next; pred != nil {
137137
predCtx := rhsCtx.WithInput(lhs)
138138
result, err := pred.Evaluate(predCtx)
139139
if err != nil {

jparse/lexer.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,7 @@ func isDigit(r rune) bool {
666666
return r >= '0' && r <= '9'
667667
}
668668

669-
func isNonZeroDigit(r rune) bool {
670-
return r >= '1' && r <= '9'
671-
}
669+
672670

673671
func isBinaryDigit(r rune) bool {
674672
return r == '0' || r == '1'

jparse/node.go

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -307,19 +307,14 @@ func (n PathNode) Evaluate(ctx *Context) (interface{}, error) {
307307

308308
var current interface{} = ctx.Input
309309
for i, step := range n.Steps {
310-
stepNode, ok := step.(Node)
311-
if !ok {
312-
return nil, fmt.Errorf("invalid path step type at position %d", i)
313-
}
314-
315310
nextCtx := &Context{
316311
Parent: ctx,
317312
Position: -1,
318313
Input: current,
319314
}
320315

321316
var err error
322-
current, err = stepNode.Evaluate(nextCtx)
317+
current, err = step.Evaluate(nextCtx)
323318
if err != nil {
324319
return nil, err
325320
}
@@ -1559,7 +1554,6 @@ func (n PredicateNode) Evaluate(ctx *Context) (interface{}, error) {
15591554
}
15601555
default:
15611556
match = false
1562-
break
15631557
}
15641558
}
15651559

@@ -2416,89 +2410,7 @@ func (n FunctionApplicationNode) Evaluate(ctx *Context) (interface{}, error) {
24162410
// expressions. It is deliberately unexported and creates a PathNode
24172411
// during its optimize phase.
24182412

2419-
// A dotNode is an interim structure used to process JSONata path
2420-
// expressions. It is deliberately unexported and creates a PathNode
2421-
// during its optimize phase.
2422-
type dotNode struct {
2423-
lhs Node
2424-
rhs Node
2425-
}
2426-
2427-
func parseDot(p *parser, t token, lhs Node) (Node, error) {
2428-
return &dotNode{
2429-
lhs: lhs,
2430-
rhs: p.parseExpression(p.bp(t.Type)),
2431-
}, nil
2432-
}
2433-
2434-
func (n *dotNode) optimize() (Node, error) {
2435-
path := &PathNode{}
2436-
2437-
lhs, err := n.lhs.optimize()
2438-
if err != nil {
2439-
return nil, err
2440-
}
2441-
2442-
switch lhs := lhs.(type) {
2443-
case *NumberNode, *StringNode, *BooleanNode, *NullNode:
2444-
return nil, &Error{
2445-
Type: ErrPathLiteral,
2446-
Hint: lhs.String(),
2447-
}
2448-
case *PathNode:
2449-
path.Steps = lhs.Steps
2450-
if lhs.KeepArrays {
2451-
path.KeepArrays = true
2452-
}
2453-
default:
2454-
path.Steps = []Node{lhs}
2455-
}
2456-
2457-
rhs, err := n.rhs.optimize()
2458-
if err != nil {
2459-
return nil, err
2460-
}
2461-
2462-
switch rhs := rhs.(type) {
2463-
case *NumberNode, *StringNode, *BooleanNode, *NullNode:
2464-
return nil, &Error{
2465-
Type: ErrPathLiteral,
2466-
Hint: rhs.String(),
2467-
}
2468-
case *PathNode:
2469-
path.Steps = append(path.Steps, rhs.Steps...)
2470-
if rhs.KeepArrays {
2471-
path.KeepArrays = true
2472-
}
2473-
default:
2474-
path.Steps = append(path.Steps, rhs)
2475-
}
2476-
2477-
return path, nil
2478-
}
24792413

2480-
func (n dotNode) String() string {
2481-
return fmt.Sprintf("%s.%s", n.lhs, n.rhs)
2482-
}
2483-
2484-
func (n dotNode) Evaluate(ctx *Context) (interface{}, error) {
2485-
lhs, err := n.lhs.Evaluate(ctx)
2486-
if err != nil {
2487-
return nil, err
2488-
}
2489-
2490-
if lhs == nil {
2491-
return nil, nil
2492-
}
2493-
2494-
rhsCtx := &Context{
2495-
Input: lhs,
2496-
Parent: ctx,
2497-
Position: -1,
2498-
}
2499-
2500-
return n.rhs.Evaluate(rhsCtx)
2501-
}
25022414

25032415
// A singletonArrayNode is an interim data structure used when
25042416
// processing path expressions. It is deliberately unexported

0 commit comments

Comments
 (0)