1
0
mirror of https://github.com/golang/go synced 2024-11-25 00:07:56 -07:00

semi-weekly snapshot:

- format.go implementation complete
- lots of documentation added (not quite complete)

TBR=r
OCL=29130
CL=29130
This commit is contained in:
Robert Griesemer 2009-05-20 17:09:59 -07:00
parent e6cddeaee8
commit 787dd4d3f3
4 changed files with 500 additions and 326 deletions

View File

@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Format file for printing AST nodes (package "ast").
// Format file for printing AST nodes.
ast "ast";
token "token";
// ----------------------------------------------------------------------------
// Elementary types
token.Token =
^:string;
// Basic types, support rules
array =
*;
@ -31,10 +31,6 @@ empty =
exists =
*:empty;
// ----------------------------------------------------------------------------
// TODO these are implicit - only here for debugging
ast.Expr =
*;
@ -44,9 +40,11 @@ ast.Stmt =
ast.Decl =
*;
// ----------------------------------------------------------------------------
// Comments
// Tokens and comments
token.Token =
^:string;
ast.Comment =
Text:string [Text:isMultiLineComment "\n"];

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@ import (
func check(t *testing.T, form, expected string, args ...) {
f, err := format.Parse(io.StringBytes(form), nil);
if err != nil {
panic(err.String());
panic(form + ": " + err.String());
}
result := f.Sprint(args);
if result != expected {
@ -51,6 +51,7 @@ type T1 struct {
}
const F1 =
`format "format";`
`int = "%d";`
`format.T1 = "<" a ">";`
@ -95,11 +96,13 @@ type T3 struct {
}
const F3a =
`format "format";`
`default = "%v";`
`array = *;`
`format.T3 = s {" " a a / ","};`
const F3b =
`format "format";`
`int = "%d";`
`string = "%s";`
`array = *;`
@ -124,6 +127,7 @@ type T4 struct {
}
const F4a =
`format "format";`
`int = "%d";`
`pointer = *;`
`array = *;`
@ -132,6 +136,7 @@ const F4a =
`format.T4 = "<" (x:empty x | "-") ">" `
const F4b =
`format "format";`
`int = "%d";`
`pointer = *;`
`array = *;`

View File

@ -120,7 +120,7 @@ func main() {
}
ast_format, err := format.Parse(src, fmap);
if err != nil {
fmt.Fprintf(os.Stderr, "%s: format errors:\n%s", ast_txt, err);
fmt.Fprintf(os.Stderr, "%s:%v\n", ast_txt, err);
os.Exit(1);
}