-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtoken.go
65 lines (51 loc) · 1.18 KB
/
token.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 bibtex
import (
"fmt"
"strings"
)
// Lexer token.
type token int
const (
// tILLEGAL stands for an invalid token.
tILLEGAL token = iota
)
var eof = rune(0)
// tokenPos is a pair of coordinate to identify start of token.
type tokenPos struct {
Char int
Lines []int
}
func (p tokenPos) String() string {
return fmt.Sprintf("%d:%d", len(p.Lines)+1, p.Char)
}
func isWhitespace(ch rune) bool {
return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'
}
func isAccent(ch rune) bool {
accents := "äöüßéêçñÁÉÍÓÚáéíóúàèìòùâêîôûãõñÄÖÜ"
for _, accent := range accents {
if ch == accent {
return true
}
}
return false
}
func isAlpha(ch rune) bool {
return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || isAccent(ch)
}
func isDigit(ch rune) bool {
return ('0' <= ch && ch <= '9')
}
func isAlphanum(ch rune) bool {
return isAlpha(ch) || isDigit(ch)
}
func isBareSymbol(ch rune) bool {
return strings.ContainsRune("-_:./+", ch)
}
// isSymbol returns true if ch is a valid symbol
func isSymbol(ch rune) bool {
return strings.ContainsRune("!?&*+-./:;<>[]^_`|~@", ch)
}
func isOpenQuote(ch rune) bool {
return ch == '{' || ch == '"'
}