From d72868194afab96a309ebfe0ce1a1a2eea1d9b38 Mon Sep 17 00:00:00 2001 From: chai2010 Date: Sun, 28 Aug 2022 12:23:25 +0800 Subject: [PATCH] =?UTF-8?q?type=20=E6=8C=87=E4=BB=A4=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=86=92=E5=8F=B7=E5=88=86=E9=9A=94=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/ast/ast.go | 11 ++++++----- internal/parser/parser.go | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 64d3d5d..7c42b3f 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -798,11 +798,12 @@ type ( // A TypeSpec node represents a type declaration (TypeSpec production). TypeSpec struct { - Doc *CommentGroup // associated documentation; or nil - Name *Ident // type name - Assign token.Pos // position of '=', if any - Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes - Comment *CommentGroup // line comments; or nil + Doc *CommentGroup // associated documentation; or nil + Name *Ident // type name + ColonPos token.Pos // position of ":" operator (token.NoPos if there is no ":") + Assign token.Pos // position of '=', if any + Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes + Comment *CommentGroup // line comments; or nil } ) diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 74bb09f..a330cbf 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -2297,7 +2297,10 @@ func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast. // (Global identifiers are resolved in a separate phase after parsing.) spec := &ast.TypeSpec{Doc: doc, Name: ident} p.declare(spec, nil, p.topScope, ast.Typ, ident) - if p.tok == token.ASSIGN { + if p.tok == token.COLON { + spec.ColonPos = p.pos + p.next() + } else if p.tok == token.ASSIGN { spec.Assign = p.pos p.next() } -- GitLab