From e6cda92d15701ccca5734644b51eedec9e6d2f33 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 1 Jun 2009 19:12:10 -0700 Subject: - enable scanner to handle illegal chars w/o returning an error so that it can be used for non-Go chars - adjust parser accordingly R=rsc DELTA=58 (42 added, 2 deleted, 14 changed) OCL=29688 CL=29703 --- src/lib/go/parser/parser.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/lib/go/parser/parser.go') diff --git a/src/lib/go/parser/parser.go b/src/lib/go/parser/parser.go index 37fd431ed..622268d1e 100644 --- a/src/lib/go/parser/parser.go +++ b/src/lib/go/parser/parser.go @@ -1921,6 +1921,15 @@ func readSource(src interface{}) ([]byte, os.Error) { } +// scannerMode returns the scanner mode bits given the parser's mode bits. +func scannerMode(mode uint) uint { + if mode & ParseComments != 0 { + return scanner.ScanComments; + } + return 0; +} + + // Parse parses a Go program. // // The program source src may be provided in a variety of formats. At the @@ -1944,7 +1953,7 @@ func Parse(src interface{}, mode uint) (*ast.Program, os.Error) { // initialize parser state var p parser; p.errors.Init(0); - p.scanner.Init(data, &p, mode & ParseComments != 0); + p.scanner.Init(data, &p, scannerMode(mode)); p.mode = mode; p.trace = mode & Trace != 0; // for convenience (p.trace is used frequently) p.comments.Init(0); -- cgit v1.2.3