Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Commit ecfecb3

Browse files
committed
Fixes parsing of const defs with separators
The Thrift IDL grammar specifies that constant definitions may be terminated with a separator, which was not included in the thriftpy parser.
1 parent d749d09 commit ecfecb3

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

tests/const.thrift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const double DOUBLE_CONST = 123.456
88
const string DOUBLE_QUOTED_CONST = "hello"
99
const string SINGLE_QUOTED_CONST = 'hello'
1010

11+
const string CONST_WITH_SEP1 = "hello",
12+
const string CONST_WITH_SEP2 = "hello";
13+
1114
const list<i32> I32_LIST_CONST = [1, 2, 3]
1215
const list<double> DOUBLE_LIST_CONST = [1.1, 2.2, 3.3]
1316
const list<string> STRING_LIST_CONST = ["hello", "world"]

tests/test_const.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def test_string_const():
2020
assert "hello" == const.SINGLE_QUOTED_CONST
2121

2222

23+
def test_const_with_sep():
24+
assert "hello" == const.CONST_WITH_SEP1
25+
assert "hello" == const.CONST_WITH_SEP2
26+
27+
2328
def test_list_const():
2429
assert [1, 2, 3] == const.I32_LIST_CONST
2530
assert [1.1, 2.2, 3.3] == const.DOUBLE_LIST_CONST

thriftpy/parser/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def p_definition_unit(p):
9191

9292

9393
def p_const(p):
94-
'''const : CONST field_type IDENTIFIER '=' const_value'''
94+
'''const : CONST field_type IDENTIFIER '=' const_value
95+
| CONST field_type IDENTIFIER '=' const_value sep'''
9596

9697
try:
9798
val = _cast(p[2])(p[5])

0 commit comments

Comments
 (0)