Skip to content

Commit

Permalink
parser: handle macros with named variable argument
Browse files Browse the repository at this point in the history
GCC and Clang support named variable argument FOO(args...) in addition
to the standard FOO(...) and __VA_ARGS__. Handle it properly.

Simply gather and concatenate all the tokens until the next "," or
")". The parsing remains rather simplistic.
  • Loading branch information
jnikula committed Mar 24, 2024
1 parent fd55c0e commit 54f0db9
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/hawkmoth/doccursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,19 @@ def _get_macro_args(self):
return None

# Naïve parsing of macro arguments
# FIXME: This doesn't handle GCC named vararg extension FOO(vararg...)
args = []
arg_spellings = []
for token in tokens:
if token.spelling == ')':
return args
elif token.spelling == ',':
if token.spelling in [')', ',']:
if arg_spellings:
args.extend([('', ''.join(arg_spellings))])
arg_spellings = []

if token.spelling == ')':
return args
continue
elif token.kind == TokenKind.IDENTIFIER:
args.extend([('', token.spelling)])
elif token.spelling == '...':
args.extend([('', token.spelling)])
elif token.kind == TokenKind.IDENTIFIER or token.spelling == '...':
arg_spellings.append(token.spelling)
else:
break

Expand Down

0 comments on commit 54f0db9

Please sign in to comment.