diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-25 01:10:29 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-08-18 16:38:37 +0200 |
commit | 8c8ade7167781e074402446c20a5b248d909103e (patch) | |
tree | ec9cd84be8935546a0f1f249dd0e5a164a08d6c8 /module/c/unlex.scm | |
parent | Minor general cleanup. (diff) | |
download | calp-8c8ade7167781e074402446c20a5b248d909103e.tar.gz calp-8c8ade7167781e074402446c20a5b248d909103e.tar.xz |
Properly unlex characters.
Diffstat (limited to '')
-rw-r--r-- | module/c/unlex.scm | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/module/c/unlex.scm b/module/c/unlex.scm index e467a50f..13968698 100644 --- a/module/c/unlex.scm +++ b/module/c/unlex.scm @@ -72,11 +72,32 @@ (`(pp-number ,n) n) - ;; TODO remaining parts - (('character-constant `(character-encoding . ,x) c parts ...) - (format #f "'~a'" c)) + (('character-constant `(character-prefix . ,x) c parts ...) + (with-output-to-string + (lambda () + (unless (null? x) + (display (car x))) + (display #\') + (match c + (`(escape-sequence (simple-escape-sequence ,x)) + (format #t "\\~a" x)) + (`(escape-sequence (octal-escape-sequence ,x)) + (format #t "\\~a" x)) + (`(escape-sequence (octal-escape-sequence ,x)) + (format #t "\\x~a" x)) + (`(escape-sequence (universal-character-name ,x)) + (format #t "\\~a~a" + (case (string-length x) + ((4) #\u) ((8) #\U)) + x)) + (else (display c))) + ;; TODO remaining parts + (display #\')))) - (`(punctuator ,p) p))) + (`(punctuator ,p) p) + (_ (scm-error 'cpp-error "stringify-token" + "No matching patterns for: ~s" + (list preprocessing-token) #f)))) ;; takes a token list, and return a single string literal token (define (stringify-tokens tokens) |