diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-14 23:44:03 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-14 23:44:03 +0200 |
commit | 64375c16c8316b8381ad59fa3538ad84732d90b7 (patch) | |
tree | cec344cb9306f1353ff0c4a4daaf7a81506eef5a /module/c/cpp-util.scm | |
parent | Add C LALR parser. (diff) | |
download | calp-64375c16c8316b8381ad59fa3538ad84732d90b7.tar.gz calp-64375c16c8316b8381ad59fa3538ad84732d90b7.tar.xz |
work
Diffstat (limited to 'module/c/cpp-util.scm')
-rw-r--r-- | module/c/cpp-util.scm | 19 |
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)))))) |