From c1defcf83c0eedd2fc5cf70c43239336d5abf238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 13 Jul 2022 12:46:45 +0200 Subject: Clearen conditional status predicates. --- module/c/preprocessor2.scm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'module/c/preprocessor2.scm') diff --git a/module/c/preprocessor2.scm b/module/c/preprocessor2.scm index 28d11901..6757521f 100644 --- a/module/c/preprocessor2.scm +++ b/module/c/preprocessor2.scm @@ -607,7 +607,7 @@ ;; null directive (loop environment remaining-tokens)) - ((in-comment-block? environment) + ((in-conditional/inactive? environment) (case (string->symbol (identifier-token? (car line-tokens))) ((else) (loop (flip-flop-if environment) remaining-tokens)) ((endif) (loop (leave-if environment) remaining-tokens)) @@ -642,8 +642,14 @@ enter-inactive-if enter-active-if) env))) ;; NOTE possibly validate that body is empty for endif and else - ((endif) (lambda (env _) (leave-if env))) - ((else) (lambda (env _) (flip-flop-if env))) + ((endif) (lambda (env _) + (unless (in-conditional? env) + (err "#endif outside conditional")) + (leave-if env))) + ((else) (lambda (env _) + (unless (in-conditional? env) + (err "#else outside conditional")) + (flip-flop-if env))) ;; ((elif) (lambda )) ((define) resolve-define) ((undef) (lambda (env body) (remove-identifier env (identifier-token? (car body))))) @@ -658,7 +664,7 @@ ;; Line is not a pre-processing directive (else (let ((preceding-tokens remaining-tokens (tokens-until-cpp-directive (cdr tokens)))) - (let* ((env* resolved-tokens (if (in-comment-block? environment) + (let* ((env* resolved-tokens (if (in-conditional/inactive? environment) (values environment '()) (resolve-token-stream environment preceding-tokens)))) (on-snd (append resolved-tokens -- cgit v1.2.3