// scan returns the next token from the underlying scanner.
// If a token has been unscanned then read that instead.
scan returns the next token from the underlying scanner.
If a token has been unscanned then read that instead.
// scan returns the next token from the underlying scanner . // If a token has been unscanned then read that instead .
func (p *Parser) Scan() (tok Token, lit string, pos ParserPosition) {
	if p.buf.n != 0 {
		p.buf.n = 0
		p.forwardPos(p.buf.tok, p.buf.lit)
		if TokenLog {
			log.Println("Re-read", DescribeToklit(p.buf.tok, p.buf.lit), "after", p.buf.pos)
		}
		return p.buf.tok, p.buf.lit, p.buf.pos
	}
	pos = p.Pos()
	tok, lit = p.s.scan()
	p.forwardPos(tok, lit)
	p.buf.tok, p.buf.lit = tok, lit
	p.buf.pos = pos
	if tok == B1 {
		p.pBal++
	} else if tok == B2 {
		p.pBal--
	}
	if TokenLog {
		pos := p.Pos()
		log.Printf("scan reached %v %v {%d}.\n", pos.String(), pos.ShortenedLineheadMsg(), p.pBal)
	}
	return
}
func ( p * Parser ) Scan ( ) ( tok Token , lit string , pos ParserPosition ) { if p . buf . n != 0 { p . buf . n = 0 p . forwardPos ( p . buf . tok , p . buf . lit ) if TokenLog { log . Println ( " " , DescribeToklit ( p . buf . tok , p . buf . lit ) , " " , p . buf . pos ) } return p . buf . tok , p . buf . lit , p . buf . pos } pos = p . Pos ( ) tok , lit = p . s . scan ( ) p . forwardPos ( tok , lit ) p . buf . tok , p . buf . lit = tok , lit p . buf . pos = pos if tok == B1 { p . pBal ++ } else if tok == B2 { p . pBal -- } if TokenLog { pos := p . Pos ( ) log . Printf ( " \n " , pos . String ( ) , pos . ShortenedLineheadMsg ( ) , p . pBal ) } return }
scan returns the next token from the underlying scanner.
scan returns the next token from the underlying scanner .
// If we have a token on the buffer, then return it. // pos is what we return and buffer. It is where we are before(!) reading the next literal. // read the next token from the scanner. // Save it to the buffer in case we unscan later.