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

Add support for i8 (alias to byte) #296

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/const.thrift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const i16 NEGATIVE_I16 = -10
const double NEGATIVE_DOUBLE = -123.456

const i8 I8_CONST = 10
const i16 I16_CONST = 10
const i32 I32_CONST = 100000
const double DOUBLE_CONST = 123.456
Expand Down
1 change: 1 addition & 0 deletions thriftpy/parser/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
'void',
'bool',
'byte',
'i8',
'i16',
'i32',
'i64',
Expand Down
3 changes: 3 additions & 0 deletions thriftpy/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def p_ref_type(p):
def p_simple_base_type(p): # noqa
'''simple_base_type : BOOL
| BYTE
| I8
| I16
| I32
| I64
Expand All @@ -399,6 +400,8 @@ def p_simple_base_type(p): # noqa
p[0] = TType.BOOL
if p[1] == 'byte':
p[0] = TType.BYTE
if p[1] == 'i8':
Copy link
Contributor

@jparise jparise Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These conditions should probably become elif so we don't continuously reevaluate p[1] after we find a match.

... but that would be better down in a separate change.

p[0] = TType.BYTE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not good to reuse TType.BYTE, as I8 you defined in p_simple_base_type is useless now.

if p[1] == 'i16':
p[0] = TType.I16
if p[1] == 'i32':
Expand Down