aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-06-30 00:20:43 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-07 21:17:22 +0200
commit5aa839f774ea4eac0c919a2bd53e804dea7a06f1 (patch)
tree760725b7d7aa0704d6280c1df2da2c78b015a57c
parentFix C order of operations. (diff)
downloadcalp-5aa839f774ea4eac0c919a2bd53e804dea7a06f1.tar.gz
calp-5aa839f774ea4eac0c919a2bd53e804dea7a06f1.tar.xz
C-parser #define without body.
-rw-r--r--module/c/cpp.scm13
1 files changed, 8 insertions, 5 deletions
diff --git a/module/c/cpp.scm b/module/c/cpp.scm
index 9a8245ad..86130167 100644
--- a/module/c/cpp.scm
+++ b/module/c/cpp.scm
@@ -16,16 +16,19 @@
;; input "#define F(x, y) x + y"
-;; 1 full define | F(x, y)
+;; 1 full define | F(x,y)
;; 2 macro name | F
-;; 3 macro args | (x, y)
-;; 4 macro body | x + y
-(define define-re (make-regexp "^#define ((\\w+)([(][^)]*[)])?) (.*)"))
+;; 3 macro args | (x,y)
+;; 5 macro body | x + y or #f
+(define define-re (make-regexp "^#define ((\\w+)([(][^)]*[)])?)( (.*))?"))
(define (tokenize-define-line header-line)
(aif (regexp-exec define-re header-line)
(cons (match:substring it 1)
- (match:substring it 4))
+ (let ((body (match:substring it 5)))
+ (if (or (eqv? body #f)
+ (string-null? body))
+ "1" body)))
(scm-error 'c-parse-error
"tokenize-define-line"
"Line dosen't match: ~s"