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

Commit

Permalink
Fixes parsing of const defs with separators
Browse files Browse the repository at this point in the history
The Thrift IDL grammar specifies that constant definitions may be terminated with a separator, which was not included in the thriftpy parser.
laserson committed May 29, 2015
1 parent d749d09 commit ecfecb3
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/const.thrift
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@ const double DOUBLE_CONST = 123.456
const string DOUBLE_QUOTED_CONST = "hello"
const string SINGLE_QUOTED_CONST = 'hello'

const string CONST_WITH_SEP1 = "hello",
const string CONST_WITH_SEP2 = "hello";

const list<i32> I32_LIST_CONST = [1, 2, 3]
const list<double> DOUBLE_LIST_CONST = [1.1, 2.2, 3.3]
const list<string> STRING_LIST_CONST = ["hello", "world"]
5 changes: 5 additions & 0 deletions tests/test_const.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,11 @@ def test_string_const():
assert "hello" == const.SINGLE_QUOTED_CONST


def test_const_with_sep():
assert "hello" == const.CONST_WITH_SEP1
assert "hello" == const.CONST_WITH_SEP2


def test_list_const():
assert [1, 2, 3] == const.I32_LIST_CONST
assert [1.1, 2.2, 3.3] == const.DOUBLE_LIST_CONST
3 changes: 2 additions & 1 deletion thriftpy/parser/parser.py
Original file line number Diff line number Diff line change
@@ -91,7 +91,8 @@ def p_definition_unit(p):


def p_const(p):
'''const : CONST field_type IDENTIFIER '=' const_value'''
'''const : CONST field_type IDENTIFIER '=' const_value
| CONST field_type IDENTIFIER '=' const_value sep'''

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

0 comments on commit ecfecb3

Please sign in to comment.