1
2
3
4
5 package lex
6
7 import (
8 "text/scanner"
9
10 "cmd/internal/src"
11 )
12
13
14
15 type Stack struct {
16 tr []TokenReader
17 }
18
19
20 func (s *Stack) Push(tr TokenReader) {
21 s.tr = append(s.tr, tr)
22 }
23
24 func (s *Stack) Next() ScanToken {
25 tos := s.tr[len(s.tr)-1]
26 tok := tos.Next()
27 for tok == scanner.EOF && len(s.tr) > 1 {
28 tos.Close()
29
30 s.tr = s.tr[:len(s.tr)-1]
31 tok = s.Next()
32 }
33 return tok
34 }
35
36 func (s *Stack) Text() string {
37 return s.tr[len(s.tr)-1].Text()
38 }
39
40 func (s *Stack) File() string {
41 return s.Base().Filename()
42 }
43
44 func (s *Stack) Base() *src.PosBase {
45 return s.tr[len(s.tr)-1].Base()
46 }
47
48 func (s *Stack) SetBase(base *src.PosBase) {
49 s.tr[len(s.tr)-1].SetBase(base)
50 }
51
52 func (s *Stack) Line() int {
53 return s.tr[len(s.tr)-1].Line()
54 }
55
56 func (s *Stack) Col() int {
57 return s.tr[len(s.tr)-1].Col()
58 }
59
60 func (s *Stack) Close() {
61 }
62
View as plain text