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
67cbe943
Commit
67cbe943
authored
Mar 06, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/parser: better error sync. if commas are missing
R=rsc, bradfitz CC=golang-dev
https://golang.org/cl/5756045
parent
4f25e4be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
6 deletions
+18
-6
src/pkg/go/parser/parser.go
src/pkg/go/parser/parser.go
+18
-6
No files found.
src/pkg/go/parser/parser.go
View file @
67cbe943
...
...
@@ -362,9 +362,9 @@ func (p *parser) expect(tok token.Token) token.Pos {
// expectClosing is like expect but provides a better error message
// for the common case of a missing comma before a newline.
//
func
(
p
*
parser
)
expectClosing
(
tok
token
.
Token
,
con
struc
t
string
)
token
.
Pos
{
func
(
p
*
parser
)
expectClosing
(
tok
token
.
Token
,
con
tex
t
string
)
token
.
Pos
{
if
p
.
tok
!=
tok
&&
p
.
tok
==
token
.
SEMICOLON
&&
p
.
lit
==
"
\n
"
{
p
.
error
(
p
.
pos
,
"missing ',' before newline in "
+
con
struc
t
)
p
.
error
(
p
.
pos
,
"missing ',' before newline in "
+
con
tex
t
)
p
.
next
()
}
return
p
.
expect
(
tok
)
...
...
@@ -376,6 +376,18 @@ func (p *parser) expectSemi() {
}
}
func
(
p
*
parser
)
seesComma
(
context
string
)
bool
{
if
p
.
tok
==
token
.
COMMA
{
return
true
}
if
p
.
tok
==
token
.
SEMICOLON
&&
p
.
lit
==
"
\n
"
{
p
.
error
(
p
.
pos
,
"missing ',' before newline in "
+
context
)
return
true
// "insert" the comma and continue
}
return
false
}
func
assert
(
cond
bool
,
msg
string
)
{
if
!
cond
{
panic
(
"go/parser internal error: "
+
msg
)
...
...
@@ -647,7 +659,7 @@ func (p *parser) parseVarList(isParam bool) (list []ast.Expr, typ ast.Expr) {
// accept them all for more robust parsing and complain later
for
typ
:=
p
.
parseVarType
(
isParam
);
typ
!=
nil
;
{
list
=
append
(
list
,
typ
)
if
p
.
tok
!=
token
.
COMMA
{
if
!
p
.
seesComma
(
"variable list"
)
{
break
}
p
.
next
()
...
...
@@ -688,7 +700,7 @@ func (p *parser) parseParameterList(scope *ast.Scope, ellipsisOk bool) (params [
// Go spec: The scope of an identifier denoting a function
// parameter or result variable is the function body.
p
.
declare
(
field
,
nil
,
scope
,
ast
.
Var
,
idents
...
)
if
p
.
tok
!=
token
.
COMMA
{
if
!
p
.
seesComma
(
"parameter list"
)
{
break
}
p
.
next
()
...
...
@@ -1078,7 +1090,7 @@ func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr {
ellipsis
=
p
.
pos
p
.
next
()
}
if
p
.
tok
!=
token
.
COMMA
{
if
!
p
.
seesComma
(
"argument list"
)
{
break
}
p
.
next
()
...
...
@@ -1118,7 +1130,7 @@ func (p *parser) parseElementList() (list []ast.Expr) {
for
p
.
tok
!=
token
.
RBRACE
&&
p
.
tok
!=
token
.
EOF
{
list
=
append
(
list
,
p
.
parseElement
(
true
))
if
p
.
tok
!=
token
.
COMMA
{
if
!
p
.
seesComma
(
"composite literal"
)
{
break
}
p
.
next
()
...
...
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