From ae04e842f5949881b76cce3d5082f5027d047453 Mon Sep 17 00:00:00 2001 From: Jan Mercl <jan.mercl@nic.cz> Date: Wed, 9 Nov 2011 14:32:38 +0100 Subject: [PATCH] Adjust for weekly.2011-11-09 --- all_test.go | 2 +- lexer.go | 6 +++--- regex.go | 8 ++++---- source.go | 9 ++++----- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/all_test.go b/all_test.go index cf81364..f5505ef 100644 --- a/all_test.go +++ b/all_test.go @@ -226,7 +226,7 @@ func BenchmarkNFA(b *testing.B) { var v visitor for i := 0; i < b.N; i++ { v = visitor{s: lex.Scanner("test-go-scanner", nil)} - filepath.Walk(runtime.GOROOT()+"/src", func(pth string, info *os.FileInfo, err os.Error) os.Error { + filepath.Walk(runtime.GOROOT()+"/src", func(pth string, info *os.FileInfo, err error) error { if err != nil { panic(err) } diff --git a/lexer.go b/lexer.go index d9332fe..f7a8d70 100644 --- a/lexer.go +++ b/lexer.go @@ -213,13 +213,13 @@ type Lexer struct { type StartSetID int //TODO:full docs -func CompileLexer(starts [][]int, tokdefs map[string]int, grammar, start string) (lexer *Lexer, err os.Error) { +func CompileLexer(starts [][]int, tokdefs map[string]int, grammar, start string) (lexer *Lexer, err error) { lexer = &Lexer{} defer func() { if e := recover(); e != nil { lexer = nil - err = e.(os.Error) + err = e.(error) } }() @@ -303,7 +303,7 @@ func CompileLexer(starts [][]int, tokdefs map[string]int, grammar, start string) // MustCompileLexer is like CompileLexer but panics if the definitions cannot be compiled. // It simplifies safe initialization of global variables holding compiled Lexers. func MustCompileLexer(starts [][]int, tokdefs map[string]int, grammar, start string) (lexer *Lexer) { - var err os.Error + var err error if lexer, err = CompileLexer(starts, tokdefs, grammar, start); err != nil { if list, ok := err.(scanner.ErrorList); ok { scanner.PrintError(os.Stderr, list) diff --git a/regex.go b/regex.go index e7146f2..ee74a12 100644 --- a/regex.go +++ b/regex.go @@ -10,8 +10,8 @@ package lexer import ( + "errors" "fmt" - "os" "strings" "unicode" ) @@ -23,14 +23,14 @@ func qs(s string) string { // ParseRE compiles a regular expression re into Nfa, returns the re component starting // and accepting states or an Error if any. -func (n *Nfa) ParseRE(name, re string) (in, out *NfaState, err os.Error) { +func (n *Nfa) ParseRE(name, re string) (in, out *NfaState, err error) { s := NewScannerSource(name, strings.NewReader(re)) defer func() { if e := recover(); e != nil { in, out = nil, nil pos := s.CurrentRune().Position - err = fmt.Errorf(`%s - "%s^%s" - %s`, pos, qs(re[:pos.Offset]), qs(re[pos.Offset:]), e.(os.Error)) + err = fmt.Errorf(`%s - "%s^%s" - %s`, pos, qs(re[:pos.Offset]), qs(re[pos.Offset:]), e.(error)) } }() @@ -245,7 +245,7 @@ func (s *ScannerSource) hex() (v int) { return v - 'A' + 10 } - panic(os.NewError("expected hex digit")) + panic(errors.New("expected hex digit")) } func (s *ScannerSource) expect(rune int) { diff --git a/source.go b/source.go index 0f375ab..42b161e 100644 --- a/source.go +++ b/source.go @@ -12,14 +12,13 @@ package lexer import ( "go/token" "io" - "os" ) // EOFReader implements a RuneReader allways returning 0 (EOF) type EOFReader int -func (r EOFReader) ReadRune() (rune int, size int, err os.Error) { - return 0, 0, os.EOF +func (r EOFReader) ReadRune() (rune int, size int, err error) { + return 0, 0, io.EOF } type source struct { @@ -69,7 +68,7 @@ func (s *Source) Read() (r ScannerRune) { for { r.Position = s.Position() r.Rune, r.Size, r.Err = s.tos.reader.ReadRune() - if r.Err == nil || r.Err != os.EOF { + if r.Err == nil || r.Err != io.EOF { p := &s.tos.position p.Offset += r.Size if r.Rune != '\n' { @@ -98,7 +97,7 @@ type ScannerRune struct { Position token.Position // Starting position of Rune Rune int // Rune value Size int // Rune size - Err os.Error // os.EOF or nil. Any other value invalidates all other fields of a ScannerRune. + Err error // os.EOF or nil. Any other value invalidates all other fields of a ScannerRune. } // ScannerSource is a Source with one ScannerRune look behind and an on demand one ScannerRune lookahead. -- GitLab