forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.go
65 lines (59 loc) · 1.24 KB
/
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
61
62
63
64
65
package wavefront
import (
"bufio"
"io"
)
// Lexical Point Scanner
type PointScanner struct {
r *bufio.Reader
}
func NewScanner(r io.Reader) *PointScanner {
return &PointScanner{r: bufio.NewReader(r)}
}
// read reads the next rune from the buffered reader.
// Returns rune(0) if an error occurs (or io.EOF is returned).
func (s *PointScanner) read() rune {
ch, _, err := s.r.ReadRune()
if err != nil {
return eof
}
return ch
}
// Scan returns the next token and literal value.
func (s *PointScanner) Scan() (Token, string) {
// Read the next rune
ch := s.read()
if isWhitespace(ch) {
return Ws, string(ch)
} else if isLetter(ch) {
return Letter, string(ch)
} else if isNumber(ch) {
return Number, string(ch)
} else if isDelta(ch) {
return Delta, string(ch)
}
// Otherwise read the individual character.
switch ch {
case eof:
return EOF, ""
case '\n':
return Newline, string(ch)
case '.':
return Dot, string(ch)
case '-':
return MinusSign, string(ch)
case '_':
return Underscore, string(ch)
case '/':
return Slash, string(ch)
case '\\':
return Backslash, string(ch)
case ',':
return Comma, string(ch)
case '"':
return Quotes, string(ch)
case '=':
return Equals, string(ch)
}
return Illegal, string(ch)
}