1// Copyright 2015 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.45package lex67import (8 "text/scanner"910 "cmd/internal/src"11)1213// A Slice reads from a slice of Tokens.14type Slice struct {15 tokens []Token16 base *src.PosBase17 line int18 pos int19}2021func NewSlice(base *src.PosBase, line int, tokens []Token) *Slice {22 return &Slice{23 tokens: tokens,24 base: base,25 line: line,26 pos: -1, // Next will advance to zero.27 }28}2930func (s *Slice) Next() ScanToken {31 s.pos++32 if s.pos >= len(s.tokens) {33 return scanner.EOF34 }35 return s.tokens[s.pos].ScanToken36}3738func (s *Slice) Text() string {39 return s.tokens[s.pos].text40}4142func (s *Slice) File() string {43 return s.base.Filename()44}4546func (s *Slice) Base() *src.PosBase {47 return s.base48}4950func (s *Slice) SetBase(base *src.PosBase) {51 // Cannot happen because we only have slices of already-scanned text,52 // but be prepared.53 s.base = base54}5556func (s *Slice) Line() int {57 return s.line58}5960func (s *Slice) Col() int {61 // TODO: Col is only called when defining a macro and all it cares about is increasing62 // position to discover whether there is a blank before the parenthesis.63 // We only get here if defining a macro inside a macro.64 // This imperfect implementation means we cannot tell the difference between65 // #define A #define B(x) x66 // and67 // #define A #define B (x) x68 // The first definition of B has an argument, the second doesn't. Because we let69 // text/scanner strip the blanks for us, this is extremely rare, hard to fix, and not worth it.70 return s.pos71}7273func (s *Slice) Close() {74}
Findings
✓ No findings reported for this file.