diff options
author | Armin Rigo <arigo@tunes.org> | 2015-07-30 17:05:10 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2015-07-30 17:05:10 +0200 |
commit | 7fec8108df0d434bcf998c280d7d90d04df1b0b0 (patch) | |
tree | 26868e1027e39c3c520509d16b6bb5c99413cb21 /cffi/cparser.py | |
parent | 4535619b759c5dfc75ad9c9eca54144864272479 (diff) | |
download | cffi-7fec8108df0d434bcf998c280d7d90d04df1b0b0.tar.gz |
Support "\" escapes in a #define
Diffstat (limited to 'cffi/cparser.py')
-rw-r--r-- | cffi/cparser.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/cffi/cparser.py b/cffi/cparser.py index 9139798..cba6308 100644 --- a/cffi/cparser.py +++ b/cffi/cparser.py @@ -17,8 +17,9 @@ except ImportError: _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$", re.DOTALL | re.MULTILINE) -_r_define = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)\s+(.*?)$", - re.MULTILINE) +_r_define = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)" + r"\b((?:[^\n\\]|\\.)*?)$", + re.DOTALL | re.MULTILINE) _r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}") _r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$") _r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]") @@ -40,6 +41,7 @@ def _preprocess(csource): macros = {} for match in _r_define.finditer(csource): macroname, macrovalue = match.groups() + macrovalue = macrovalue.replace('\\\n', '').strip() macros[macroname] = macrovalue csource = _r_define.sub('', csource) # Replace "[...]" with "[__dotdotdotarray__]" |