aboutsummaryrefslogtreecommitdiff
path: root/module/c/unlex.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-12 02:37:49 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-12 02:37:49 +0200
commitccc7848110b06479cf8a38ee843d4d3adc01a27c (patch)
tree2db89619c228b5e17f2df5b76b2eaf90060b0928 /module/c/unlex.scm
parentRemove linear update environment procedures. (diff)
downloadcalp-ccc7848110b06479cf8a38ee843d4d3adc01a27c.tar.gz
calp-ccc7848110b06479cf8a38ee843d4d3adc01a27c.tar.xz
work
Diffstat (limited to '')
-rw-r--r--module/c/unlex.scm12
1 files changed, 10 insertions, 2 deletions
diff --git a/module/c/unlex.scm b/module/c/unlex.scm
index 9f4b25b9..18e800d9 100644
--- a/module/c/unlex.scm
+++ b/module/c/unlex.scm
@@ -8,10 +8,17 @@
stringify-token
stringify-tokens))
-;; takes a list of preprocessing-token's, and return a "source" string
(define (unlex tokens)
(typecheck tokens (list-of lexeme?))
(string-concatenate
+ (map (lambda (x) (cond (x preprocessing-token? => stringify-token)
+ ((whitespace-token? x) (lexeme-body x))))
+ tokens)))
+
+;; takes a list of preprocessing-token's, and return a "source" string
+(define (unlex-aggressive tokens)
+ (typecheck tokens (list-of lexeme?))
+ (string-concatenate
(map (lambda (x)
(cond ((preprocessing-token? x) (stringify-token x))
((whitespace-token? x) " ")))
@@ -34,4 +41,5 @@
;; takes a token list, and return a single string literal token
(define (stringify-tokens tokens)
- (lexeme type: 'preprocessing-token body: `(string-literal ,(unlex tokens))))
+ (lexeme type: 'preprocessing-token
+ body: `(string-literal ,(unlex-aggressive tokens))))