Commit 59ee0373 authored by Robert Griesemer's avatar Robert Griesemer

- removed TODO, minor adjustments

R=rsc
DELTA=16  (6 added, 1 deleted, 9 changed)
OCL=31638
CL=31641
parent f752e909
...@@ -169,10 +169,13 @@ func parse(path string, mode uint) (*ast.Program, *parseErrors) { ...@@ -169,10 +169,13 @@ func parse(path string, mode uint) (*ast.Program, *parseErrors) {
prog, err := parser.Parse(path, src, mode); prog, err := parser.Parse(path, src, mode);
if err != nil { if err != nil {
// sort and convert error list var errs []parseError;
if errors, ok := err.(scanner.ErrorList); ok { if errors, ok := err.(scanner.ErrorList); ok {
sort.Sort(errors); // convert error list (already sorted)
errs := make([]parseError, len(errors) + 1); // +1 for final fragment of source // TODO(gri) If the file contains //line comments, the errors
// may not be sorted in increasing file offset value
// which will lead to incorrect output.
errs = make([]parseError, len(errors) + 1); // +1 for final fragment of source
offs := 0; offs := 0;
for i, r := range errors { for i, r := range errors {
// Should always be true, but check for robustness. // Should always be true, but check for robustness.
...@@ -184,11 +187,13 @@ func parse(path string, mode uint) (*ast.Program, *parseErrors) { ...@@ -184,11 +187,13 @@ func parse(path string, mode uint) (*ast.Program, *parseErrors) {
errs[i].msg = r.Msg; errs[i].msg = r.Msg;
} }
errs[len(errors)].src = src[offs : len(src)]; errs[len(errors)].src = src[offs : len(src)];
return nil, &parseErrors{path, errs, src};
} else { } else {
// TODO should have some default handling here to be more robust // single error of unspecified type
panic("unreachable"); errs = make([]parseError, 2);
errs[0] = parseError{[]byte{}, 0, err.String()};
errs[1].src = src;
} }
return nil, &parseErrors{path, errs, src};
} }
return prog, nil; return prog, nil;
...@@ -478,7 +483,7 @@ func findPackage(path string) (canonical string, pd *pakDesc, dirs dirList) { ...@@ -478,7 +483,7 @@ func findPackage(path string) (canonical string, pd *pakDesc, dirs dirList) {
} }
func (p *pakDesc) Doc() (*doc.PackageDoc, *parseErrors) { func (p *pakDesc) doc() (*doc.PackageDoc, *parseErrors) {
if p == nil { if p == nil {
return nil, nil; return nil, nil;
} }
...@@ -519,7 +524,7 @@ func servePkg(c *http.Conn, r *http.Request) { ...@@ -519,7 +524,7 @@ func servePkg(c *http.Conn, r *http.Request) {
return; return;
} }
pdoc, errors := desc.Doc(); pdoc, errors := desc.doc();
if errors != nil { if errors != nil {
serveParseErrors(c, errors); serveParseErrors(c, errors);
return; return;
...@@ -695,7 +700,7 @@ func main() { ...@@ -695,7 +700,7 @@ func main() {
} }
_, desc, dirs := findPackage(flag.Arg(0)); _, desc, dirs := findPackage(flag.Arg(0));
pdoc, errors := desc.Doc(); pdoc, errors := desc.doc();
if errors != nil { if errors != nil {
err := parseerrorText.Execute(errors, os.Stderr); err := parseerrorText.Execute(errors, os.Stderr);
if err != nil { if err != nil {
......
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