fix issue with (set (. x y) z)

fennel needs to skip these instead of failing to parse them
This commit is contained in:
XeroOl 2024-06-30 18:37:55 -05:00
parent 0a5ca27dfa
commit 9e9af12f41
2 changed files with 25 additions and 20 deletions

View File

@ -103,12 +103,15 @@ identifiers are declared / referenced in which places."
(if (sym? binding)
(action binding ?definition keys keys.multival)
(list? binding)
(let [nested? (not= depth 0)]
(if nested? (error (.. "I didn't expect to find a nested multival destructure in " (view binding) " at " (view keys))))
(each [i child (ipairs binding)]
(set keys.multival i)
(recurse child keys (+ depth 1))
(set keys.multival nil)))
(let [set-target? (sym? (. binding 1) ".")]
(if set-target?
(action binding ?definition keys keys.multival)
(not= depth 0)
(error (.. "I didn't expect to find a nested multival destructure in " (view binding) " at " (view keys)))
(each [i child (ipairs binding)]
(set keys.multival i)
(recurse child keys (+ depth 1))
(set keys.multival nil))))
(table? binding)
(accumulate [prev nil
key child (iter binding)]
@ -129,22 +132,23 @@ identifiers are declared / referenced in which places."
(λ define [?definition binding scope ?opts]
(for-each-binding-in binding ?definition
(fn [symbol ?definition keys ?multival]
(let [definition
{:binding symbol
:definition ?definition
:referenced-by (or (?. definitions symbol :referenced-by) [])
:keys (if (. keys 1)
(icollect [_ v (ipairs keys)] v))
:multival ?multival
:var? (?. ?opts :isvar)
: file}]
(tset (. definitions-by-scope scope) (tostring symbol) definition)
(tset definitions symbol definition)))))
(when (not (or (list? symbol) (multisym? symbol)))
(let [definition
{:binding symbol
:definition ?definition
:referenced-by (or (?. definitions symbol :referenced-by) [])
:keys (if (. keys 1)
(icollect [_ v (ipairs keys)] v))
:multival ?multival
:var? (?. ?opts :isvar)
: file}]
(tset (. definitions-by-scope scope) (tostring symbol) definition)
(tset definitions symbol definition))))))
(λ mutate [_?definition binding scope]
(for-each-binding-in binding _?definition
(λ mutate [?definition binding scope]
(for-each-binding-in binding ?definition
(fn [symbol _?definition _keys]
(when (not (multisym? symbol))
(when (not (or (list? symbol) (multisym? symbol)))
(reference symbol scope :write)
(if (. references symbol)
(tset (. references symbol :target) :var-set true))))))

View File

@ -40,6 +40,7 @@
(λ test {} nil)
(λ {} nil")
(create-client-with-files "(fn foo []\n #\n (print :test))")
(create-client-with-files "(let [map {}] (set (. map (tostring :a)) :b))")
nil)
(fn test-split-spaces []