diff options
Diffstat (limited to 'module/c/cpp-types.scm')
-rw-r--r-- | module/c/cpp-types.scm | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/module/c/cpp-types.scm b/module/c/cpp-types.scm index b08e9810..6dad061e 100644 --- a/module/c/cpp-types.scm +++ b/module/c/cpp-types.scm @@ -2,6 +2,7 @@ :use-module (c lex2) :use-module (ice-9 match) :use-module (c cpp-util) + :use-module (hnh util type) :export (whitespace-token? comment-token? preprocessing-token? @@ -15,6 +16,9 @@ h-string-token? q-string-token? character-constant? + comment->whitespace + comments->whitespace + make-string-literal )) (define (whitespace-token? x) @@ -59,29 +63,32 @@ (`(pp-number ,x) x) (_ #f)))) -;; TODO this fails if there are multiple components in the string token ;; TODO rename to string-literal-token? (define (string-token? token) (and (preprocessing-token? token) (match (lexeme-body token) - (`(string-literal ,x) x) + (('string-literal x ...) (apply values x)) (_ #f)))) (define (character-constant? token) (and (preprocessing-token? token) (match (lexeme-body token) - (`(character-constant ,x) x) + (('character-constant x ...) (apply values x)) (_ #f)))) (define (h-string-token? token) (and (preprocessing-token? token) (match (lexeme-body token) - (`(h-string ,x) x) + (`(header-name (h-string ,x)) x) (_ #f)))) +;; NOTE q-string tokens are never produced by the lexer, +;; since they instead are treated as regular strings (define (q-string-token? token) - (and (preprocessing-token? token) - (match (lexeme-body token) - (`(q-string ,x) x) - (_ #f)))) + (string-token? token)) + +(define (make-string-literal parts) + (typecheck parts (list-of (or string? list?))) + (lexeme type: 'preprocessing-token + body: (cons 'string-literal parts))) |