diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-09-11 05:46:30 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-09-11 05:46:30 +0200 |
commit | 06995c35d0479a3f1806b2d8057979a563733390 (patch) | |
tree | 6822642bddd63365439fc94c3d22c162d51bac8e /parser | |
parent | 8059760d51cd1f8b5aae0f150c349f3ef687927e (diff) |
Minor refactoring
Diffstat (limited to 'parser')
-rw-r--r-- | parser/reader.go | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/parser/reader.go b/parser/reader.go index f947cfb..d77d1f5 100644 --- a/parser/reader.go +++ b/parser/reader.go @@ -23,9 +23,8 @@ type reader struct { pos position } -func (reader *reader) peekRune() (rune, error) { +func (reader *reader) peekRune() (r rune, err error) { bytes := make([]byte, 0, 4) - var err error // Peeking the next rune is annoying. We want to get the next rune // which could be the next 1–4 bytes. Normally we can just call @@ -35,10 +34,10 @@ func (reader *reader) peekRune() (rune, error) { if bytes, err = reader.r.Peek(i); err == io.EOF { continue } else if err != nil { - return 0, err + return } else { - rune, _ := utf8.DecodeRune(bytes) - return rune, nil + r, _ = utf8.DecodeRune(bytes) + return } } @@ -57,15 +56,15 @@ func (reader *reader) unreadRune() error { } func (reader *reader) readRune() (rune, error) { - rune, _, err := reader.r.ReadRune() - if rune == '\n' { + r, _, err := reader.r.ReadRune() + if r == '\n' { reader.pos.prevCol = reader.pos.col reader.pos.col = 0 reader.pos.row++ } else { reader.pos.col++ } - return rune, err + return r, err } func (reader *reader) readNonSpaceRune() (rune, error) { @@ -73,21 +72,17 @@ func (reader *reader) readNonSpaceRune() (rune, error) { return 0, err } - if r, err := reader.readRune(); err != nil { - return 0, err - } else { - return r, nil - } + return reader.readRune() } func (reader *reader) skipSpaces() error { for { - if rune, err := reader.readRune(); err != nil { + if r, err := reader.readRune(); err != nil { if err == io.EOF { return nil } return err - } else if !unicode.IsSpace(rune) { + } else if !unicode.IsSpace(r) { return reader.unreadRune() } } |