aboutsummaryrefslogtreecommitdiff
path: root/module/c/cpp-util.scm
diff options
context:
space:
mode:
Diffstat (limited to 'module/c/cpp-util.scm')
-rw-r--r--module/c/cpp-util.scm19
1 files changed, 18 insertions, 1 deletions
diff --git a/module/c/cpp-util.scm b/module/c/cpp-util.scm
index 3ea06505..633c5a0c 100644
--- a/module/c/cpp-util.scm
+++ b/module/c/cpp-util.scm
@@ -15,7 +15,8 @@
drop-whitespace-right
drop-whitespace-both
cleanup-whitespace
- concatenate-tokens))
+ concatenate-tokens
+ merge-string-literals))
;; Does the next non-whitespace token in the stream satisfy the predicate?
@@ -109,3 +110,19 @@
(define (concatenate-tokens a b)
(car (lex (string-append (unlex (list a))
(unlex (list b))))))
+
+
+(define (merge-string-literals tokens)
+ (cond ((null? tokens) '())
+ ((null? (cdr tokens)) tokens)
+ ((string-token? (car tokens))
+ (lambda (a . _) a)
+ => (lambda parts-a
+ (cond ((string-token? (cadr tokens))
+ (lambda (a . _) a)
+ => (lambda parts-b (merge-string-literals
+ (cons (make-string-literal (append parts-a parts-b))
+ (cddr tokens)))))
+ (else (cons (car tokens)
+ (merge-string-literals (cdr tokens)))))))
+ (else (cons (car tokens) (merge-string-literals (cdr tokens))))))