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
8b60613b
Commit
8b60613b
authored
Jan 24, 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
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
7 deletions
+9
-7
src/pkg/go/parser/parser.go
src/pkg/go/parser/parser.go
+1
-1
src/pkg/go/scanner/scanner.go
src/pkg/go/scanner/scanner.go
+7
-5
src/pkg/go/scanner/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 {
...
@@ -54,7 +54,7 @@ type parser struct {
func
(
p
*
parser
)
init
(
fset
*
token
.
FileSet
,
filename
string
,
src
[]
byte
,
mode
Mode
)
{
func
(
p
*
parser
)
init
(
fset
*
token
.
FileSet
,
filename
string
,
src
[]
byte
,
mode
Mode
)
{
p
.
file
=
fset
.
AddFile
(
filename
,
fset
.
Base
(),
len
(
src
))
p
.
file
=
fset
.
AddFile
(
filename
,
fset
.
Base
(),
len
(
src
))
var
m
uint
var
m
scanner
.
Mode
if
mode
&
ParseComments
!=
0
{
if
mode
&
ParseComments
!=
0
{
m
=
scanner
.
ScanComments
m
=
scanner
.
ScanComments
}
}
...
...
src/pkg/go/scanner/scanner.go
View file @
8b60613b
...
@@ -40,7 +40,7 @@ type Scanner struct {
...
@@ -40,7 +40,7 @@ type Scanner struct {
dir
string
// directory portion of file.Name()
dir
string
// directory portion of file.Name()
src
[]
byte
// source
src
[]
byte
// source
err
ErrorHandler
// error reporting; or nil
err
ErrorHandler
// error reporting; or nil
mode
uint
// scanning mode
mode
Mode
// scanning mode
// scanning state
// scanning state
ch
rune
// current character
ch
rune
// current character
...
@@ -86,11 +86,13 @@ func (S *Scanner) next() {
...
@@ -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.
// They control scanner behavior.
//
//
type
Mode
uint
const
(
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
dontInsertSemis
// do not automatically insert semicolons - for testing only
)
)
...
@@ -109,7 +111,7 @@ const (
...
@@ -109,7 +111,7 @@ const (
// Note that Init may call err if there is an error in the first character
// Note that Init may call err if there is an error in the first character
// of the file.
// 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.
// Explicitly initialize all fields since a scanner may be reused.
if
file
.
Size
()
!=
len
(
src
)
{
if
file
.
Size
()
!=
len
(
src
)
{
panic
(
"file size does not match src len"
)
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) {
...
@@ -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
var
S
Scanner
file
:=
fset
.
AddFile
(
"TestSemis"
,
fset
.
Base
(),
len
(
line
))
file
:=
fset
.
AddFile
(
"TestSemis"
,
fset
.
Base
(),
len
(
line
))
S
.
Init
(
file
,
[]
byte
(
line
),
nil
,
mode
)
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