Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
9a40b101
Commit
9a40b101
authored
Jun 22, 2015
by
Drew Fisher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow trailing commas in parenthesized and bracketed lists
And add a test to verify this behavior.
parent
9473dff0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
lexer-test.c++
c++/src/capnp/compiler/lexer-test.c++
+13
-0
lexer.c++
c++/src/capnp/compiler/lexer.c++
+9
-2
No files found.
c++/src/capnp/compiler/lexer-test.c++
View file @
9a40b101
...
...
@@ -146,6 +146,19 @@ TEST(Lexer, Tokens) {
"])"
,
doLex
<
LexedTokens
>
(
"[foo bar, baz qux, corge grault]"
).
cStr
());
// Trailing commas should not create an empty final list item, but be stripped by the lexer.
EXPECT_STREQ
(
"(tokens = ["
"(bracketedList = ["
"["
"(identifier = 'foo', startByte = 1, endByte = 4)"
"], ["
"(identifier = 'bar', startByte = 6, endByte = 9)"
"]"
"], startByte = 0, endByte = 11)"
"])"
,
doLex
<
LexedTokens
>
(
"[foo, bar,]"
).
cStr
());
EXPECT_STREQ
(
"(tokens = ["
"(bracketedList = ["
...
...
c++/src/capnp/compiler/lexer.c++
View file @
9a40b101
...
...
@@ -158,9 +158,16 @@ Lexer::Lexer(Orphanage orphanageParam, ErrorReporter& errorReporter)
// Completely empty list.
return
nullptr
;
}
else
{
auto
result
=
kj
::
heapArrayBuilder
<
kj
::
Array
<
Orphan
<
Token
>>>
(
rest
.
size
()
+
1
);
uint
restSize
=
rest
.
size
();
if
(
rest
.
size
()
>
0
&&
rest
[
restSize
-
1
]
==
nullptr
)
{
// Allow for trailing commas by shortening the list by one item if the final token is
// nullptr
restSize
--
;
}
auto
result
=
kj
::
heapArrayBuilder
<
kj
::
Array
<
Orphan
<
Token
>>>
(
1
+
restSize
);
// first + rest
result
.
add
(
kj
::
mv
(
first
));
for
(
auto
&
item
:
rest
)
{
for
(
uint
i
=
0
;
i
<
restSize
;
i
++
)
{
auto
&
item
=
rest
[
i
];
result
.
add
(
kj
::
mv
(
item
));
}
return
result
.
finish
();
...
...
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