-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
63 lines (53 loc) · 932 Bytes
/
utils.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
package gqlyzer
import (
"errors"
)
func isNumber(c rune) bool {
if c >= '0' && c <= '9' {
return true
}
return false
}
func isAlphabet(c rune) bool {
if (c >= 'a' && c <= 'z') ||
(c >= 'A' && c < 'Z') {
return true
}
return false
}
func isWhitespace(c rune) bool {
switch c {
case '\n', '\t', ' ':
return true
default:
return false
}
}
func (l *Lexer) isEOF() bool {
return l.cursor >= len(l.input)
}
func (l *Lexer) read() (c rune, err error) {
if l.isEOF() {
err = errors.New("end of file")
} else {
c = rune(l.input[l.cursor])
}
return
}
func (l *Lexer) consumeWhitespace() {
c, err := l.read()
for err == nil && isWhitespace(c) {
if c == '\n' {
l.push('\\')
}
l.cursor++
c, err = l.read()
}
}
// commented out since no usage, needed in development
//func (l *Lexer) printParseStack() {
// for _, c := range l.parseStack {
// fmt.Print(string(c))
// }
// fmt.Println()
//}