aboutsummaryrefslogtreecommitdiff
path: root/module/c/cpp-util.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-14 23:44:03 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-14 23:44:03 +0200
commit64375c16c8316b8381ad59fa3538ad84732d90b7 (patch)
treecec344cb9306f1353ff0c4a4daaf7a81506eef5a /module/c/cpp-util.scm
parentAdd C LALR parser. (diff)
downloadcalp-64375c16c8316b8381ad59fa3538ad84732d90b7.tar.gz
calp-64375c16c8316b8381ad59fa3538ad84732d90b7.tar.xz
work
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))))))