Skip to content

Commit b72a08c

Browse files
chenzhuoyujenkins
authored andcommitted
scrooge: fix handling of the function separator
Problem The thrift parser is not handling optional function separators correctly. The ; or , separator appears AFTER the annotation section, not before it. https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/thrifty.yy#L800 Solution Rearranging the term opt(listSeparator) after defaultedAnnotations solves the problem. Signed-off-by: Bryce Anderson <[email protected]> Differential Revision: https://phabricator.twitter.biz/D467476
1 parent 8d995d7 commit b72a08c

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Note that ``PHAB_ID=#`` and ``RB_ID=#`` correspond to associated messages in com
77
Unreleased
88
----------
99

10+
* scrooge-generator: Respect the proper order of separators in function declarations.
11+
``PHAB_ID=D467476``
12+
1013
20.4.0
1114
------
1215

scrooge-generator-tests/src/test/scala/com/twitter/scrooge/frontend/ThriftParserSpec.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ enum Foo
472472
val code = """
473473
/** cold hard cache */
474474
service Cache {
475-
void put(1: string name, 2: binary value);
475+
void put(1: string name, 2: binary value) (mode="LRU");
476476
binary get(1: string name) throws (1: NotFoundException ex);
477477
}
478478
"""
@@ -490,7 +490,8 @@ enum Foo
490490
Field(2, SimpleID("value"), "value", TBinary, None, Requiredness.Default)
491491
),
492492
Seq(),
493-
None
493+
None,
494+
Map("mode" -> "LRU")
494495
),
495496
Function(
496497
SimpleID("get"),

scrooge-generator/src/main/scala/com/twitter/scrooge/frontend/ThriftParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class ThriftParser(
273273
(opt(comments) ~ (opt("oneway") ~ functionType)) ~ (simpleID <~ "(") ~ (rep(
274274
field
275275
) <~ ")") ~
276-
(opt(throws) <~ opt(listSeparator)) ~ defaultedAnnotations ^^ {
276+
opt(throws) ~ defaultedAnnotations <~ opt(listSeparator) ^^ {
277277
case comment ~ (oneway ~ ftype) ~ id ~ args ~ throws ~ annotations =>
278278
Function(
279279
id,

0 commit comments

Comments
 (0)