Skip to content

Commit

Permalink
scrooge: fix handling of the function separator
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chenzhuoyu authored and jenkins committed Apr 16, 2020
1 parent 8d995d7 commit b72a08c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Note that ``PHAB_ID=#`` and ``RB_ID=#`` correspond to associated messages in com
Unreleased
----------

* scrooge-generator: Respect the proper order of separators in function declarations.
``PHAB_ID=D467476``

20.4.0
------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ enum Foo
val code = """
/** cold hard cache */
service Cache {
void put(1: string name, 2: binary value);
void put(1: string name, 2: binary value) (mode="LRU");
binary get(1: string name) throws (1: NotFoundException ex);
}
"""
Expand All @@ -490,7 +490,8 @@ enum Foo
Field(2, SimpleID("value"), "value", TBinary, None, Requiredness.Default)
),
Seq(),
None
None,
Map("mode" -> "LRU")
),
Function(
SimpleID("get"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class ThriftParser(
(opt(comments) ~ (opt("oneway") ~ functionType)) ~ (simpleID <~ "(") ~ (rep(
field
) <~ ")") ~
(opt(throws) <~ opt(listSeparator)) ~ defaultedAnnotations ^^ {
opt(throws) ~ defaultedAnnotations <~ opt(listSeparator) ^^ {
case comment ~ (oneway ~ ftype) ~ id ~ args ~ throws ~ annotations =>
Function(
id,
Expand Down

0 comments on commit b72a08c

Please sign in to comment.