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
fda1d169
Commit
fda1d169
authored
Jul 23, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- parsing support for composite literals
R=r OCL=13394 CL=13394
parent
b0ada5dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
5 deletions
+81
-5
parser.go
usr/gri/gosrc/parser.go
+81
-5
No files found.
usr/gri/gosrc/parser.go
View file @
fda1d169
...
...
@@ -474,6 +474,7 @@ func (P *Parser) ParseNamedSignature() (name string, typ *Globals.Type) {
P
.
TryResult
();
P
.
CloseScope
();
P
.
Ecart
();
return
name
,
MakeFunctionType
(
sig
,
p0
,
r0
,
true
);
}
...
...
@@ -684,12 +685,82 @@ func (P *Parser) ParseFunctionLit() {
}
func
(
P
*
Parser
)
ParseExpressionPair
()
{
P
.
Trace
(
"ExpressionPair"
);
P
.
ParseExpression
();
P
.
Expect
(
Scanner
.
COLON
);
P
.
ParseExpression
();
P
.
Ecart
();
}
func
(
P
*
Parser
)
ParseExpressionPairList
()
{
P
.
Trace
(
"ExpressionPairList"
);
P
.
ParseExpressionPair
();
for
(
P
.
tok
==
Scanner
.
COMMA
)
{
P
.
ParseExpressionPair
();
}
P
.
Ecart
();
}
func
(
P
*
Parser
)
ParseCompositeLit
(
typ
*
Globals
.
Type
)
{
P
.
Trace
(
"CompositeLit"
);
// TODO I think we should use {} instead of () for
// composite literals to syntactically distinguish
// them from conversions. For now: allow both.
var
paren
int
;
if
P
.
tok
==
Scanner
.
LPAREN
{
P
.
Next
();
paren
=
Scanner
.
RPAREN
;
}
else
{
P
.
Expect
(
Scanner
.
LBRACE
);
paren
=
Scanner
.
RBRACE
;
}
// TODO: should allow trailing ','
if
P
.
tok
!=
paren
{
P
.
ParseExpression
();
if
P
.
tok
==
Scanner
.
COMMA
{
P
.
Next
();
if
P
.
tok
!=
paren
{
P
.
ParseExpressionList
();
}
}
else
if
P
.
tok
==
Scanner
.
COLON
{
P
.
Next
();
P
.
ParseExpression
();
if
P
.
tok
==
Scanner
.
COMMA
{
P
.
Next
();
if
P
.
tok
!=
paren
{
P
.
ParseExpressionPairList
();
}
}
}
}
P
.
Expect
(
paren
);
P
.
Ecart
();
}
func
(
P
*
Parser
)
ParseOperand
()
{
P
.
Trace
(
"Operand"
);
switch
P
.
tok
{
case
Scanner
.
IDENT
:
P
.
ParseQualifiedIdent
();
// TODO enable code below
/*
if obj.kind == Object.TYPE {
P.ParseCompositeLit(obj.typ);
}
*/
case
Scanner
.
LPAREN
:
P
.
Next
();
P
.
ParseExpression
();
...
...
@@ -706,8 +777,13 @@ func (P *Parser) ParseOperand() {
case
Scanner
.
NEW
:
P
.
ParseNew
();
default
:
P
.
Error
(
P
.
pos
,
"operand expected"
);
P
.
Next
();
// make progress
typ
:=
P
.
TryType
();
if
typ
!=
nil
{
P
.
ParseCompositeLit
(
typ
);
}
else
{
P
.
Error
(
P
.
pos
,
"operand expected"
);
P
.
Next
();
// make progress
}
}
P
.
Ecart
();
...
...
@@ -863,7 +939,7 @@ func (P *Parser) ParseExpression() {
P
.
ParseBinaryExpr
(
1
);
if
indent
!=
P
.
indent
{
panic
"imbalanced tracing code"
;
panic
"imbalanced tracing code
(Expression)
"
;
}
P
.
Ecart
();
}
...
...
@@ -1194,7 +1270,7 @@ func (P *Parser) TryStatement() bool {
}
if
indent
!=
P
.
indent
{
panic
"imbalanced tracing code"
panic
"imbalanced tracing code
(Statement)
"
}
P
.
Ecart
();
return
res
;
...
...
@@ -1431,7 +1507,7 @@ func (P *Parser) ParseDeclaration() {
P
.
Next
();
// make progress
}
if
indent
!=
P
.
indent
{
panic
"imbalanced tracing code"
panic
"imbalanced tracing code
(Declaration)
"
}
P
.
Ecart
();
...
...
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