Skip to content

Commit

Permalink
Handle some edge cases better
Browse files Browse the repository at this point in the history
Literal :.
Some macros could work like callables.
  • Loading branch information
gilch committed May 30, 2023
1 parent 8b9dd08 commit 72d4864
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions src/hissp/macros.lissp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,43 +2218,44 @@ except ModuleNotFoundError:pass"
(let ($#stack (list $#args))
(.reverse $#stack)
,@(i#starmap
XY#(case X (let (obj (next (.reads reader (.replace X "`" ""))))
`(.append ,'$#stack
,(if-else (|| (literal? obj)
(.startswith Y ",")
(hissp.reader..is_lissp_string obj)
(control-word? obj)
(module-handle? obj)
(quotation? obj))
(if-else (depth Y)
`(op#getitem (.pop ,'$#stack) ,obj)
obj)
(if-else (|| (depth Y) (not (method? obj)))
`(,obj ,@(XYZ#.#"(X+1-Y)*Z"
(depth Y)
(kwargs? Y)
`((.pop ,'$#stack
,(op#sub -1 (kwargs? Y)))))
: ,@(when (kwargs? Y)
`(:** (dict (.pop ,'$#stack)))))
`((op#attrgetter ',.#"obj[1:]")
(.pop ,'$#stack))))))
.#"/" `(.pop ,'$#stack ,(op#sub -1 (depth Y)))
.#"&" `(.append ,'$#stack (,'XY#.#"X[-1-Y]" ,'$#stack ,(depth Y)))
.#"@" `(.append ,'$#stack (.pop ,'$#stack ,(op#sub -2 (depth Y))))
.#"[" `(.append ,'$#stack
(-<>> (tuple (iter ,'$#stack.pop
(getattr unittest.mock..sentinel
"hissp.]")))
,@(when Y `(op#itemgetter
(:<> (,'$#stack.pop))))))
.#"]" `(.insert ,'$#stack
(op#sub (len ,'$#stack) ,(depth Y))
(getattr unittest.mock..sentinel "hissp.]"))
.#"*" `(.extend ,'$#stack
(reversed (tuple (.pop ,'$#stack
,(op#sub -1 (depth Y))))))
: ())
XY#(case X
(let (obj (next (.reads reader (.replace X "`" ""))))
`(.append ,'$#stack
: :? ,(if-else (|| (literal? obj)
(.startswith Y ",")
(hissp.reader..is_lissp_string obj)
(control-word? obj)
(module-handle? obj)
(quotation? obj))
(if-else (depth Y)
`(op#getitem (.pop ,'$#stack) ,obj)
obj)
(if-else (|| (depth Y) (not (method? obj)))
`(,obj ,@(XYZ#.#"(X+1-Y)*Z"
(depth Y)
(kwargs? Y)
`((.pop ,'$#stack
,(op#sub -1 (kwargs? Y)))))
,@(when (kwargs? Y)
`(: :** (dict (.pop ,'$#stack)))))
`((op#attrgetter ',.#"obj[1:]")
(.pop ,'$#stack))))))
.#"/" `(.pop ,'$#stack ,(op#sub -1 (depth Y)))
.#"&" `(.append ,'$#stack (,'XY#.#"X[-1-Y]" ,'$#stack ,(depth Y)))
.#"@" `(.append ,'$#stack (.pop ,'$#stack ,(op#sub -2 (depth Y))))
.#"[" `(.append ,'$#stack
(-<>> (tuple (iter ,'$#stack.pop
(getattr unittest.mock..sentinel
"hissp.]")))
,@(when Y `(op#itemgetter
(:<> (,'$#stack.pop))))))
.#"]" `(.insert ,'$#stack
(op#sub (len ,'$#stack) ,(depth Y))
(getattr unittest.mock..sentinel "hissp.]"))
.#"*" `(.extend ,'$#stack
(reversed (tuple (.pop ,'$#stack
,(op#sub -1 (depth Y))))))
: ())
(reversed (re..findall
"([/&@[\]*:]|(?:[^,%^`/&@[\]*:]|`[,%^/&@[\]*:])+)(%?,?\^*)"
(hissp..demunge s))))
Expand Down

0 comments on commit 72d4864

Please sign in to comment.