From 3ffd391d7fa3e774056555abd53156bb535d0c39 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Wed, 17 Mar 2021 08:45:31 -0700 Subject: [PATCH] Use semicolon instead of do/end as paren disambiguation. It's just clearer what it's there for, and it shouldn't give luacheck warnings. --- src/fennel/compiler.fnl | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/fennel/compiler.fnl b/src/fennel/compiler.fnl index 8709e6a..65f40cf 100644 --- a/src/fennel/compiler.fnl +++ b/src/fennel/compiler.fnl @@ -343,17 +343,18 @@ Tab is what is used to indent a block." (fn keep-side-effects [exprs chunk start ast] "Compile side effects for a chunk." - (let [start (or start 1)] - (for [j start (length exprs)] - (let [se (. exprs j)] - ;; Avoid the rogue 'nil' expression (nil is usually a literal, - ;; but becomes an expression if a special form returns 'nil') - (if (and (= se.type :expression) (not= (. se 1) :nil)) - (emit chunk (string.format "do local _ = %s end" (tostring se)) ast) - (= se.type :statement) - (let [code (tostring se)] - (emit chunk - (or (and (= (code:byte) 40) (.. "do end " code)) code) ast))))))) + (for [j (or start 1) (length exprs)] + (let [se (. exprs j)] + ;; Avoid the rogue 'nil' expression (nil is usually a literal, + ;; but becomes an expression if a special form returns 'nil') + (if (and (= se.type :expression) (not= (. se 1) :nil)) + (emit chunk (string.format "do local _ = %s end" (tostring se)) ast) + (= se.type :statement) + (let [code (tostring se) + ;; without the semicolon, parens can be misinterpreted + ;; as a function call rather than being used for grouping. + unambiguous-code (if (= (code:byte) 40) (.. "; " code) code)] + (emit chunk unambiguous-code ast)))))) (fn handle-compile-opts [exprs parent opts ast] "Does some common handling of returns and register targets for special -- 2.38.5