~technomancy/fennel

3ffd391d7fa3e774056555abd53156bb535d0c39 — Phil Hagelberg 6 months ago 7c72a7a
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.
1 files changed, 12 insertions(+), 11 deletions(-)

M src/fennel/compiler.fnl
M src/fennel/compiler.fnl => src/fennel/compiler.fnl +12 -11
@@ 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