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