-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
50 lines (39 loc) · 828 Bytes
/
helpers.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
package main
import (
"strings"
)
func isNumeric(r rune) bool {
digits := "+-0987654321"
return strings.IndexRune(digits, r) >= 0
}
func isAlphaNumeric(r rune) bool {
digits := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
return strings.IndexRune(digits, r) >= 0
}
func matchExact(valid string, l *lexer) bool {
if len(valid) > len(l.input[l.pos:]) {
return false
}
backupCount := 0
idx := 0
for ; idx < len(valid); idx++ {
backupCount++
if strings.IndexRune(valid[idx:idx+1], l.next()) == -1 {
break
}
}
// backup
for ; backupCount > 0; backupCount-- {
l.backup()
}
return idx == len(valid)
}
func isTrue(l *lexer) bool {
return matchExact("true", l)
}
func isFalse(l *lexer) bool {
return matchExact("false", l)
}
func isNull(l *lexer) bool {
return matchExact("null", l)
}