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

Commit

Permalink
Merge pull request #134 from laserson/const_with_sep
Browse files Browse the repository at this point in the history
Fixes parsing of const defs with separators
  • Loading branch information
hit9 committed May 29, 2015
2 parents d749d09 + ecfecb3 commit f3db6de
Show file tree
Hide file tree
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
Expand Up @@ -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"]
Expand Down
5 changes: 5 additions & 0 deletions tests/test_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion thriftpy/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit f3db6de

Please sign in to comment.