]> Cypherpunks repositories - gostls13.git/commitdiff
go/scanner: Use explicit scanner.Mode type.
authorRobert Griesemer <gri@golang.org>
Wed, 25 Jan 2012 00:49:03 +0000 (16:49 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 25 Jan 2012 00:49:03 +0000 (16:49 -0800)
R=r, bradfitz
CC=golang-dev
https://golang.org/cl/5574059

src/pkg/go/parser/parser.go
src/pkg/go/scanner/scanner.go
src/pkg/go/scanner/scanner_test.go

index ab8953f4fbf60fe98374c84a3accf5bc6076d87c..6bee8de9f65e04fc3a95ca9be548d3f6a4cd0502 100644 (file)
@@ -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
        }
index 05665b25487e58d5385a522b50f54d43848749ed..7c72c0a46b922372165aa1b1f47185962d95ac14 100644 (file)
@@ -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,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.
 //
+type Mode uint
+
 const (
-       ScanComments    = 1 << iota // return comments as COMMENT tokens
-       dontInsertSemis             // do not automatically insert semicolons - for testing only
+       ScanComments    Mode = 1 << iota // return comments as COMMENT tokens
+       dontInsertSemis                  // do not automatically insert semicolons - for testing only
 )
 
 // 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
 // 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")
index 2e4dd4fff638860b79aaf2a1e8a86930a014060f..af45bc5b1c8af8788a4275c07a97def3fd573867 100644 (file)
@@ -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)