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
ad8527c4
Commit
ad8527c4
authored
May 21, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjustments for relaxed composite literal syntax
R=r DELTA=41 (0 added, 21 deleted, 20 changed) OCL=29219 CL=29219
parent
f4d3d22a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
30 deletions
+9
-30
src/lib/go/parser/parser.go
src/lib/go/parser/parser.go
+9
-30
No files found.
src/lib/go/parser/parser.go
View file @
ad8527c4
...
...
@@ -984,51 +984,30 @@ func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr {
}
func
(
p
*
parser
)
parse
KeyValueExpr
()
ast
.
Expr
{
func
(
p
*
parser
)
parse
Element
()
ast
.
Expr
{
if
p
.
trace
{
defer
un
(
trace
(
p
,
"
KeyValueExpr
"
));
defer
un
(
trace
(
p
,
"
Element
"
));
}
key
:=
p
.
parseExpression
();
x
:=
p
.
parseExpression
();
if
p
.
tok
==
token
.
COLON
{
colon
:=
p
.
pos
;
p
.
next
();
value
:=
p
.
parseExpression
();
return
&
ast
.
KeyValueExpr
{
key
,
colon
,
value
};
x
=
&
ast
.
KeyValueExpr
{
x
,
colon
,
p
.
parseExpression
()};
}
return
key
;
}
func
isPair
(
x
ast
.
Expr
)
bool
{
tmp
,
is_pair
:=
x
.
(
*
ast
.
KeyValueExpr
);
return
is_pair
;
return
x
;
}
func
(
p
*
parser
)
parseE
xpressionOrKeyValue
List
()
[]
ast
.
Expr
{
func
(
p
*
parser
)
parseE
lement
List
()
[]
ast
.
Expr
{
if
p
.
trace
{
defer
un
(
trace
(
p
,
"E
xpressionOrKeyValue
List"
));
defer
un
(
trace
(
p
,
"E
lement
List"
));
}
var
pairs
bool
;
list
:=
vector
.
New
(
0
);
for
p
.
tok
!=
token
.
RBRACE
&&
p
.
tok
!=
token
.
EOF
{
x
:=
p
.
parseKeyValueExpr
();
if
list
.
Len
()
==
0
{
pairs
=
isPair
(
x
);
}
else
{
// not the first element - check syntax
if
pairs
!=
isPair
(
x
)
{
p
.
error_expected
(
x
.
Pos
(),
"all single expressions or all key-value pairs"
);
}
}
list
.
Push
(
x
);
list
.
Push
(
p
.
parseElement
());
if
p
.
tok
==
token
.
COMMA
{
p
.
next
();
}
else
{
...
...
@@ -1054,7 +1033,7 @@ func (p *parser) parseCompositeLit(typ ast.Expr) ast.Expr {
lbrace
:=
p
.
expect
(
token
.
LBRACE
);
var
elts
[]
ast
.
Expr
;
if
p
.
tok
!=
token
.
RBRACE
{
elts
=
p
.
parseE
xpressionOrKeyValue
List
();
elts
=
p
.
parseE
lement
List
();
}
rbrace
:=
p
.
expect
(
token
.
RBRACE
);
return
&
ast
.
CompositeLit
{
typ
,
lbrace
,
elts
,
rbrace
};
...
...
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