mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-12-20 04:34:20 +08:00
ch12: fix code path
This commit is contained in:
@@ -16,9 +16,8 @@ Unmarshal函數使用了反射機製類脩改movie變量的每個成員,根據
|
||||
|
||||
因爲每個解析器可能需要多次使用當前的記號,但是Scan會一直向前掃描,所有我們包裝了一個lexer掃描器輔助類型,用於跟蹤最近由Scan方法返迴的記號。
|
||||
|
||||
<u><i>gopl.io/ch12/sexpr</i></u>
|
||||
```Go
|
||||
gopl.io/ch12/sexpr
|
||||
|
||||
type lexer struct {
|
||||
scan scanner.Scanner
|
||||
token rune // the current token
|
||||
@@ -158,5 +157,3 @@ func Unmarshal(data []byte, out interface{}) (err error) {
|
||||
**練習 12.9:** 編寫一個基於標記的API用於解碼S表達式,參考xml.Decoder(7.14)的風格。你將需要五種類型的標記:Symbol、String、Int、StartList和EndList。
|
||||
|
||||
**練習 12.10:** 擴展sexpr.Unmarshal函數,支持布爾型、浮點數和interface類型的解碼,使用 **練習 12.3:** 的方案。(提示:要解碼接口,你需要將name映射到每個支持類型的reflect.Type。)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user