...
1
2
3
4
5 package lex
6
7 import (
8 "text/scanner"
9
10 "cmd/internal/src"
11 )
12
13
14 type Slice struct {
15 tokens []Token
16 base *src.PosBase
17 line int
18 pos int
19 }
20
21 func NewSlice(base *src.PosBase, line int, tokens []Token) *Slice {
22 return &Slice{
23 tokens: tokens,
24 base: base,
25 line: line,
26 pos: -1,
27 }
28 }
29
30 func (s *Slice) Next() ScanToken {
31 s.pos++
32 if s.pos >= len(s.tokens) {
33 return scanner.EOF
34 }
35 return s.tokens[s.pos].ScanToken
36 }
37
38 func (s *Slice) Text() string {
39 return s.tokens[s.pos].text
40 }
41
42 func (s *Slice) File() string {
43 return s.base.Filename()
44 }
45
46 func (s *Slice) Base() *src.PosBase {
47 return s.base
48 }
49
50 func (s *Slice) SetBase(base *src.PosBase) {
51
52
53 s.base = base
54 }
55
56 func (s *Slice) Line() int {
57 return s.line
58 }
59
60 func (s *Slice) Col() int {
61
62
63
64
65
66
67
68
69
70 return s.pos
71 }
72
73 func (s *Slice) Close() {
74 }
75
View as plain text