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
8b60613b
Commit
8b60613b
authored
Jan 25, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/scanner: Use explicit scanner.Mode type.
R=r, bradfitz CC=golang-dev
https://golang.org/cl/5574059
parent
c3b9650c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
6 deletions
+8
-6
parser.go
src/pkg/go/parser/parser.go
+1
-1
scanner.go
src/pkg/go/scanner/scanner.go
+6
-4
scanner_test.go
src/pkg/go/scanner/scanner_test.go
+1
-1
No files found.
src/pkg/go/parser/parser.go
View file @
8b60613b
...
...
@@ -54,7 +54,7 @@ type parser struct {
func
(
p
*
parser
)
init
(
fset
*
token
.
FileSet
,
filename
string
,
src
[]
byte
,
mode
Mode
)
{
p
.
file
=
fset
.
AddFile
(
filename
,
fset
.
Base
(),
len
(
src
))
var
m
uint
var
m
scanner
.
Mode
if
mode
&
ParseComments
!=
0
{
m
=
scanner
.
ScanComments
}
...
...
src/pkg/go/scanner/scanner.go
View file @
8b60613b
...
...
@@ -40,7 +40,7 @@ type Scanner struct {
dir
string
// directory portion of file.Name()
src
[]
byte
// source
err
ErrorHandler
// error reporting; or nil
mode
uint
// scanning mode
mode
Mode
// scanning mode
// scanning state
ch
rune
// current character
...
...
@@ -86,11 +86,13 @@ func (S *Scanner) next() {
}
}
//
The mode parameter to the Init function is a
set of flags (or 0).
//
A mode value is
set of flags (or 0).
// They control scanner behavior.
//
type
Mode
uint
const
(
ScanComments
=
1
<<
iota
// return comments as COMMENT tokens
ScanComments
Mode
=
1
<<
iota
// return comments as COMMENT tokens
dontInsertSemis
// do not automatically insert semicolons - for testing only
)
...
...
@@ -109,7 +111,7 @@ const (
// Note that Init may call err if there is an error in the first character
// of the file.
//
func
(
S
*
Scanner
)
Init
(
file
*
token
.
File
,
src
[]
byte
,
err
ErrorHandler
,
mode
uint
)
{
func
(
S
*
Scanner
)
Init
(
file
*
token
.
File
,
src
[]
byte
,
err
ErrorHandler
,
mode
Mode
)
{
// Explicitly initialize all fields since a scanner may be reused.
if
file
.
Size
()
!=
len
(
src
)
{
panic
(
"file size does not match src len"
)
...
...
src/pkg/go/scanner/scanner_test.go
View file @
8b60613b
...
...
@@ -281,7 +281,7 @@ func TestScan(t *testing.T) {
}
}
func
checkSemi
(
t
*
testing
.
T
,
line
string
,
mode
uint
)
{
func
checkSemi
(
t
*
testing
.
T
,
line
string
,
mode
Mode
)
{
var
S
Scanner
file
:=
fset
.
AddFile
(
"TestSemis"
,
fset
.
Base
(),
len
(
line
))
S
.
Init
(
file
,
[]
byte
(
line
),
nil
,
mode
)
...
...
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