Commit 75a5d6cd authored by Robert Griesemer's avatar Robert Griesemer

Significant parser cleanup:

- commented public interface
- much better and very precise error messages
- much better tracing output
- many more checks (still permits more than just syntactically legal
  programs, but much more is checked that can be checked w/o semantic information)
- updated with respect to updated AST
- general cleanup throughout

Parser almost ready for move into lib/go.

R=r
OCL=26853
CL=26855
parent 7cba8e6f
...@@ -97,11 +97,11 @@ func Compile(src_file string, flags *Flags) (*ast.Package, ErrorList) { ...@@ -97,11 +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);
pflags := uint(0); mode := uint(0);
if flags.Verbose { if flags.Verbose {
pflags |= parser.Trace; mode |= parser.Trace;
} }
prog, nerrs := parser.Parse(&scanner, &err, parser.ParseEntirePackage, pflags); prog, nerrs := parser.Parse(&scanner, &err, mode);
if err.errors.Len() == 0 { if err.errors.Len() == 0 {
TypeChecker.CheckProgram(&err, prog); TypeChecker.CheckProgram(&err, prog);
......
This diff is collapsed.
...@@ -591,6 +591,15 @@ func (P *Printer) DoBinaryExpr(x *ast.BinaryExpr) { ...@@ -591,6 +591,15 @@ func (P *Printer) DoBinaryExpr(x *ast.BinaryExpr) {
} }
func (P *Printer) DoKeyValueExpr(x *ast.KeyValueExpr) {
P.Expr(x.Key);
P.separator = blank;
P.Token(x.Colon, token.COLON);
P.separator = blank;
P.Expr(x.Value);
}
func (P *Printer) DoStarExpr(x *ast.StarExpr) { func (P *Printer) DoStarExpr(x *ast.StarExpr) {
P.Token(x.Pos(), token.MUL); P.Token(x.Pos(), token.MUL);
P.Expr(x.X); P.Expr(x.X);
...@@ -721,9 +730,14 @@ func (P *Printer) DoEllipsis(x *ast.Ellipsis) { ...@@ -721,9 +730,14 @@ func (P *Printer) DoEllipsis(x *ast.Ellipsis) {
func (P *Printer) DoArrayType(x *ast.ArrayType) { func (P *Printer) DoArrayType(x *ast.ArrayType) {
P.Token(x.Pos(), token.LBRACK); P.Token(x.Pos(), token.LBRACK);
if x.Len != nil { P.Expr(x.Len);
P.Expr(x.Len); P.Token(nopos, token.RBRACK);
} P.Expr(x.Elt);
}
func (P *Printer) DoSliceType(x *ast.SliceType) {
P.Token(x.Pos(), token.LBRACK);
P.Token(nopos, token.RBRACK); P.Token(nopos, token.RBRACK);
P.Expr(x.Elt); P.Expr(x.Elt);
} }
...@@ -751,11 +765,6 @@ func (P *Printer) DoInterfaceType(x *ast.InterfaceType) { ...@@ -751,11 +765,6 @@ func (P *Printer) DoInterfaceType(x *ast.InterfaceType) {
} }
func (P *Printer) DoSliceType(x *ast.SliceType) {
unimplemented();
}
func (P *Printer) DoMapType(x *ast.MapType) { func (P *Printer) DoMapType(x *ast.MapType) {
P.Token(x.Pos(), token.MAP); P.Token(x.Pos(), token.MAP);
P.separator = blank; P.separator = blank;
......
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