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
e7d513ea
Commit
e7d513ea
authored
Jan 24, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/parser: Use explicit parser.Mode type.
R=r, bradfitz CC=golang-dev
https://golang.org/cl/5574058
parent
324513bc
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
11 deletions
+16
-11
src/cmd/cgo/ast.go
src/cmd/cgo/ast.go
+1
-1
src/cmd/godoc/parser.go
src/cmd/godoc/parser.go
+1
-1
src/cmd/gofmt/gofmt.go
src/cmd/gofmt/gofmt.go
+2
-2
src/pkg/go/parser/interface.go
src/pkg/go/parser/interface.go
+10
-5
src/pkg/go/parser/parser.go
src/pkg/go/parser/parser.go
+2
-2
No files found.
src/cmd/cgo/ast.go
View file @
e7d513ea
...
...
@@ -16,7 +16,7 @@ import (
"strings"
)
func
parse
(
name
string
,
flags
uint
)
*
ast
.
File
{
func
parse
(
name
string
,
flags
parser
.
Mode
)
*
ast
.
File
{
ast1
,
err
:=
parser
.
ParseFile
(
fset
,
name
,
nil
,
flags
)
if
err
!=
nil
{
if
list
,
ok
:=
err
.
(
scanner
.
ErrorList
);
ok
{
...
...
src/cmd/godoc/parser.go
View file @
e7d513ea
...
...
@@ -17,7 +17,7 @@ import (
"path/filepath"
)
func
parseFile
(
fset
*
token
.
FileSet
,
filename
string
,
mode
uint
)
(
*
ast
.
File
,
error
)
{
func
parseFile
(
fset
*
token
.
FileSet
,
filename
string
,
mode
parser
.
Mode
)
(
*
ast
.
File
,
error
)
{
src
,
err
:=
ReadFile
(
fs
,
filename
)
if
err
!=
nil
{
return
nil
,
err
...
...
src/cmd/gofmt/gofmt.go
View file @
e7d513ea
...
...
@@ -44,7 +44,7 @@ var (
fset
=
token
.
NewFileSet
()
exitCode
=
0
rewrite
func
(
*
ast
.
File
)
*
ast
.
File
parserMode
uint
parserMode
parser
.
Mode
printerMode
uint
)
...
...
@@ -60,7 +60,7 @@ func usage() {
}
func
initParserMode
()
{
parserMode
=
uint
(
0
)
parserMode
=
parser
.
Mode
(
0
)
if
*
comments
{
parserMode
|=
parser
.
ParseComments
}
...
...
src/pkg/go/parser/interface.go
View file @
e7d513ea
...
...
@@ -45,12 +45,14 @@ func readSource(filename string, src interface{}) ([]byte, error) {
return
ioutil
.
ReadFile
(
filename
)
}
//
The mode parameter to the Parse* functions
is a set of flags (or 0).
//
A Mode value
is a set of flags (or 0).
// They control the amount of source code parsed and other optional
// parser functionality.
//
type
Mode
uint
const
(
PackageClauseOnly
uint
=
1
<<
iota
// parsing stops after package clause
PackageClauseOnly
Mode
=
1
<<
iota
// parsing stops after package clause
ImportsOnly
// parsing stops after import declarations
ParseComments
// parse comments and add them to AST
Trace
// print a trace of parsed productions
...
...
@@ -77,7 +79,7 @@ const (
// representing the fragments of erroneous source code). Multiple errors
// are returned via a scanner.ErrorList which is sorted by file position.
//
func
ParseFile
(
fset
*
token
.
FileSet
,
filename
string
,
src
interface
{},
mode
uint
)
(
*
ast
.
File
,
error
)
{
func
ParseFile
(
fset
*
token
.
FileSet
,
filename
string
,
src
interface
{},
mode
Mode
)
(
*
ast
.
File
,
error
)
{
text
,
err
:=
readSource
(
filename
,
src
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -97,7 +99,7 @@ func ParseFile(fset *token.FileSet, filename string, src interface{}, mode uint)
// returned. If a parse error occurred, a non-nil but incomplete map and the
// first error encountered are returned.
//
func
ParseDir
(
fset
*
token
.
FileSet
,
path
string
,
filter
func
(
os
.
FileInfo
)
bool
,
mode
uint
)
(
pkgs
map
[
string
]
*
ast
.
Package
,
first
error
)
{
func
ParseDir
(
fset
*
token
.
FileSet
,
path
string
,
filter
func
(
os
.
FileInfo
)
bool
,
mode
Mode
)
(
pkgs
map
[
string
]
*
ast
.
Package
,
first
error
)
{
fd
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -117,7 +119,10 @@ func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, m
name
:=
src
.
Name
.
Name
pkg
,
found
:=
pkgs
[
name
]
if
!
found
{
pkg
=
&
ast
.
Package
{
name
,
nil
,
nil
,
make
(
map
[
string
]
*
ast
.
File
)}
pkg
=
&
ast
.
Package
{
Name
:
name
,
Files
:
make
(
map
[
string
]
*
ast
.
File
),
}
pkgs
[
name
]
=
pkg
}
pkg
.
Files
[
filename
]
=
src
...
...
src/pkg/go/parser/parser.go
View file @
e7d513ea
...
...
@@ -23,7 +23,7 @@ type parser struct {
scanner
scanner
.
Scanner
// Tracing/debugging
mode
uint
// parsing mode
mode
Mode
// parsing mode
trace
bool
// == (mode & Trace != 0)
indent
uint
// indentation used for tracing output
...
...
@@ -52,7 +52,7 @@ type parser struct {
targetStack
[][]
*
ast
.
Ident
// stack of unresolved labels
}
func
(
p
*
parser
)
init
(
fset
*
token
.
FileSet
,
filename
string
,
src
[]
byte
,
mode
uint
)
{
func
(
p
*
parser
)
init
(
fset
*
token
.
FileSet
,
filename
string
,
src
[]
byte
,
mode
Mode
)
{
p
.
file
=
fset
.
AddFile
(
filename
,
fset
.
Base
(),
len
(
src
))
var
m
uint
if
mode
&
ParseComments
!=
0
{
...
...
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