提交 cd5d785b 编写于 作者: chai2010's avatar chai2010

import 支持可选 => 符号

上级 1365d395
......@@ -3,9 +3,9 @@
导入 "fmt"
import (
"3rdparty/pkg"
"myapp/mymath"
"myapp/mypkg"
"3rdparty/pkg" => pkg
"myapp/mymath" => mymath
"myapp/mypkg" => mypkg
)
函数 main() {
......
......@@ -2170,14 +2170,33 @@ func (p *parser) parseImportSpec(doc *ast.CommentGroup, _ token.Token, _ int) as
} else {
p.expect(token.STRING) // use expect() error handling
}
// parse => asname
var arrowPos token.Pos
if ident == nil && p.tok == token.ARROW {
arrowPos = p.pos
p.next() // skip =>
switch p.tok {
case token.PERIOD:
ident = &ast.Ident{NamePos: p.pos, Name: "."}
p.next()
case token.IDENT:
ident = p.parseIdent()
default:
p.expect(token.IDENT)
}
}
p.expectSemi() // call before accessing p.linecomment
// collect imports
spec := &ast.ImportSpec{
Doc: doc,
Name: ident,
Path: &ast.BasicLit{ValuePos: pos, Kind: token.STRING, Value: path},
Comment: p.lineComment,
Doc: doc,
Name: ident,
Path: &ast.BasicLit{ValuePos: pos, Kind: token.STRING, Value: path},
ArrowPos: arrowPos,
Comment: p.lineComment,
}
p.imports = append(p.imports, spec)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册