1
0
mirror of https://github.com/golang/go synced 2024-11-12 08:40:21 -07:00
go/usr/gri/src/test_scanner.go
Robert Griesemer 65269ccd3d - more work on Go scanner
SVN=126004
2008-07-03 18:07:03 -07:00

39 lines
770 B
Go

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import Scanner "scanner"
func Scan(src string) {
S := new(Scanner.Scanner);
S.Open(src);
for {
var t Scanner.Token;
var tok, beg, end int;
tok, beg, end = S.Scan(&t);
//t.Print(); // TODO this doesn't compile?
print Scanner.TokenName(tok), "\t ", src[beg : end], "\n";
if tok == Scanner.EOF {
return;
}
}
}
func main() {
for i := 1; i < sys.argc(); i++ {
var src string;
var ok bool;
src, ok = sys.readfile(sys.argv(i));
if ok {
print "scanning " + sys.argv(i) + "\n";
Scan(src);
} else {
print "error: cannot read " + sys.argv(i) + "\n";
}
}
}