cmd/compile: move Io state into lexer and remove Io type

Pass lexer around so state is accessible and dependency is explicit.
In the process remove EOF -> '\n' conversion that has to be corrected
for when reporting errors.

Change-Id: If95564b70e7484dedc1f5348e585cd19acbc1243
Reviewed-on: https://go-review.googlesource.com/19819
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2016-02-22 11:53:20 -08:00
parent 0784e6918e
commit e7524d51fd
4 changed files with 119 additions and 141 deletions

View file

@ -21,24 +21,14 @@ import (
const trace = false // if set, parse tracing can be enabled with -x
// parse_import parses the export data of a package that is imported.
func parse_import(bin *obj.Biobuf, indent []byte) {
pushedio := curio
curio = Io{bin: bin}
importparser := parser{indent: indent} // preserve indentation
importparser.next()
importparser.import_package()
curio = pushedio
newparser(bin, indent).import_package()
}
// parse_file sets up a new parser and parses a single Go source file.
// parse_file parses a single Go source file.
func parse_file(bin *obj.Biobuf) {
curio = Io{bin: bin}
fileparser := parser{}
fileparser.next()
fileparser.file()
newparser(bin, nil).file()
}
type parser struct {
@ -48,6 +38,16 @@ type parser struct {
indent []byte // tracing support
}
// newparser returns a new parser ready to parse from src.
// indent is the initial indentation for tracing output.
func newparser(src *obj.Biobuf, indent []byte) *parser {
var p parser
p.bin = src
p.indent = indent
p.next()
return &p
}
func (p *parser) got(tok int32) bool {
if p.tok == tok {
p.next()