type parser struct {
scanner scanner.Scanner;
err ErrorHandler; // nil if no handler installed
- errorCount int;
+ hasErrors bool;
// Tracing/debugging
mode uint; // parsing mode
if p.err != nil {
p.err.Error(pos, msg);
}
- p.errorCount++;
+ p.hasErrors = true;
}
if typ == nil {
p.error_expected(p.pos, "type");
+ p.next(); // make progress
return &ast.BadExpr{p.pos};
}
typ := p.tryParameterType(ellipsis_ok);
if typ == nil {
p.error_expected(p.pos, "type");
+ p.next(); // make progress
typ = &ast.BadExpr{p.pos};
}
return typ;
// no statement found
p.error_expected(p.pos, "statement");
+ p.next(); // make progress
return &ast.BadStmt{p.pos};
}
comment := p.getDoc();
pos := p.expect(token.PACKAGE);
ident := p.parseIdent();
- if p.tok == token.SEMICOLON {
- // common error
- p.error(p.pos, "extra semicolon");
- p.next();
- }
-
var decls []ast.Decl;
- if p.mode & PackageClauseOnly == 0 {
+
+ // Don't bother parsing the rest if we had errors already.
+ // Likely not a Go source file at all.
+
+ if !p.hasErrors && p.mode & PackageClauseOnly == 0 {
// import decls
list := vector.New(0);
for p.tok == token.IMPORT {
// parse program
prog := p.parsePackage();
- return prog, p.scanner.ErrorCount == 0 && p.errorCount == 0;
+ return prog, p.scanner.ErrorCount == 0 && !p.hasErrors;
}