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
ff90d639
Commit
ff90d639
authored
Jun 26, 2015
by
Kenton Varda
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #218 from zarvox/allow_trailing_commas
Allow trailing commas in parenthesized and bracketed lists.
parents
949f7353
9a40b101
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
2 deletions
+24
-2
Makefile.am
c++/Makefile.am
+1
-0
CMakeLists.txt
c++/src/capnp/CMakeLists.txt
+1
-0
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++/Makefile.am
View file @
ff90d639
...
...
@@ -375,6 +375,7 @@ heavy_tests = \
src/capnp/capability-test.c++
\
src/capnp/schema-test.c++
\
src/capnp/schema-loader-test.c++
\
src/capnp/schema-parser-test.c++
\
src/capnp/dynamic-test.c++
\
src/capnp/stringify-test.c++
\
src/capnp/serialize-async-test.c++
\
...
...
c++/src/capnp/CMakeLists.txt
View file @
ff90d639
...
...
@@ -211,6 +211,7 @@ if(BUILD_TESTING)
capability-test.c++
schema-test.c++
schema-loader-test.c++
schema-parser-test.c++
dynamic-test.c++
stringify-test.c++
serialize-async-test.c++
...
...
c++/src/capnp/compiler/lexer-test.c++
View file @
ff90d639
...
...
@@ -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 @
ff90d639
...
...
@@ -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