Skip to content

Commit 650589f

Browse files
cgeweckefedericobond
authored andcommitted
Parse function calls that use a name-value list
1 parent 0c8208c commit 650589f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

solidity.pegjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,31 @@ Arguments
657657
= "(" __ args:(ArgumentList __)? ")" {
658658
return optionalList(extractOptional(args, 0));
659659
}
660+
/ "(" __ "{" __ args:(NameValueList __ )? "}" __ ")" {
661+
return optionalList(extractOptional(args, 0));
662+
}
660663

661664
ArgumentList
662665
= head:AssignmentExpression tail:(__ "," __ AssignmentExpression)* {
663666
return buildList(head, tail, 3);
664667
}
665668

669+
NameValueList
670+
= head:NameValueAssignment tail:(__ "," __ NameValueAssignment)* {
671+
return buildList(head, tail, 3);
672+
}
673+
674+
NameValueAssignment
675+
= name:Identifier __ ":" __ value:AssignmentExpression __ {
676+
return {
677+
type: "NameValueAssignment",
678+
name: name,
679+
value: value,
680+
start: location().start.offset,
681+
end: location().end.offset
682+
};
683+
}
684+
666685
LeftHandSideExpression
667686
= DeclarativeExpression
668687
/ CallExpression

test/doc_examples.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,22 @@ contract TypeIndexSpacing {
366366
uint [ 7 ] x;
367367
uint [] y;
368368
}
369+
370+
contract Ballot {
371+
372+
struct Voter {
373+
uint weight;
374+
bool voted;
375+
}
376+
377+
function abstain() returns (bool) {
378+
return false;
379+
}
380+
381+
Voter you = Voter(1, true);
382+
383+
Voter me = Voter({
384+
weight: 2,
385+
voted: abstain()
386+
});
387+
}

0 commit comments

Comments
 (0)