Skip to content

Commit f6fb0f9

Browse files
committed
Fix example
1 parent ff661c2 commit f6fb0f9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

_examples/torpn/torpn.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,19 @@ func Parse(s string) ([]interface{}, error) {
155155
}
156156

157157
if out.MatchStatus == MatchStatus_Matched {
158-
var result AstSlice
159158
switch out.AstStack[0].Type {
160159
case AstType_Int:
161-
result = AstSlice{out.AstStack[0].Value.(Ast)}
160+
return []interface{}{out.AstStack[0].Value.(int64)}, nil
162161
case AstType_ListOfAst:
163-
result = out.AstStack[0].Value.(AstSlice)
164-
}
165-
ret := make([]interface{}, 0, len(result))
166-
for _, v := range result {
167-
ret = append(ret, v.Value)
162+
result := out.AstStack[0].Value.(AstSlice)
163+
ret := make([]interface{}, 0, len(result))
164+
for _, v := range result {
165+
ret = append(ret, v.Value)
166+
}
167+
return ret, nil
168+
default:
169+
return nil, errors.New("Unexpected: no result")
168170
}
169-
return ret, nil
170171
} else {
171172
pos := GetLineAndColPosition(s, out.SourcePosition, 4)
172173
return nil, errors.New(

_examples/torpn/torpn_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ func TestParse(t *testing.T) {
8080
args: args{s: "(3+5)*(7+11)"},
8181
want: []interface{}{int64(3), int64(5), "+", int64(7), int64(11), "+", "*"},
8282
wantErr: false,
83+
}, {
84+
name: "8",
85+
args: args{s: "13"},
86+
want: []interface{}{int64(13)},
87+
wantErr: false,
8388
}}
8489

8590
runMatrixParse(t, tests)

0 commit comments

Comments
 (0)