Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
907e998c
Commit
907e998c
authored
Oct 29, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/scanner: added another test case, clarified some code
R=rsc CC=golang-dev
https://golang.org/cl/2741042
parent
11684680
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
8 deletions
+7
-8
scanner.go
src/pkg/go/scanner/scanner.go
+4
-8
scanner_test.go
src/pkg/go/scanner/scanner_test.go
+3
-0
No files found.
src/pkg/go/scanner/scanner.go
View file @
907e998c
...
@@ -197,11 +197,11 @@ func (S *Scanner) scanComment(pos token.Position) {
...
@@ -197,11 +197,11 @@ func (S *Scanner) scanComment(pos token.Position) {
func
(
S
*
Scanner
)
findLineEnd
(
pos
token
.
Position
)
bool
{
func
(
S
*
Scanner
)
findLineEnd
(
pos
token
.
Position
)
bool
{
//
first '/' already consumed; assume S.ch == '/' || S.ch == '*
'
//
initial '/' already consumed; pos is position of '/
'
// read ahead until a newline, EOF, or non-comment token is found
// read ahead until a newline, EOF, or non-comment token is found
lineend
:=
false
lineend
:=
false
for
pos1
:=
pos
;
S
.
ch
>=
0
;
{
for
pos1
:=
pos
;
S
.
ch
==
'/'
||
S
.
ch
==
'*'
;
{
if
S
.
ch
==
'/'
{
if
S
.
ch
==
'/'
{
//-style comment always contains a newline
//-style comment always contains a newline
lineend
=
true
lineend
=
true
...
@@ -224,17 +224,13 @@ func (S *Scanner) findLineEnd(pos token.Position) bool {
...
@@ -224,17 +224,13 @@ func (S *Scanner) findLineEnd(pos token.Position) bool {
break
break
}
}
pos1
=
S
.
pos
pos1
=
S
.
pos
S
.
next
()
S
.
next
()
// consume '/'
if
S
.
ch
!=
'/'
&&
S
.
ch
!=
'*'
{
// non-comment token
break
}
}
}
// reset position to where it was upon calling findLineEnd
// reset position to where it was upon calling findLineEnd
S
.
pos
=
pos
S
.
pos
=
pos
S
.
offset
=
pos
.
Offset
+
1
S
.
offset
=
pos
.
Offset
+
1
S
.
next
()
S
.
next
()
// consume initial '/' again
return
lineend
return
lineend
}
}
...
...
src/pkg/go/scanner/scanner_test.go
View file @
907e998c
...
@@ -407,8 +407,11 @@ var lines = []string{
...
@@ -407,8 +407,11 @@ var lines = []string{
"foo $/*comment*/
\n
"
,
"foo $/*comment*/
\n
"
,
"foo $/*0*/ /*1*/ /*2*/
\n
"
,
"foo $/*0*/ /*1*/ /*2*/
\n
"
,
"foo $/**/ /*-------------*/ /*----
\n
*/bar $/*
\n
*/baa$
\n
"
,
"foo $/**/ /*-------------*/ /*----
\n
*/bar $/*
\n
*/baa$
\n
"
,
"foo $/* an EOF terminates a line */"
,
"foo $/* an EOF terminates a line *//*"
,
"package main$
\n\n
func main() {
\n\t
if {
\n\t\t
return /* */ }$
\n
}$
\n
"
,
"package main$
\n\n
func main() {
\n\t
if {
\n\t\t
return /* */ }$
\n
}$
\n
"
,
"package main$"
,
}
}
...
...
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