Commit e06a654c authored by Robert Griesemer's avatar Robert Griesemer

daily snapshot:

- correctly associate comments with declarations
  (available through AST)
- very raw printing of interface
- much more functionality, now needs some formatting, sorting, etc.

R=r
OCL=26213
CL=26213
parent ce9417ee
...@@ -28,6 +28,21 @@ func assert(pred bool) { ...@@ -28,6 +28,21 @@ func assert(pred bool) {
} }
// ----------------------------------------------------------------------------
// Comments
type Comment struct {
Loc scanner.Location;
EndLine int; // the line where the comment ends
Text []byte;
}
// A CommentGroup is a sequence of consequtive comments
// with no other tokens and no empty lines inbetween.
type CommentGroup []*Comment
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Expressions // Expressions
...@@ -132,6 +147,7 @@ type ( ...@@ -132,6 +147,7 @@ type (
Idents []*Ident; Idents []*Ident;
Typ Expr; Typ Expr;
Tag Expr; // nil = no tag Tag Expr; // nil = no tag
Comment CommentGroup;
}; };
StructType struct { StructType struct {
...@@ -445,12 +461,14 @@ type ( ...@@ -445,12 +461,14 @@ type (
Idents []*Ident; Idents []*Ident;
Typ Expr; Typ Expr;
Vals Expr; Vals Expr;
Comment CommentGroup;
}; };
TypeDecl struct { TypeDecl struct {
Loc scanner.Location; // if > 0: position of "type" Loc scanner.Location; // if > 0: position of "type"
Ident *Ident; Ident *Ident;
Typ Expr; Typ Expr;
Comment CommentGroup;
}; };
VarDecl struct { VarDecl struct {
...@@ -458,6 +476,7 @@ type ( ...@@ -458,6 +476,7 @@ type (
Idents []*Ident; Idents []*Ident;
Typ Expr; Typ Expr;
Vals Expr; Vals Expr;
Comment CommentGroup;
}; };
FuncDecl struct { FuncDecl struct {
...@@ -466,6 +485,7 @@ type ( ...@@ -466,6 +485,7 @@ type (
Ident *Ident; Ident *Ident;
Sig *Signature; Sig *Signature;
Body *Block; Body *Block;
Comment CommentGroup;
}; };
DeclList struct { DeclList struct {
...@@ -500,17 +520,13 @@ func (d *DeclList) Visit(v DeclVisitor) { v.DoDeclList(d); } ...@@ -500,17 +520,13 @@ func (d *DeclList) Visit(v DeclVisitor) { v.DoDeclList(d); }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Program // Program
type Comment struct { // TODO rename to Package
Loc scanner.Location;
Text []byte;
}
type Program struct { type Program struct {
Loc scanner.Location; // tok is token.PACKAGE Loc scanner.Location; // tok is token.PACKAGE
Ident *Ident; Ident *Ident;
Decls []Decl; Decls []Decl;
Comments []*Comment; Comment CommentGroup;
Comments []CommentGroup;
} }
......
...@@ -112,7 +112,7 @@ func Compile(src_file string, flags *Flags) (*AST.Program, int) { ...@@ -112,7 +112,7 @@ func Compile(src_file string, flags *Flags) (*AST.Program, int) {
var parser Parser.Parser; var parser Parser.Parser;
parser.Init(&scanner, &err, flags.Verbose); parser.Init(&scanner, &err, flags.Verbose);
prog := parser.ParseProgram(); prog := parser.Parse(Parser.ParseEntirePackage);
if err.nerrors == 0 { if err.nerrors == 0 {
TypeChecker.CheckProgram(&err, prog); TypeChecker.CheckProgram(&err, prog);
......
...@@ -108,7 +108,7 @@ func serveFile(c *http.Conn, filename string) { ...@@ -108,7 +108,7 @@ func serveFile(c *http.Conn, filename string) {
} }
c.SetHeader("content-type", "text/html; charset=utf-8"); c.SetHeader("content-type", "text/html; charset=utf-8");
Printer.Print(c, true, prog); Printer.Print(c, prog, true);
} }
......
This diff is collapsed.
...@@ -53,7 +53,7 @@ func main() { ...@@ -53,7 +53,7 @@ func main() {
sys.Exit(1); sys.Exit(1);
} }
if !*silent { if !*silent {
Printer.Print(os.Stdout, *html, prog); Printer.Print(os.Stdout, prog, *html);
} }
} }
} }
......
This diff is collapsed.
<h1>package <!--PACKAGE--></h1> <font color=red>THIS SECTION IS CURRENTLY UNDER CONSTRUCTION</font>
<!--INTERFACE--> <h1>package <!--PACKAGE_NAME--></h1>
<!--PACKAGE_COMMENT-->
<!--PACKAGE_INTERFACE-->
<hr /> <hr />
<h1>Implementation</h1>
<h1>package <!--PACKAGE--></h1> <font color=grey>Comments are currently not shown in the source.</font>
<pre> <pre>
<!--BODY--> <!--PACKAGE_BODY-->
</pre> </pre>
</div> <!-- content --> </div> <!-- content -->
......
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