forked from pingcap/parser
-
Notifications
You must be signed in to change notification settings - Fork 2
/
scanner_extension .go
68 lines (56 loc) · 1.25 KB
/
scanner_extension .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
66
67
68
package parser
// 这个Reset方法在原有reset()方法上增加了将最后扫描的偏移量置零
func (s *Scanner) Reset(sql string) {
s.reset(sql)
s.lastScanOffset = 0
}
// 该方法返回Scanner最后扫描到的位置
func (s *Scanner) Offset() int {
return s.lastScanOffset
}
// 该方法修改Scanner最后扫描到的位置
func (s *Scanner) SetCursor(offset int) {
s.lastScanOffset = offset
}
const (
Identifier int = identifier
YyEOFCode int = yyEOFCode
YyDefault int = yyDefault
IfKwd int = ifKwd
CaseKwd int = caseKwd
Repeat int = repeat
Begin int = begin
End int = end
StringLit int = stringLit
Invalid int = invalid
)
type TokenValue yySymType
type Token struct {
tokenType int
tokenValue *yySymType
}
func (t Token) Ident() string {
return t.tokenValue.ident
}
func (t Token) TokenType() int {
return t.tokenType
}
func (s *Scanner) NextToken() *Token {
tokenValue := &yySymType{}
tokenType := s.Lex(tokenValue)
return &Token{
tokenType: tokenType,
tokenValue: tokenValue,
}
}
func (s *Scanner) ScannedLines() int {
return s.r.pos().Line - 1
}
func (s *Scanner) Text() string {
return s.r.s
}
func (s *Scanner) HandleInvalid() {
if s.lastScanOffset == s.r.p.Offset {
s.r.inc()
}
}