Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
4fb8f44e
Commit
4fb8f44e
authored
Jul 14, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- interface and comments cleanup
R=rsc DELTA=33 (1 added, 3 deleted, 29 changed) OCL=31620 CL=31642
parent
59ee0373
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
28 deletions
+26
-28
parser.go
src/pkg/go/parser/parser.go
+26
-28
No files found.
src/pkg/go/parser/parser.go
View file @
4fb8f44e
...
@@ -2003,17 +2003,18 @@ func (p *parser) init(filename string, src interface{}, mode uint) os.Error {
...
@@ -2003,17 +2003,18 @@ func (p *parser) init(filename string, src interface{}, mode uint) os.Error {
// Parse parses a Go program.
// Parse parses a Go program.
//
//
// The program source src may be provided in a variety of formats. At the
// The filename is only used in AST position information and error messages
// moment the following types are supported: string, []byte, and io.Reader.
// and may be empty. The program source src may be provided in a variety of
// The mode parameter controls the amount of source text parsed and other
// formats. At the moment the following types are supported: string, []byte,
// optional parser functionality.
// and io.Reader. The mode parameter controls the amount of source text parsed
// and other optional parser functionality.
//
//
// Parse returns a complete AST if no error occured. Otherwise, if the
// Parse returns a complete AST if no error occured. Otherwise, if the
// source couldn't be read, the returned program is nil and the error
// source couldn't be read, the returned program is nil and the error
// indicates the specific failure. If the source was read but syntax
// indicates the specific failure. If the source was read but syntax
// errors were found, the result is a partial AST (with ast.BadX nodes
// errors were found, the result is a partial AST (with ast.BadX nodes
// representing the fragments of erroneous source code)
and an ErrorList
// representing the fragments of erroneous source code)
. Multiple errors
//
describing the syntax errors
.
//
are returned via a scanner.ErrorList which is sorted by file position
.
//
//
func
Parse
(
filename
string
,
src
interface
{},
mode
uint
)
(
*
ast
.
Program
,
os
.
Error
)
{
func
Parse
(
filename
string
,
src
interface
{},
mode
uint
)
(
*
ast
.
Program
,
os
.
Error
)
{
var
p
parser
;
var
p
parser
;
...
@@ -2021,41 +2022,38 @@ func Parse(filename string, src interface{}, mode uint) (*ast.Program, os.Error)
...
@@ -2021,41 +2022,38 @@ func Parse(filename string, src interface{}, mode uint) (*ast.Program, os.Error)
return
nil
,
err
;
return
nil
,
err
;
}
}
prog
:=
p
.
parsePackage
();
prog
:=
p
.
parsePackage
();
// TODO 6g bug - function call order in expr lists
return
prog
,
p
.
GetError
(
scanner
.
NoMultiples
);
return
prog
,
p
.
GetError
(
scanner
.
NoMultiples
);
}
}
// ParseStmts parses a list of Go statement
.
// ParseStmts parses a list of Go statement
s and returns the list of
func
ParseStmts
(
filename
string
,
src
interface
{},
mode
uint
)
([]
ast
.
Stmt
,
os
.
Error
)
{
// corresponding AST nodes. The filename and src arguments have the
if
mode
&
(
PackageClauseOnly
|
ImportsOnly
)
!=
0
{
// same interpretation as for Parse. If there is an error, the node
return
nil
,
nil
;
// list may be nil or contain partial ASTs.
}
//
func
ParseStmts
(
filename
string
,
src
interface
{})
([]
ast
.
Stmt
,
os
.
Error
)
{
var
p
parser
;
var
p
parser
;
if
err
:=
p
.
init
(
filename
,
src
,
mode
);
err
!=
nil
{
if
err
:=
p
.
init
(
filename
,
src
,
0
);
err
!=
nil
{
return
nil
,
err
;
return
nil
,
err
;
}
}
stmts
:=
p
.
parseStatementList
();
list
:=
p
.
parseStatementList
();
// TODO 6g bug - function call order in expr lists
return
list
,
p
.
GetError
(
scanner
.
Sorted
);
return
stmts
,
p
.
GetError
(
scanner
.
Sorted
);
}
}
// ParseExpr parses a single Go expression
.
// ParseExpr parses a single Go expression
and returns the corresponding
func
ParseExpr
(
filename
string
,
src
interface
{},
mode
uint
)
(
ast
.
Expr
,
os
.
Error
)
{
// AST node. The filename and src arguments have the same interpretation
if
mode
&
(
PackageClauseOnly
|
ImportsOnly
)
!=
0
{
// as for Parse. If there is an error, the result expression may be nil
return
nil
,
nil
;
// or contain a partial AST.
}
//
func
ParseExpr
(
filename
string
,
src
interface
{})
(
ast
.
Expr
,
os
.
Error
)
{
var
p
parser
;
var
p
parser
;
if
err
:=
p
.
init
(
filename
,
src
,
mode
);
err
!=
nil
{
if
err
:=
p
.
init
(
filename
,
src
,
0
);
err
!=
nil
{
return
nil
,
err
;
return
nil
,
err
;
}
}
expr
:=
p
.
parseExpression
();
x
:=
p
.
parseExpression
();
// TODO 6g bug - function call order in expr lists
return
x
,
p
.
GetError
(
scanner
.
Sorted
);
return
expr
,
p
.
GetError
(
scanner
.
Sorted
);
}
}
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