Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
059bc274
Commit
059bc274
authored
Feb 26, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/parser cleanup: remove some state by writing more functional code
R=rsc CC=golang-dev
https://golang.org/cl/223071
parent
bc687833
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
16 deletions
+17
-16
src/pkg/go/parser/parser.go
src/pkg/go/parser/parser.go
+17
-16
No files found.
src/pkg/go/parser/parser.go
View file @
059bc274
...
...
@@ -46,7 +46,6 @@ type parser struct {
// Comments
comments
vector
.
Vector
// list of *CommentGroup
lastComment
*
ast
.
CommentGroup
// last comment in the comments list
leadComment
*
ast
.
CommentGroup
// the last lead comment
lineComment
*
ast
.
CommentGroup
// the last line comment
...
...
@@ -163,13 +162,13 @@ func (p *parser) consumeComment() (comment *ast.Comment, endline int) {
// Consume a group of adjacent comments, add it to the parser's
// comments list, and return
the line of which the last comment
//
in the group ends. An empty line or non-comment token terminates
// a comment group.
// comments list, and return
it together with the line at which
//
the last comment in the group ends. An empty line or non-comment
//
token terminates
a comment group.
//
func
(
p
*
parser
)
consumeCommentGroup
()
int
{
func
(
p
*
parser
)
consumeCommentGroup
()
(
comments
*
ast
.
CommentGroup
,
endline
int
)
{
var
list
vector
.
Vector
endline
:
=
p
.
pos
.
Line
endline
=
p
.
pos
.
Line
for
p
.
tok
==
token
.
COMMENT
&&
endline
+
1
>=
p
.
pos
.
Line
{
var
comment
*
ast
.
Comment
comment
,
endline
=
p
.
consumeComment
()
...
...
@@ -183,11 +182,10 @@ func (p *parser) consumeCommentGroup() int {
}
// add comment group to the comments list
g
:=
&
ast
.
CommentGroup
{
group
}
p
.
comments
.
Push
(
g
)
p
.
lastComment
=
g
comments
=
&
ast
.
CommentGroup
{
group
}
p
.
comments
.
Push
(
comments
)
return
endline
return
}
...
...
@@ -213,27 +211,30 @@ func (p *parser) next() {
p
.
next0
()
if
p
.
tok
==
token
.
COMMENT
{
var
comment
*
ast
.
CommentGroup
var
endline
int
if
p
.
pos
.
Line
==
line
{
// The comment is on same line as previous token; it
// cannot be a lead comment but may be a line comment.
endline
:
=
p
.
consumeCommentGroup
()
comment
,
endline
=
p
.
consumeCommentGroup
()
if
p
.
pos
.
Line
!=
endline
{
// The next token is on a different line, thus
// the last comment group is a line comment.
p
.
lineComment
=
p
.
lastC
omment
p
.
lineComment
=
c
omment
}
}
// consume successor comments, if any
endline
:
=
-
1
endline
=
-
1
for
p
.
tok
==
token
.
COMMENT
{
endline
=
p
.
consumeCommentGroup
()
comment
,
endline
=
p
.
consumeCommentGroup
()
}
if
endline
>=
0
&&
endline
+
1
==
p
.
pos
.
Line
{
if
endline
+
1
==
p
.
pos
.
Line
{
// The next token is following on the line immediately after the
// comment group, thus the last comment group is a lead comment.
p
.
leadComment
=
p
.
lastC
omment
p
.
leadComment
=
c
omment
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment