mirror of
https://github.com/golang/go
synced 2024-11-20 07:34:40 -07:00
22301e8cea
- work-around for incorrect import path - added tmpl root in order to run against a goroot w/o templates - clarifications Daily snapshot of syntax-driven formatter. Some progress. Updated gccgo Makefile. TBR=r OCL=28004 CL=28004
218 lines
2.6 KiB
Plaintext
218 lines
2.6 KiB
Plaintext
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Debugging
|
|
|
|
token.Token =
|
|
^ : "%s";
|
|
|
|
|
|
// Format file for printing AST nodes (package "ast").
|
|
ast;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// TODO should these be automatic?
|
|
|
|
Expr =
|
|
"expr ";
|
|
//*;
|
|
|
|
Stmt =
|
|
*;
|
|
|
|
Decl =
|
|
*;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Comments
|
|
|
|
Comment =
|
|
Text : "%s\n";
|
|
|
|
Comments =
|
|
{*};
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Expressions & Types
|
|
|
|
Field =
|
|
{Names ", "} Type;
|
|
|
|
BadExpr =
|
|
"BAD EXPR";
|
|
|
|
Ident =
|
|
Value;
|
|
|
|
Elipsis =
|
|
"...";
|
|
|
|
IntLit =
|
|
Value : "%s";
|
|
|
|
FloatLit =
|
|
Value : "%s";
|
|
|
|
CharLit =
|
|
Value : "%s";
|
|
|
|
StringLit =
|
|
Value : "%s";
|
|
|
|
StringList =
|
|
{ Strings };
|
|
|
|
FuncLit =
|
|
"func ";
|
|
|
|
CompositeLit =
|
|
Type "{}";
|
|
|
|
ParenExpr =
|
|
"(" X ")";
|
|
|
|
SelectorExpr =
|
|
X "." Sel;
|
|
|
|
IndexExpr =
|
|
X "[" Index "]";
|
|
|
|
SliceExpr =
|
|
X "[" Begin " : " End "]";
|
|
|
|
TypeAssertExpr =
|
|
X ".(" Type ")";
|
|
|
|
CallExpr =
|
|
Fun "(" {Args} ")";
|
|
|
|
StarExpr =
|
|
"*" X;
|
|
|
|
UnaryExpr =
|
|
Op X;
|
|
|
|
BinaryExpr =
|
|
X Op Y;
|
|
|
|
KeyValueExpr =
|
|
Key ": " Value;
|
|
|
|
ArrayType =
|
|
"[" Len "]" Elt;
|
|
|
|
SliceType =
|
|
"[]" Elt;
|
|
|
|
StructType =
|
|
"struct {\n"
|
|
"}";
|
|
|
|
FuncType =
|
|
"(" {Params " "} ")";
|
|
|
|
// BUG take this one away and the code crashes
|
|
InterfaceType =
|
|
"interface {}";
|
|
|
|
MapType =
|
|
"map[" Key "]" Value;
|
|
|
|
ChanType =
|
|
"chan";
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Statements
|
|
|
|
BadStmt =
|
|
"BAD STMT";
|
|
|
|
DeclStmt =
|
|
Decl;
|
|
|
|
EmptyStmt =
|
|
;
|
|
|
|
LabeledStmt =
|
|
Label ":\t" Stmt;
|
|
|
|
ExprStmt =
|
|
X;
|
|
|
|
IncDecStmt =
|
|
X Tok;
|
|
|
|
AssignStmt =
|
|
"assignment " {Lhs ", "};
|
|
//{Lhs ", "} Tok {Rhs ", "};
|
|
|
|
GoStmt =
|
|
"go " Call;
|
|
|
|
ReturnStmt =
|
|
"return" {" " Results};
|
|
|
|
BranchStmt =
|
|
Tok [" " Label];
|
|
|
|
BlockStmt =
|
|
"{\n" {List ";\n"} "}\n";
|
|
|
|
IfStmt =
|
|
"if " "{" [Body] "}" [Else];
|
|
|
|
SwitchStmt =
|
|
"switch {}";
|
|
|
|
TypeSwitchStmt =
|
|
"switch {}";
|
|
|
|
SelectStmt =
|
|
"select {}";
|
|
|
|
ForStmt =
|
|
"for {}";
|
|
|
|
RangeStmt =
|
|
"range";
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Declarations
|
|
|
|
Spec =
|
|
*;
|
|
|
|
ImportSpec =
|
|
"import";
|
|
|
|
ValueSpec =
|
|
"value";
|
|
|
|
TypeSpec =
|
|
"type";
|
|
|
|
BadDecl =
|
|
"BAD DECL";
|
|
|
|
GenDecl =
|
|
Doc
|
|
Tok " (\n"
|
|
")\n";
|
|
|
|
FuncDecl =
|
|
"func " ["(" Recv ") "] Name Type [" " Body];
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Program
|
|
|
|
Program =
|
|
Doc
|
|
"package " Name "\n\n"
|
|
{Decls "\n\n"};
|