Analyze (include) the same way as (require)

This commit is contained in:
XeroOl 2024-03-01 17:37:32 -06:00
parent be997dc7fb
commit cb8dc29bed
4 changed files with 14 additions and 12 deletions

View File

@ -23,6 +23,7 @@ identifiers are declared / referenced in which places."
;; words surrounded by - are symbols,
;; because fennel doesn't allow 'require in a runtime file
(local -require- (sym :require))
(local -include- (sym :include))
(local -fn- (sym :fn))
(local -lambda- (sym :lambda))
(local -λ- (sym :λ))
@ -224,7 +225,8 @@ identifiers are declared / referenced in which places."
;; TODO check if hashfn needs to be here
(where (or [(= -fn-)] [(= -lambda-)] [(= -λ-)]))
(define-function ast scope)
(where [(= -require-) _modname])
(where (or [(= -require-) _modname]
[(= -include-) _modname]))
(tset require-calls ast true)
;; fennel expands multisym calls into the `:` special, so we need to reference the symbol while we still can
(where [sym] (multisym? sym) (: (tostring sym) :find ":"))

View File

@ -119,7 +119,7 @@ a user-written file.
(if (< multival len)
(search-val self file (. call (+ 1 multival)) stack opts)
(search-multival self file (. call (+ len 1)) stack (+ multival (- len) 1) opts)))
:require
(where (or :require :include))
(let [mod (. call 2)]
(if (= multival 1)
(when (= :string (type mod))

View File

@ -197,6 +197,8 @@
;; steal as many lints as possible from cargo
;; unnecessary parens around single multival destructure
;; unused variable, when a function binding is only used in its body, and the function value is discarded
{: test-compile-error
: test-parse-error
: test-macro-error
@ -204,6 +206,7 @@
: test-unused
: test-ampersand
: test-no-warnings
: test-unknown-module-field
: test-unnecessary-colon
: test-unset-var
: test-unpack-into-op

View File

@ -160,13 +160,12 @@
:main.fnl "(local {: target} (require| :foo))
(target)"})
;; TODO make it work on include
; (check
; {:foo.fnl "(fn target []
; nil)
; =={: target}=="
; :main.fnl "(local {: target} (include| :foo))
; (target)"}))
(check
{:foo.fnl "(fn target []
nil)
=={: target}=="
:main.fnl "(local {: target} (includ|e :foo))
(target)"})
;; TODO fix goto-definition on the module name string itself
; (check
@ -189,15 +188,13 @@
(fn test-no-crash []
;; TODO convert the rest of goto
; ;; (it "can go to a destructured function argument")
(check "(macro cool [a b] `(let [,b 10] ,a))\n(cool |x ==x==)")
(check "(macro cool [a b] `(let [,b 10] ,a))\n(cool x x|)")
(check "|#$..."))
; ;; (it "can go to a destructured function argument")
; ;; (it "can go through more than one file")
; ;; (it "will give up instead of freezing on recursive requires")
; ;; (it "will give up instead of freezing on recursive tables constructed with (set)")