Commit eeddc8e7 authored by Robert Griesemer's avatar Robert Griesemer

- adjustments to match new token/scanner/ast

R=r
OCL=26794
CL=26794
parent 5a72ca45
......@@ -11,8 +11,9 @@ import (
"os";
"utils";
"platform";
"token";
"scanner";
Parser "parser";
"parser";
"ast";
"typechecker";
"sort";
......@@ -34,7 +35,7 @@ type Flags struct {
type Error struct {
Loc scanner.Location;
Pos token.Position;
Msg string;
}
......@@ -42,7 +43,7 @@ type Error struct {
type ErrorList []Error
func (list ErrorList) Len() int { return len(list); }
func (list ErrorList) Less(i, j int) bool { return list[i].Loc.Pos < list[j].Loc.Pos; }
func (list ErrorList) Less(i, j int) bool { return list[i].Pos.Offset < list[j].Pos.Offset; }
func (list ErrorList) Swap(i, j int) { list[i], list[j] = list[j], list[i]; }
......@@ -63,23 +64,23 @@ func (h *errorHandler) Init(filename string, src []byte, columns bool) {
}
func (h *errorHandler) Error(loc scanner.Location, msg string) {
func (h *errorHandler) Error(pos token.Position, msg string) {
// only report errors that are on a new line
// in the hope to avoid most follow-up errors
if loc.Line == h.errline {
if pos.Line == h.errline {
return;
}
// report error
fmt.Printf("%s:%d:", h.filename, loc.Line);
fmt.Printf("%s:%d:", h.filename, pos.Line);
if h.columns {
fmt.Printf("%d:", loc.Col);
fmt.Printf("%d:", pos.Column);
}
fmt.Printf(" %s\n", msg);
// collect the error
h.errors.Push(Error{loc, msg});
h.errline = loc.Line;
h.errors.Push(Error{pos, msg});
h.errline = pos.Line;
}
......@@ -96,10 +97,11 @@ func Compile(src_file string, flags *Flags) (*ast.Package, ErrorList) {
var scanner scanner.Scanner;
scanner.Init(src, &err, true);
var parser Parser.Parser;
parser.Init(&scanner, &err, flags.Verbose);
prog := parser.Parse(Parser.ParseEntirePackage);
pflags := uint(0);
if flags.Verbose {
pflags |= parser.Trace;
}
prog := parser.Parse(&scanner, &err, parser.ParseEntirePackage, pflags);
if err.errors.Len() == 0 {
TypeChecker.CheckProgram(&err, prog);
......
......@@ -124,20 +124,20 @@ func printErrors(c *http.Conn, filename string, errors Compilation.ErrorList) {
fmt.Fprintf(c, "could not read file %s\n", *root + filename);
return;
}
pos := 0;
offs := 0;
for i, e := range errors {
if 0 <= e.Loc.Pos && e.Loc.Pos <= len(src) {
if 0 <= e.Pos.Offset && e.Pos.Offset <= len(src) {
// TODO handle Write errors
c.Write(src[pos : e.Loc.Pos]);
c.Write(src[offs : e.Pos.Offset]);
// TODO this should be done using a .css file
fmt.Fprintf(c, "<b><font color=red>%s >>></font></b>", e.Msg);
pos = e.Loc.Pos;
offs = e.Pos.Offset;
} else {
log.Stdoutf("error position %d out of bounds (len = %d)", e.Loc.Pos, len(src));
log.Stdoutf("error position %d out of bounds (len = %d)", e.Pos.Offset, len(src));
}
}
// TODO handle Write errors
c.Write(src[pos : len(src)]);
c.Write(src[offs : len(src)]);
}
});
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -42,8 +42,8 @@ func assert(pred bool) {
}
func (s *state) Error(loc scanner.Location, msg string) {
s.err.Error(loc, msg);
func (s *state) Error(pos token.Position, msg string) {
s.err.Error(pos, msg);
}
......
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