~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/text/scanner/scanner.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
// Package scanner provides a scanner and tokenizer for UTF-8-encoded text.
6
6
// It takes an io.Reader providing the source, which then can be tokenized
7
7
// through repeated calls to the Scan function.  For compatibility with
8
 
// existing tools, the NUL character is not allowed.
 
8
// existing tools, the NUL character is not allowed. If the first character
 
9
// in the source is a UTF-8 encoded byte order mark (BOM), it is discarded.
9
10
//
10
11
// By default, a Scanner skips white space and Go comments and recognizes all
11
12
// literals as defined by the Go language specification.  It may be
208
209
        return s
209
210
}
210
211
 
211
 
// TODO(gri): The code for next() and the internal scanner state could benefit
212
 
//            from a rethink. While next() is optimized for the common ASCII
213
 
//            case, the "corrections" needed for proper position tracking undo
214
 
//            some of the attempts for fast-path optimization.
215
 
 
216
212
// next reads and returns the next Unicode character. It is designed such
217
213
// that only a minimal amount of work needs to be done in the common ASCII
218
214
// case (one test to check for both ASCII and end-of-buffer, and one test
316
312
// character of the source.
317
313
func (s *Scanner) Peek() rune {
318
314
        if s.ch < 0 {
 
315
                // this code is only run for the very first character
319
316
                s.ch = s.next()
 
317
                if s.ch == '\uFEFF' {
 
318
                        s.ch = s.next() // ignore BOM
 
319
                }
320
320
        }
321
321
        return s.ch
322
322
}
389
389
                if ch == 'x' || ch == 'X' {
390
390
                        // hexadecimal int
391
391
                        ch = s.next()
 
392
                        hasMantissa := false
392
393
                        for digitVal(ch) < 16 {
393
394
                                ch = s.next()
 
395
                                hasMantissa = true
 
396
                        }
 
397
                        if !hasMantissa {
 
398
                                s.error("illegal hexadecimal number")
394
399
                        }
395
400
                } else {
396
401
                        // octal int or float
397
 
                        seenDecimalDigit := false
 
402
                        has8or9 := false
398
403
                        for isDecimal(ch) {
399
404
                                if ch > '7' {
400
 
                                        seenDecimalDigit = true
 
405
                                        has8or9 = true
401
406
                                }
402
407
                                ch = s.next()
403
408
                        }
408
413
                                return Float, ch
409
414
                        }
410
415
                        // octal int
411
 
                        if seenDecimalDigit {
 
416
                        if has8or9 {
412
417
                                s.error("illegal octal number")
413
418
                        }
414
419
                }