Commit a3d1045f authored by Robert Griesemer's avatar Robert Griesemer

1) Change default gofmt default settings for

   parsing and printing to new syntax.

   Use -oldparser to parse the old syntax,
   use -oldprinter to print the old syntax.

2) Change default gofmt formatting settings
   to use tabs for indentation only and to use
   spaces for alignment. This will make the code
   alignment insensitive to an editor's tabwidth.

   Use -spaces=false to use tabs for alignment.

3) Manually changed src/exp/parser/parser_test.go
   so that it doesn't try to parse the parser's
   source files using the old syntax (they have
   new syntax now).

4) gofmt -w src misc test/bench

3rd set of files.

R=rsc
CC=golang-dev
https://golang.org/cl/180048
parent 5a1d3323
This diff is collapsed.
......@@ -8,14 +8,14 @@ import "go/token"
func filterIdentList(list []*Ident) []*Ident {
j := 0;
j := 0
for _, x := range list {
if x.IsExported() {
list[j] = x;
j++;
list[j] = x
j++
}
}
return list[0:j];
return list[0:j]
}
......@@ -32,14 +32,14 @@ func isExportedType(typ Expr) bool {
case *StarExpr:
return isExportedType(t.X)
}
return false;
return false
}
func filterFieldList(list []*Field, incomplete *bool) []*Field {
j := 0;
j := 0
for _, f := range list {
exported := false;
exported := false
if len(f.Names) == 0 {
// anonymous field
// (Note that a non-exported anonymous field
......@@ -49,23 +49,23 @@ func filterFieldList(list []*Field, incomplete *bool) []*Field {
// type information.)
exported = isExportedType(f.Type)
} else {
n := len(f.Names);
f.Names = filterIdentList(f.Names);
n := len(f.Names)
f.Names = filterIdentList(f.Names)
if len(f.Names) < n {
*incomplete = true
}
exported = len(f.Names) > 0;
exported = len(f.Names) > 0
}
if exported {
filterType(f.Type);
list[j] = f;
j++;
filterType(f.Type)
list[j] = f
j++
}
}
if j < len(list) {
*incomplete = true
}
return list[0:j];
return list[0:j]
}
......@@ -85,13 +85,13 @@ func filterType(typ Expr) {
case *StructType:
t.Fields = filterFieldList(t.Fields, &t.Incomplete)
case *FuncType:
filterParamList(t.Params);
filterParamList(t.Results);
filterParamList(t.Params)
filterParamList(t.Results)
case *InterfaceType:
t.Methods = filterFieldList(t.Methods, &t.Incomplete)
case *MapType:
filterType(t.Key);
filterType(t.Value);
filterType(t.Key)
filterType(t.Value)
case *ChanType:
filterType(t.Value)
}
......@@ -101,48 +101,48 @@ func filterType(typ Expr) {
func filterSpec(spec Spec) bool {
switch s := spec.(type) {
case *ValueSpec:
s.Names = filterIdentList(s.Names);
s.Names = filterIdentList(s.Names)
if len(s.Names) > 0 {
filterType(s.Type);
return true;
filterType(s.Type)
return true
}
case *TypeSpec:
// TODO(gri) consider stripping forward declarations
// of structs, interfaces, functions, and methods
if s.Name.IsExported() {
filterType(s.Type);
return true;
filterType(s.Type)
return true
}
}
return false;
return false
}
func filterSpecList(list []Spec) []Spec {
j := 0;
j := 0
for _, s := range list {
if filterSpec(s) {
list[j] = s;
j++;
list[j] = s
j++
}
}
return list[0:j];
return list[0:j]
}
func filterDecl(decl Decl) bool {
switch d := decl.(type) {
case *GenDecl:
d.Specs = filterSpecList(d.Specs);
return len(d.Specs) > 0;
d.Specs = filterSpecList(d.Specs)
return len(d.Specs) > 0
case *FuncDecl:
// TODO consider removing function declaration altogether if
// forward declaration (i.e., if d.Body == nil) because
// in that case the actual declaration will come later.
d.Body = nil; // strip body
return d.Name.IsExported();
d.Body = nil // strip body
return d.Name.IsExported()
}
return false;
return false
}
......@@ -157,15 +157,15 @@ func filterDecl(decl Decl) bool {
// false otherwise.
//
func FileExports(src *File) bool {
j := 0;
j := 0
for _, d := range src.Decls {
if filterDecl(d) {
src.Decls[j] = d;
j++;
src.Decls[j] = d
j++
}
}
src.Decls = src.Decls[0:j];
return j > 0;
src.Decls = src.Decls[0:j]
return j > 0
}
......@@ -177,13 +177,13 @@ func FileExports(src *File) bool {
// returns false otherwise.
//
func PackageExports(pkg *Package) bool {
hasExports := false;
hasExports := false
for _, f := range pkg.Files {
if FileExports(f) {
hasExports = true
}
}
return hasExports;
return hasExports
}
......@@ -199,13 +199,13 @@ var separator = &Comment{noPos, []byte{'/', '/'}}
func MergePackageFiles(pkg *Package) *File {
// Count the number of package comments and declarations across
// all package files.
ncomments := 0;
ndecls := 0;
ncomments := 0
ndecls := 0
for _, f := range pkg.Files {
if f.Doc != nil {
ncomments += len(f.Doc.List) + 1 // +1 for separator
ncomments += len(f.Doc.List) + 1 // +1 for separator
}
ndecls += len(f.Decls);
ndecls += len(f.Decls)
}
// Collect package comments from all package files into a single
......@@ -213,35 +213,35 @@ func MergePackageFiles(pkg *Package) *File {
// is unspecified. In general there should be only one file with
// a package comment; but it's better to collect extra comments
// than drop them on the floor.
var doc *CommentGroup;
var doc *CommentGroup
if ncomments > 0 {
list := make([]*Comment, ncomments-1); // -1: no separator before first group
i := 0;
list := make([]*Comment, ncomments-1) // -1: no separator before first group
i := 0
for _, f := range pkg.Files {
if f.Doc != nil {
if i > 0 {
// not the first group - add separator
list[i] = separator;
i++;
list[i] = separator
i++
}
for _, c := range f.Doc.List {
list[i] = c;
i++;
list[i] = c
i++
}
}
}
doc = &CommentGroup{list, nil};
doc = &CommentGroup{list, nil}
}
// Collect declarations from all package files.
var decls []Decl;
var decls []Decl
if ndecls > 0 {
decls = make([]Decl, ndecls);
i := 0;
decls = make([]Decl, ndecls)
i := 0
for _, f := range pkg.Files {
for _, d := range f.Decls {
decls[i] = d;
i++;
decls[i] = d
i++
}
}
}
......@@ -249,5 +249,5 @@ func MergePackageFiles(pkg *Package) *File {
// TODO(gri) Should collect comments as well. For that the comment
// list should be changed back into a []*CommentGroup,
// otherwise need to modify the existing linked list.
return &File{doc, noPos, &Ident{noPos, pkg.Name}, decls, nil};
return &File{doc, noPos, &Ident{noPos, pkg.Name}, decls, nil}
}
......@@ -11,13 +11,13 @@ package ast
// NOTE: WORK IN PROGRESS
//
type Scope struct {
Outer *Scope;
Names map[string]*Ident;
Outer *Scope
Names map[string]*Ident
}
// NewScope creates a new scope nested in the outer scope.
func NewScope(outer *Scope) *Scope { return &Scope{outer, make(map[string]*Ident)} }
func NewScope(outer *Scope) *Scope { return &Scope{outer, make(map[string]*Ident)} }
// Declare inserts an identifier into the scope s. If the
......@@ -28,8 +28,8 @@ func (s *Scope) Declare(ident *Ident) bool {
if _, found := s.Names[ident.Value]; found {
return false
}
s.Names[ident.Value] = ident;
return true;
s.Names[ident.Value] = ident
return true
}
......@@ -43,7 +43,7 @@ func (s *Scope) Lookup(name string) *Ident {
return ident
}
}
return nil;
return nil
}
......
......@@ -10,7 +10,7 @@ import "fmt"
// If the result visitor w is not nil, Walk visits each of the children
// of node with the visitor w, followed by a call of w.Visit(nil).
type Visitor interface {
Visit(node interface{}) (w Visitor);
Visit(node interface{}) (w Visitor)
}
......@@ -71,13 +71,13 @@ func Walk(v Visitor, node interface{}) {
// comments list.
case *Field:
walkCommentGroup(v, n.Doc);
Walk(v, n.Names);
Walk(v, n.Type);
walkCommentGroup(v, n.Doc)
Walk(v, n.Names)
Walk(v, n.Type)
for _, x := range n.Tag {
Walk(v, x)
}
walkCommentGroup(v, n.Comment);
walkCommentGroup(v, n.Comment)
// Expressions
case *BadExpr, *Ident, *Ellipsis, *BasicLit:
......@@ -92,35 +92,35 @@ func Walk(v Visitor, node interface{}) {
if n != nil {
Walk(v, n.Type)
}
walkBlockStmt(v, n.Body);
walkBlockStmt(v, n.Body)
case *CompositeLit:
Walk(v, n.Type);
Walk(v, n.Elts);
Walk(v, n.Type)
Walk(v, n.Elts)
case *ParenExpr:
Walk(v, n.X)
case *SelectorExpr:
Walk(v, n.X);
walkIdent(v, n.Sel);
Walk(v, n.X)
walkIdent(v, n.Sel)
case *IndexExpr:
Walk(v, n.X);
Walk(v, n.Index);
Walk(v, n.X)
Walk(v, n.Index)
case *SliceExpr:
Walk(v, n.X);
Walk(v, n.Index);
Walk(v, n.End);
Walk(v, n.X)
Walk(v, n.Index)
Walk(v, n.End)
case *TypeAssertExpr:
Walk(v, n.X);
Walk(v, n.Type);
Walk(v, n.X)
Walk(v, n.Type)
case *CallExpr:
Walk(v, n.Fun);
Walk(v, n.Args);
Walk(v, n.Fun)
Walk(v, n.Args)
case *StarExpr:
Walk(v, n.X)
......@@ -129,31 +129,31 @@ func Walk(v Visitor, node interface{}) {
Walk(v, n.X)
case *BinaryExpr:
Walk(v, n.X);
Walk(v, n.Y);
Walk(v, n.X)
Walk(v, n.Y)
case *KeyValueExpr:
Walk(v, n.Key);
Walk(v, n.Value);
Walk(v, n.Key)
Walk(v, n.Value)
// Types
case *ArrayType:
Walk(v, n.Len);
Walk(v, n.Elt);
Walk(v, n.Len)
Walk(v, n.Elt)
case *StructType:
Walk(v, n.Fields)
case *FuncType:
Walk(v, n.Params);
Walk(v, n.Results);
Walk(v, n.Params)
Walk(v, n.Results)
case *InterfaceType:
Walk(v, n.Methods)
case *MapType:
Walk(v, n.Key);
Walk(v, n.Value);
Walk(v, n.Key)
Walk(v, n.Value)
case *ChanType:
Walk(v, n.Value)
......@@ -169,8 +169,8 @@ func Walk(v Visitor, node interface{}) {
// nothing to do
case *LabeledStmt:
walkIdent(v, n.Label);
Walk(v, n.Stmt);
walkIdent(v, n.Label)
Walk(v, n.Stmt)
case *ExprStmt:
Walk(v, n.X)
......@@ -179,8 +179,8 @@ func Walk(v Visitor, node interface{}) {
Walk(v, n.X)
case *AssignStmt:
Walk(v, n.Lhs);
Walk(v, n.Rhs);
Walk(v, n.Lhs)
Walk(v, n.Rhs)
case *GoStmt:
if n.Call != nil {
......@@ -202,99 +202,99 @@ func Walk(v Visitor, node interface{}) {
Walk(v, n.List)
case *IfStmt:
Walk(v, n.Init);
Walk(v, n.Cond);
walkBlockStmt(v, n.Body);
Walk(v, n.Else);
Walk(v, n.Init)
Walk(v, n.Cond)
walkBlockStmt(v, n.Body)
Walk(v, n.Else)
case *CaseClause:
Walk(v, n.Values);
Walk(v, n.Body);
Walk(v, n.Values)
Walk(v, n.Body)
case *SwitchStmt:
Walk(v, n.Init);
Walk(v, n.Tag);
walkBlockStmt(v, n.Body);
Walk(v, n.Init)
Walk(v, n.Tag)
walkBlockStmt(v, n.Body)
case *TypeCaseClause:
Walk(v, n.Types);
Walk(v, n.Body);
Walk(v, n.Types)
Walk(v, n.Body)
case *TypeSwitchStmt:
Walk(v, n.Init);
Walk(v, n.Assign);
walkBlockStmt(v, n.Body);
Walk(v, n.Init)
Walk(v, n.Assign)
walkBlockStmt(v, n.Body)
case *CommClause:
Walk(v, n.Lhs);
Walk(v, n.Rhs);
Walk(v, n.Body);
Walk(v, n.Lhs)
Walk(v, n.Rhs)
Walk(v, n.Body)
case *SelectStmt:
walkBlockStmt(v, n.Body)
case *ForStmt:
Walk(v, n.Init);
Walk(v, n.Cond);
Walk(v, n.Post);
walkBlockStmt(v, n.Body);
Walk(v, n.Init)
Walk(v, n.Cond)
Walk(v, n.Post)
walkBlockStmt(v, n.Body)
case *RangeStmt:
Walk(v, n.Key);
Walk(v, n.Value);
Walk(v, n.X);
walkBlockStmt(v, n.Body);
Walk(v, n.Key)
Walk(v, n.Value)
Walk(v, n.X)
walkBlockStmt(v, n.Body)
// Declarations
case *ImportSpec:
walkCommentGroup(v, n.Doc);
walkIdent(v, n.Name);
walkCommentGroup(v, n.Doc)
walkIdent(v, n.Name)
for _, x := range n.Path {
Walk(v, x)
}
walkCommentGroup(v, n.Comment);
walkCommentGroup(v, n.Comment)
case *ValueSpec:
walkCommentGroup(v, n.Doc);
Walk(v, n.Names);
Walk(v, n.Type);
Walk(v, n.Values);
walkCommentGroup(v, n.Comment);
walkCommentGroup(v, n.Doc)
Walk(v, n.Names)
Walk(v, n.Type)
Walk(v, n.Values)
walkCommentGroup(v, n.Comment)
case *TypeSpec:
walkCommentGroup(v, n.Doc);
walkIdent(v, n.Name);
Walk(v, n.Type);
walkCommentGroup(v, n.Comment);
walkCommentGroup(v, n.Doc)
walkIdent(v, n.Name)
Walk(v, n.Type)
walkCommentGroup(v, n.Comment)
case *BadDecl:
// nothing to do
case *GenDecl:
walkCommentGroup(v, n.Doc);
walkCommentGroup(v, n.Doc)
for _, s := range n.Specs {
Walk(v, s)
}
case *FuncDecl:
walkCommentGroup(v, n.Doc);
walkCommentGroup(v, n.Doc)
if n.Recv != nil {
Walk(v, n.Recv)
}
walkIdent(v, n.Name);
walkIdent(v, n.Name)
if n.Type != nil {
Walk(v, n.Type)
}
walkBlockStmt(v, n.Body);
walkBlockStmt(v, n.Body)
// Files and packages
case *File:
walkCommentGroup(v, n.Doc);
walkIdent(v, n.Name);
walkCommentGroup(v, n.Doc)
walkIdent(v, n.Name)
for _, d := range n.Decls {
Walk(v, d)
}
walkCommentGroup(v, n.Comments);
walkCommentGroup(v, n.Comments)
case *Package:
for _, f := range n.Files {
......@@ -322,9 +322,9 @@ func Walk(v Visitor, node interface{}) {
}
default:
fmt.Printf("ast.Walk: unexpected type %T", n);
panic();
fmt.Printf("ast.Walk: unexpected type %T", n)
panic()
}
v.Visit(nil);
v.Visit(nil)
}
......@@ -7,10 +7,10 @@
package doc
import (
"go/ast";
"io";
"strings";
"template"; // for htmlEscape
"go/ast"
"io"
"strings"
"template" // for htmlEscape
)
// Comment extraction
......@@ -21,12 +21,12 @@ func CommentText(comment *ast.CommentGroup) string {
if comment == nil {
return ""
}
comments := make([]string, len(comment.List));
comments := make([]string, len(comment.List))
for i, c := range comment.List {
comments[i] = string(c.Text)
}
lines := make([]string, 0, 20);
lines := make([]string, 0, 20)
for _, c := range comments {
// Remove comment markers.
// The parser has given us exactly the comment text.
......@@ -34,7 +34,7 @@ func CommentText(comment *ast.CommentGroup) string {
case n >= 4 && c[0:2] == "/*" && c[n-2:n] == "*/":
c = c[2 : n-2]
case n >= 2 && c[0:2] == "//":
c = c[2:n];
c = c[2:n]
// Remove leading space after //, if there is one.
if len(c) > 0 && c[0] == ' ' {
c = c[1:]
......@@ -42,61 +42,61 @@ func CommentText(comment *ast.CommentGroup) string {
}
// Split on newlines.
cl := strings.Split(c, "\n", 0);
cl := strings.Split(c, "\n", 0)
// Walk lines, stripping trailing white space and adding to list.
for _, l := range cl {
// Strip trailing white space
m := len(l);
m := len(l)
for m > 0 && (l[m-1] == ' ' || l[m-1] == '\n' || l[m-1] == '\t' || l[m-1] == '\r') {
m--
}
l = l[0:m];
l = l[0:m]
// Add to list.
n := len(lines);
n := len(lines)
if n+1 >= cap(lines) {
newlines := make([]string, n, 2*cap(lines));
newlines := make([]string, n, 2*cap(lines))
for k := range newlines {
newlines[k] = lines[k]
}
lines = newlines;
lines = newlines
}
lines = lines[0 : n+1];
lines[n] = l;
lines = lines[0 : n+1]
lines[n] = l
}
}
// Remove leading blank lines; convert runs of
// interior blank lines to a single blank line.
n := 0;
n := 0
for _, line := range lines {
if line != "" || n > 0 && lines[n-1] != "" {
lines[n] = line;
n++;
lines[n] = line
n++
}
}
lines = lines[0:n];
lines = lines[0:n]
// Add final "" entry to get trailing newline from Join.
// The original loop always leaves room for one more.
if n > 0 && lines[n-1] != "" {
lines = lines[0 : n+1];
lines[n] = "";
lines = lines[0 : n+1]
lines[n] = ""
}
return strings.Join(lines, "\n");
return strings.Join(lines, "\n")
}
// Split bytes into lines.
func split(text []byte) [][]byte {
// count lines
n := 0;
last := 0;
n := 0
last := 0
for i, c := range text {
if c == '\n' {
last = i + 1;
n++;
last = i + 1
n++
}
}
if last < len(text) {
......@@ -104,76 +104,76 @@ func split(text []byte) [][]byte {
}
// split
out := make([][]byte, n);
last = 0;
n = 0;
out := make([][]byte, n)
last = 0
n = 0
for i, c := range text {
if c == '\n' {
out[n] = text[last : i+1];
last = i + 1;
n++;
out[n] = text[last : i+1]
last = i + 1
n++
}
}
if last < len(text) {
out[n] = text[last:]
}
return out;
return out
}
var (
ldquo = strings.Bytes("&ldquo;");
rdquo = strings.Bytes("&rdquo;");
ldquo = strings.Bytes("&ldquo;")
rdquo = strings.Bytes("&rdquo;")
)
// Escape comment text for HTML.
// Also, turn `` into &ldquo; and '' into &rdquo;.
func commentEscape(w io.Writer, s []byte) {
last := 0;
last := 0
for i := 0; i < len(s)-1; i++ {
if s[i] == s[i+1] && (s[i] == '`' || s[i] == '\'') {
template.HTMLEscape(w, s[last:i]);
last = i + 2;
template.HTMLEscape(w, s[last:i])
last = i + 2
switch s[i] {
case '`':
w.Write(ldquo)
case '\'':
w.Write(rdquo)
}
i++; // loop will add one more
i++ // loop will add one more
}
}
template.HTMLEscape(w, s[last:]);
template.HTMLEscape(w, s[last:])
}
var (
html_p = strings.Bytes("<p>\n");
html_endp = strings.Bytes("</p>\n");
html_pre = strings.Bytes("<pre>");
html_endpre = strings.Bytes("</pre>\n");
html_p = strings.Bytes("<p>\n")
html_endp = strings.Bytes("</p>\n")
html_pre = strings.Bytes("<pre>")
html_endpre = strings.Bytes("</pre>\n")
)
func indentLen(s []byte) int {
i := 0;
i := 0
for i < len(s) && (s[i] == ' ' || s[i] == '\t') {
i++
}
return i;
return i
}
func isBlank(s []byte) bool { return len(s) == 0 || (len(s) == 1 && s[0] == '\n') }
func isBlank(s []byte) bool { return len(s) == 0 || (len(s) == 1 && s[0] == '\n') }
func commonPrefix(a, b []byte) []byte {
i := 0;
i := 0
for i < len(a) && i < len(b) && a[i] == b[i] {
i++
}
return a[0:i];
return a[0:i]
}
......@@ -183,13 +183,13 @@ func unindent(block [][]byte) {
}
// compute maximum common white prefix
prefix := block[0][0:indentLen(block[0])];
prefix := block[0][0:indentLen(block[0])]
for _, line := range block {
if !isBlank(line) {
prefix = commonPrefix(prefix, line[0:indentLen(line)])
}
}
n := len(prefix);
n := len(prefix)
// remove
for i, line := range block {
......@@ -212,37 +212,37 @@ func unindent(block [][]byte) {
// TODO(rsc): I'd like to pass in an array of variable names []string
// and then italicize those strings when they appear as words.
func ToHTML(w io.Writer, s []byte) {
inpara := false;
inpara := false
close := func() {
if inpara {
w.Write(html_endp);
inpara = false;
w.Write(html_endp)
inpara = false
}
};
}
open := func() {
if !inpara {
w.Write(html_p);
inpara = true;
w.Write(html_p)
inpara = true
}
};
}
lines := split(s);
unindent(lines);
lines := split(s)
unindent(lines)
for i := 0; i < len(lines); {
line := lines[i];
line := lines[i]
if isBlank(line) {
// close paragraph
close();
i++;
continue;
close()
i++
continue
}
if indentLen(line) > 0 {
// close paragraph
close();
close()
// count indented or blank lines
j := i + 1;
j := i + 1
for j < len(lines) && (isBlank(lines[j]) || indentLen(lines[j]) > 0) {
j++
}
......@@ -250,25 +250,25 @@ func ToHTML(w io.Writer, s []byte) {
for j > i && isBlank(lines[j-1]) {
j--
}
block := lines[i:j];
i = j;
block := lines[i:j]
i = j
unindent(block);
unindent(block)
// put those lines in a pre block.
// they don't get the nice text formatting,
// just html escaping
w.Write(html_pre);
w.Write(html_pre)
for _, line := range block {
template.HTMLEscape(w, line)
}
w.Write(html_endpre);
continue;
w.Write(html_endpre)
continue
}
// open paragraph
open();
commentEscape(w, lines[i]);
i++;
open()
commentEscape(w, lines[i])
i++
}
close();
close()
}
This diff is collapsed.
......@@ -7,15 +7,15 @@
package parser
import (
"bytes";
"fmt";
"go/ast";
"go/scanner";
"io";
"io/ioutil";
"os";
pathutil "path";
"strings";
"bytes"
"fmt"
"go/ast"
"go/scanner"
"io"
"io/ioutil"
"os"
pathutil "path"
"strings"
)
......@@ -36,18 +36,18 @@ func readSource(filename string, src interface{}) ([]byte, os.Error) {
return s.Bytes(), nil
}
case io.Reader:
var buf bytes.Buffer;
_, err := io.Copy(&buf, s);
var buf bytes.Buffer
_, err := io.Copy(&buf, s)
if err != nil {
return nil, err
}
return buf.Bytes(), nil;
return buf.Bytes(), nil
default:
return nil, os.ErrorString("invalid source")
}
}
return ioutil.ReadFile(filename);
return ioutil.ReadFile(filename)
}
......@@ -57,14 +57,14 @@ func readSource(filename string, src interface{}) ([]byte, os.Error) {
// may be nil or contain a partial AST.
//
func ParseExpr(filename string, src interface{}) (ast.Expr, os.Error) {
data, err := readSource(filename, src);
data, err := readSource(filename, src)
if err != nil {
return nil, err
}
var p parser;
p.init(filename, data, 0);
return p.parseExpr(), p.GetError(scanner.Sorted);
var p parser
p.init(filename, data, 0)
return p.parseExpr(), p.GetError(scanner.Sorted)
}
......@@ -74,14 +74,14 @@ func ParseExpr(filename string, src interface{}) (ast.Expr, os.Error) {
// list may be nil or contain partial ASTs.
//
func ParseStmtList(filename string, src interface{}) ([]ast.Stmt, os.Error) {
data, err := readSource(filename, src);
data, err := readSource(filename, src)
if err != nil {
return nil, err
}
var p parser;
p.init(filename, data, 0);
return p.parseStmtList(), p.GetError(scanner.Sorted);
var p parser
p.init(filename, data, 0)
return p.parseStmtList(), p.GetError(scanner.Sorted)
}
......@@ -91,14 +91,14 @@ func ParseStmtList(filename string, src interface{}) ([]ast.Stmt, os.Error) {
// list may be nil or contain partial ASTs.
//
func ParseDeclList(filename string, src interface{}) ([]ast.Decl, os.Error) {
data, err := readSource(filename, src);
data, err := readSource(filename, src)
if err != nil {
return nil, err
}
var p parser;
p.init(filename, data, 0);
return p.parseDeclList(), p.GetError(scanner.Sorted);
var p parser
p.init(filename, data, 0)
return p.parseDeclList(), p.GetError(scanner.Sorted)
}
......@@ -121,14 +121,14 @@ func ParseDeclList(filename string, src interface{}) ([]ast.Decl, os.Error) {
// are returned via a scanner.ErrorList which is sorted by file position.
//
func ParseFile(filename string, src interface{}, mode uint) (*ast.File, os.Error) {
data, err := readSource(filename, src);
data, err := readSource(filename, src)
if err != nil {
return nil, err
}
var p parser;
p.init(filename, data, mode);
return p.parseFile(), p.GetError(scanner.NoMultiples);
var p parser
p.init(filename, data, mode)
return p.parseFile(), p.GetError(scanner.NoMultiples)
}
......@@ -139,13 +139,13 @@ func ParseFile(filename string, src interface{}, mode uint) (*ast.File, os.Error
// flags that control the amount of source text parsed are ignored.
//
func ParsePkgFile(pkgname, filename string, mode uint) (*ast.File, os.Error) {
src, err := ioutil.ReadFile(filename);
src, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
if pkgname != "" {
prog, err := ParseFile(filename, src, PackageClauseOnly);
prog, err := ParseFile(filename, src, PackageClauseOnly)
if err != nil {
return nil, err
}
......@@ -155,7 +155,7 @@ func ParsePkgFile(pkgname, filename string, mode uint) (*ast.File, os.Error) {
}
// ignore flags that control partial parsing
return ParseFile(filename, src, mode&^(PackageClauseOnly|ImportsOnly));
return ParseFile(filename, src, mode&^(PackageClauseOnly|ImportsOnly))
}
......@@ -167,27 +167,27 @@ func ParsePkgFile(pkgname, filename string, mode uint) (*ast.File, os.Error) {
// Mode flags that control the amount of source text parsed are ignored.
//
func ParsePackage(path string, filter func(*os.Dir) bool, mode uint) (*ast.Package, os.Error) {
fd, err := os.Open(path, os.O_RDONLY, 0);
fd, err := os.Open(path, os.O_RDONLY, 0)
if err != nil {
return nil, err
}
defer fd.Close();
defer fd.Close()
list, err := fd.Readdir(-1);
list, err := fd.Readdir(-1)
if err != nil {
return nil, err
}
name := "";
files := make(map[string]*ast.File);
name := ""
files := make(map[string]*ast.File)
for i := 0; i < len(list); i++ {
entry := &list[i];
entry := &list[i]
if filter == nil || filter(entry) {
src, err := ParsePkgFile(name, pathutil.Join(path, entry.Name), mode);
src, err := ParsePkgFile(name, pathutil.Join(path, entry.Name), mode)
if err != nil {
return nil, err
}
files[entry.Name] = src;
files[entry.Name] = src
if name == "" {
name = src.Name.Value
}
......@@ -198,5 +198,5 @@ func ParsePackage(path string, filter func(*os.Dir) bool, mode uint) (*ast.Packa
return nil, os.NewError(path + ": no package found")
}
return &ast.Package{name, path, files}, nil;
return &ast.Package{name, path, files}, nil
}
This diff is collapsed.
......@@ -5,8 +5,8 @@
package parser
import (
"os";
"testing";
"os"
"testing"
)
......@@ -20,7 +20,7 @@ var illegalInputs = []interface{}{
func TestParseIllegalInputs(t *testing.T) {
for _, src := range illegalInputs {
_, err := ParseFile("", src, 0);
_, err := ParseFile("", src, 0)
if err == nil {
t.Errorf("ParseFile(%v) should have failed", src)
}
......@@ -37,7 +37,7 @@ var validPrograms = []interface{}{
func TestParseValidPrograms(t *testing.T) {
for _, src := range validPrograms {
_, err := ParseFile("", src, 0);
_, err := ParseFile("", src, 0)
if err != nil {
t.Errorf("ParseFile(%q): %v", src, err)
}
......@@ -53,7 +53,7 @@ var validFiles = []string{
func TestParse3(t *testing.T) {
for _, filename := range validFiles {
_, err := ParseFile(filename, nil, 0);
_, err := ParseFile(filename, nil, 0)
if err != nil {
t.Errorf("ParseFile(%s): %v", filename, err)
}
......@@ -69,16 +69,16 @@ func nameFilter(filename string) bool {
default:
return false
}
return true;
return true
}
func dirFilter(d *os.Dir) bool { return nameFilter(d.Name) }
func dirFilter(d *os.Dir) bool { return nameFilter(d.Name) }
func TestParse4(t *testing.T) {
path := ".";
pkg, err := ParsePackage(path, dirFilter, 0);
path := "."
pkg, err := ParsePackage(path, dirFilter, 0)
if err != nil {
t.Fatalf("ParsePackage(%s): %v", path, err)
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -10,14 +10,14 @@ import "io"
// The Write method never returns an error.
// Sum returns the bytes of integer hash codes in big-endian order.
type Hash interface {
io.Writer;
Sum() []byte;
Reset();
Size() int; // number of bytes Sum returns
io.Writer
Sum() []byte
Reset()
Size() int // number of bytes Sum returns
}
// Hash32 is the common interface implemented by all 32-bit hash functions.
type Hash32 interface {
Hash;
Sum32() uint32;
Hash
Sum32() uint32
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -9,8 +9,8 @@ import "fmt"
// ParseError aggregates information about a JSON parse error. It is
// compatible with the os.Error interface.
type ParseError struct {
Index int; // A byte index in JSON string where the error occurred
Token string; // An offending token
Index int // A byte index in JSON string where the error occurred
Token string // An offending token
}
// Produce a string representation of this ParseError.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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