Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit f20fe64

Browse files
committed
sem: simplify custom Op following code review
Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent fbed224 commit f20fe64

1 file changed

Lines changed: 2 additions & 18 deletions

File tree

driver/normalizer/normalizer.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ var Normalizers = []Mapping{
136136
MapSemantic("StringLiteral", uast.String{}, MapObj(
137137
Fields{
138138
{Name: "normValue", Op: Var("val")},
139-
{Name: "value", Drop: true, Op: singleQuote{Any()}}, // only used in Annotated
139+
{Name: "value", Drop: true, Op: Check(singleQuote{}, Any())}, // only used in Annotated
140140
},
141141
Obj{
142142
"Value": Var("val"),
@@ -362,7 +362,6 @@ var Normalizers = []Mapping{
362362
}
363363

364364
type singleQuote struct {
365-
op Op
366365
}
367366

368367
func (op singleQuote) Kinds() nodes.Kind {
@@ -375,20 +374,5 @@ func (op singleQuote) Check(st *State, n nodes.Node) (bool, error) {
375374
return false, nil
376375
}
377376
s := string(sn)
378-
if !strings.HasPrefix(s, `'`) || !strings.HasSuffix(s, `'`) {
379-
return false, nil
380-
}
381-
return op.op.Check(st, nodes.String(s))
382-
}
383-
384-
func (op singleQuote) Construct(st *State, n nodes.Node) (nodes.Node, error) {
385-
n, err := op.op.Construct(st, n)
386-
if err != nil {
387-
return nil, err
388-
}
389-
sn, ok := n.(nodes.String)
390-
if !ok {
391-
return nil, ErrUnexpectedType.New(nodes.String(""), n)
392-
}
393-
return sn, nil
377+
return strings.HasPrefix(s, `'`) && strings.HasSuffix(s, `'`), nil
394378
}

0 commit comments

Comments
 (0)