summaryrefslogtreecommitdiff
path: root/usr/gri/pretty/parser.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-03-02 20:27:09 -0800
committerRobert Griesemer <gri@golang.org>2009-03-02 20:27:09 -0800
commit283668dc71ce1ed7e40112b07953b3abdcf69d23 (patch)
tree9a4be091b0dcbe319409d1b32981628a308f0020 /usr/gri/pretty/parser.go
parent97a5240489037e952b8a1bd220e50e988ca50b54 (diff)
downloadgolang-283668dc71ce1ed7e40112b07953b3abdcf69d23.tar.gz
scanner cleanup - getting it ready to as a library
- removed unneeded code that accumulated over time - change src from string to []byte (perhaps should be io.Read but that has some other disadvantages) - simplified interface R=r OCL=25615 CL=25615
Diffstat (limited to 'usr/gri/pretty/parser.go')
-rw-r--r--usr/gri/pretty/parser.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/usr/gri/pretty/parser.go b/usr/gri/pretty/parser.go
index 0eced7fdb..218324354 100644
--- a/usr/gri/pretty/parser.go
+++ b/usr/gri/pretty/parser.go
@@ -14,13 +14,20 @@ import (
)
+type ErrorHandler interface {
+ Error(pos int, msg string);
+ Warning(pos int, msg string);
+}
+
+
type Parser struct {
+ scanner *Scanner.Scanner;
+ err ErrorHandler;
+
// Tracing/debugging
trace, sixg, deps bool;
indent uint;
- // Scanner
- scanner *Scanner.Scanner;
comments *vector.Vector;
// Scanner.Token
@@ -90,7 +97,10 @@ func un/*trace*/(P *Parser) {
func (P *Parser) next0() {
- P.pos, P.tok, P.val = P.scanner.Scan();
+ // TODO make P.val a []byte
+ var val []byte;
+ P.pos, P.tok, val = P.scanner.Scan();
+ P.val = string(val);
P.opt_semi = false;
if P.trace {
@@ -118,13 +128,15 @@ func (P *Parser) next() {
}
-func (P *Parser) Open(trace, sixg, deps bool, scanner *Scanner.Scanner) {
+func (P *Parser) Open(scanner *Scanner.Scanner, err ErrorHandler, trace, sixg, deps bool) {
+ P.scanner = scanner;
+ P.err = err;
+
P.trace = trace;
P.sixg = sixg;
P.deps = deps;
P.indent = 0;
- P.scanner = scanner;
P.comments = vector.New(0);
P.next();
@@ -133,7 +145,7 @@ func (P *Parser) Open(trace, sixg, deps bool, scanner *Scanner.Scanner) {
func (P *Parser) error(pos int, msg string) {
- P.scanner.Error(pos, msg);
+ P.err.Error(pos, msg);
}