mirror of
https://github.com/golang/go
synced 2024-11-25 18:07:57 -07:00
go/scanner: Use explicit scanner.Mode type.
R=r, bradfitz CC=golang-dev https://golang.org/cl/5574059
This commit is contained in:
parent
c3b9650caa
commit
8b60613b92
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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,12 +86,14 @@ 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
|
||||||
)
|
)
|
||||||
|
|
||||||
// Init prepares the scanner S to tokenize the text src by setting the
|
// Init prepares the scanner S to tokenize the text src by setting the
|
||||||
@ -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")
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user