Skip to content

Commit

Permalink
Fix bool constants' values being always parsed as True
Browse files Browse the repository at this point in the history
This fixes issue #34.
  • Loading branch information
Zeex committed Mar 27, 2013
1 parent 438a55a commit d60e3ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 12 additions & 6 deletions cidl/cidl.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,10 @@ def debug(self, msg, *args, **kwargs):
class Parser(object):
keywords = {
'const' : 'CONST',
'false' : 'FALSE',
'true' : 'TRUE'
}

tokens = [
'BOOL',
'FLOAT',
'HEX',
'OCT',
Expand All @@ -339,9 +338,17 @@ class Parser(object):
'RBRACKET',
'EQUALS',
'COMMA',
'SEMICOLON'
'SEMICOLON',
] + list(keywords.values())

def t_BOOL(self, t):
r'(true|false)'
if t.value =='true':
t.value = True
elif t.value == 'false':
t.value = False
return t

def t_FLOAT(self, t):
r'(([0-9]*\.[0-9]*)([eE][+-]?[0-9]+)?|[0-9]+[eE][+-][0-9]+)'
t.value = float(t.value)
Expand Down Expand Up @@ -498,9 +505,8 @@ def p_uchar(self, p):
p[0] = self._value_class('uchar', p[1])

def p_bool(self, p):
"""bool : TRUE
| FALSE"""
p[0] = self._value_class('bool', bool(p[1]))
"""bool : BOOL"""
p[0] = self._value_class('bool', p[1])

def p_string(self, p):
"""string : STRING"""
Expand Down
3 changes: 1 addition & 2 deletions src/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ def gen_callbacks(idl, hdr, src):
if src is not None:
for f in callbacks:
src.write('typedef %s (SAMPGDK_CALLBACK_CALL *%s_type)(%s);\n' % (f.type, f.name, ParamList(f.params)))
src.write('bool %s_handler(AMX *amx, void *callback, cell *retval) {\n' %
f.name)
src.write('bool %s_handler(AMX *amx, void *callback, cell *retval) {\n' % f.name)

badret = f.get_attr('badret')
if badret is not None:
Expand Down

0 comments on commit d60e3ab

Please sign in to comment.