summaryrefslogtreecommitdiff
path: root/cffi/cparser.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2015-07-30 17:05:10 +0200
committerArmin Rigo <arigo@tunes.org>2015-07-30 17:05:10 +0200
commit7fec8108df0d434bcf998c280d7d90d04df1b0b0 (patch)
tree26868e1027e39c3c520509d16b6bb5c99413cb21 /cffi/cparser.py
parent4535619b759c5dfc75ad9c9eca54144864272479 (diff)
downloadcffi-7fec8108df0d434bcf998c280d7d90d04df1b0b0.tar.gz
Support "\" escapes in a #define
Diffstat (limited to 'cffi/cparser.py')
-rw-r--r--cffi/cparser.py6
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__]"