-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscanner.go
60 lines (48 loc) · 803 Bytes
/
scanner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package sfv
type scanner struct {
s string
i int
}
func (s *scanner) isEOF() bool {
return s.i == len(s.s)
}
func (s *scanner) peek() (byte, error) {
if s.i == len(s.s) {
return 0, s.parseError("unexpected end of SFV input")
}
return s.s[s.i], nil
}
func (s *scanner) next() (byte, error) {
b, err := s.peek()
if err != nil {
return 0, err
}
s.i++
return b, nil
}
func (s *scanner) mustNext() {
if _, err := s.next(); err != nil {
panic(err)
}
}
func (s *scanner) skipSP() {
for {
b, err := s.peek()
if err != nil || b != ' ' {
break
}
s.next()
}
}
func (s *scanner) skipOWS() {
for {
b, err := s.peek()
if err != nil || !isOWS(b) {
break
}
s.next()
}
}
func (s scanner) parseError(msg string) error {
return ParseError{Offset: s.i, msg: msg}
}