Commit e7524d51 authored by Robert Griesemer's avatar Robert Griesemer

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: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 0784e691
......@@ -373,14 +373,6 @@ type Sig struct {
offset int32
}
type Io struct {
bin *obj.Biobuf
last int
peekc int
peekc1 int // second peekc for ...
eofnl bool
}
type Dlist struct {
field *Type
}
......@@ -431,8 +423,6 @@ var sizeof_String int // runtime sizeof(String)
var dotlist [10]Dlist // size is max depth of embeddeds
var curio Io
var lexlineno int32
var lineno int32
......
This diff is collapsed.
......@@ -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()
......
......@@ -116,12 +116,6 @@ func Yyerror(format string, args ...interface{}) {
if strings.HasPrefix(msg, "syntax error") {
nsyntaxerrors++
// An unexpected EOF caused a syntax error. Use the previous
// line number since getc generated a fake newline character.
if curio.eofnl {
lexlineno = prevlineno
}
// only one syntax error per line
if int32(yyerror_lastsyntax) == lexlineno {
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment