Hello,

Perhaps I am misunderstanding the purpose or do not know how to optimally 
use this package, but the way I see it scanner.peek() is not doing what I 
expect it to do: return the next non-whitespace token (e.g., scanner.Ident, 
scanner.Int etc) without advancing the scanner. Instead it returns whatever 
is the next rune in the stream (which could be a space or any other char). 
So, as far as I could tell, there is no easy way to lookahead and switch 
the call to scanner.Scan on the kind of the next token. This complicates 
writing generic syntax checking functions like:

    //TODO: handle error better

    accept := func(wantedTok rune, wantedText string) {

        tok = s.Scan()

        log.Printf("%s: %d %s\n", s.Pos(), tok, s.TokenText())

        if tok != wantedTok {

            log.Fatalf("Syntax error at position %s. Expected %d. Found %d", 
s.Pos(), wantedTok, tok)

        }

        if wantedText != "" && wantedText != s.TokenText() { //case-sensitive?

            log.Fatalf("Syntax error at position %s. Expected %s. Found %s", 
s.Pos(), wantedText, s.TokenText())

        }

    }


Should not scanner.Peek do whatever scanner.Scan does just without 
advancing the scanner?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to