Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
aa126447
Commit
aa126447
authored
Jan 15, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added mechanism to detect capitalization issues
Use: pretty -naming files R=r OCL=22859 CL=22859
parent
61f33020
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
6 deletions
+56
-6
usr/gri/pretty/ast.go
usr/gri/pretty/ast.go
+12
-1
usr/gri/pretty/compilation.go
usr/gri/pretty/compilation.go
+4
-2
usr/gri/pretty/parser.go
usr/gri/pretty/parser.go
+38
-2
usr/gri/pretty/pretty.go
usr/gri/pretty/pretty.go
+2
-1
No files found.
usr/gri/pretty/ast.go
View file @
aa126447
...
...
@@ -6,11 +6,13 @@ package AST
import
(
"array"
;
"utf8"
;
"unicode"
;
Scanner
"scanner"
;
)
type
(
export
type
(
Object
struct
;
Type
struct
;
...
...
@@ -65,6 +67,15 @@ export type Object struct {
}
func
(
obj
*
Object
)
IsExported
()
bool
{
switch
obj
.
kind
{
case
NONE
/* FUNC for now */
,
CONST
,
TYPE
,
VAR
,
FUNC
:
ch
,
size
:=
utf8
.
DecodeRuneInString
(
obj
.
ident
,
0
);
return
unicode
.
IsUpper
(
ch
);
}
return
false
;
}
export
var
Universe_void_typ
*
Type
// initialized by Universe to Universe.void_typ
var
ObjectId
int
;
...
...
usr/gri/pretty/compilation.go
View file @
aa126447
...
...
@@ -30,6 +30,7 @@ export type Flags struct {
columns
bool
;
testmode
bool
;
tokenchan
bool
;
naming
bool
;
}
...
...
@@ -90,7 +91,8 @@ func (h *ErrorHandler) ErrorMsg(pos int, msg string) {
h
.
errpos
=
pos
;
if
h
.
nerrors
>=
10
{
sys
.
exit
(
1
);
// TODO enable when done with name convention
//sys.exit(1);
}
}
...
...
@@ -134,7 +136,7 @@ export func Compile(src_file string, flags *Flags) (*AST.Program, int) {
}
var
parser
Parser
.
Parser
;
parser
.
Open
(
flags
.
verbose
,
flags
.
sixg
,
flags
.
deps
,
&
scanner
,
tstream
);
parser
.
Open
(
flags
.
verbose
,
flags
.
sixg
,
flags
.
deps
,
flags
.
naming
,
&
scanner
,
tstream
);
prog
:=
parser
.
ParseProgram
();
...
...
usr/gri/pretty/parser.go
View file @
aa126447
...
...
@@ -13,7 +13,7 @@ import (
export
type
Parser
struct
{
// Tracing/debugging
verbose
,
sixg
,
deps
bool
;
verbose
,
sixg
,
deps
,
naming
bool
;
indent
uint
;
// Scanner
...
...
@@ -109,10 +109,11 @@ func (P *Parser) Next() {
}
func
(
P
*
Parser
)
Open
(
verbose
,
sixg
,
deps
bool
,
scanner
*
Scanner
.
Scanner
,
tokchan
<-
chan
*
Scanner
.
Token
)
{
func
(
P
*
Parser
)
Open
(
verbose
,
sixg
,
deps
,
naming
bool
,
scanner
*
Scanner
.
Scanner
,
tokchan
<-
chan
*
Scanner
.
Token
)
{
P
.
verbose
=
verbose
;
P
.
sixg
=
sixg
;
P
.
deps
=
deps
;
P
.
naming
=
naming
;
P
.
indent
=
0
;
P
.
scanner
=
scanner
;
...
...
@@ -191,6 +192,33 @@ func (P *Parser) Declare(p *AST.Expr, kind int) {
}
func
(
P
*
Parser
)
VerifyExport1
(
p
*
AST
.
Expr
,
exported
bool
)
{
obj
:=
p
.
obj
;
if
exported
{
if
!
obj
.
IsExported
()
{
P
.
Error
(
obj
.
pos
,
`"`
+
obj
.
ident
+
`" should be uppercase`
);
}
}
else
if
P
.
scope_lev
==
0
{
if
obj
.
IsExported
()
{
P
.
Error
(
obj
.
pos
,
`"`
+
obj
.
ident
+
`" should be lowercase`
);
}
}
}
func
(
P
*
Parser
)
VerifyExport
(
p
*
AST
.
Expr
,
exported
bool
)
{
if
!
P
.
naming
{
return
;
}
for
p
.
tok
==
Scanner
.
COMMA
{
P
.
VerifyExport1
(
p
.
x
,
exported
);
p
=
p
.
y
;
}
P
.
VerifyExport1
(
p
,
exported
);
}
// ----------------------------------------------------------------------------
// AST support
...
...
@@ -1510,6 +1538,7 @@ func (P *Parser) ParseConstSpec(exported bool, pos int) *AST.Decl {
}
P
.
Declare
(
d
.
ident
,
AST
.
CONST
);
P
.
VerifyExport
(
d
.
ident
,
exported
);
P
.
Ecart
();
return
d
;
...
...
@@ -1524,6 +1553,8 @@ func (P *Parser) ParseTypeSpec(exported bool, pos int) *AST.Decl {
d
.
typ
=
P
.
ParseType
();
P
.
opt_semi
=
true
;
P
.
VerifyExport
(
d
.
ident
,
exported
);
P
.
Ecart
();
return
d
;
}
...
...
@@ -1546,6 +1577,7 @@ func (P *Parser) ParseVarSpec(exported bool, pos int) *AST.Decl {
}
P
.
Declare
(
d
.
ident
,
AST
.
VAR
);
P
.
VerifyExport
(
d
.
ident
,
exported
);
P
.
Ecart
();
return
d
;
...
...
@@ -1630,6 +1662,10 @@ func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl {
P
.
scope_lev
--
;
}
if
recv
==
nil
||
exported
{
P
.
VerifyExport
(
d
.
ident
,
exported
);
}
P
.
Ecart
();
return
d
;
}
...
...
usr/gri/pretty/pretty.go
View file @
aa126447
...
...
@@ -25,6 +25,7 @@ func init() {
Flag
.
BoolVar
(
&
flags
.
columns
,
"columns"
,
Platform
.
USER
==
"gri"
,
"print column info in error messages"
);
Flag
.
BoolVar
(
&
flags
.
testmode
,
"t"
,
false
,
"test mode: interprets /* ERROR */ and /* SYNC */ comments"
);
Flag
.
BoolVar
(
&
flags
.
tokenchan
,
"token_chan"
,
false
,
"use token channel for scanner-parser connection"
);
Flag
.
BoolVar
(
&
flags
.
naming
,
"naming"
,
false
,
"verify export naming scheme"
);
}
...
...
@@ -54,7 +55,7 @@ func main() {
if
nerrors
>
0
{
return
;
}
if
!*
silent
&&
!
flags
.
testmode
{
if
!
flags
.
naming
&&
!
*
silent
&&
!
flags
.
testmode
{
Printer
.
Print
(
prog
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment