mirror of
https://github.com/janet-lang/janet
synced 2024-12-29 18:00:26 +00:00
add checks to & _ pattern in match macro
This commit adds 2 checks for & rest pattern in the match macro: - & is followed by exactly 1 item - & is followed by a symbol
This commit is contained in:
parent
651e12cfe4
commit
82688b9a44
@ -1760,7 +1760,15 @@
|
||||
(get-length-sym s)
|
||||
(eachp [i sub-pattern] pattern
|
||||
(when (= sub-pattern '&)
|
||||
# TODO: check that & is followed by something
|
||||
(when (<= (length pattern) (inc i))
|
||||
(errorf "expected symbol following & in pattern"))
|
||||
|
||||
(when (< (+ i 2) (length pattern))
|
||||
(errorf "expected a single symbol follow '& in pattern, found %q" (slice pattern (inc i))))
|
||||
|
||||
(when (not= (type (pattern (inc i))) :symbol)
|
||||
(errorf "expected symbol following & in pattern, found %q" (pattern (inc i))))
|
||||
|
||||
(put b2g (pattern (inc i)) @[[slice s i]])
|
||||
(break))
|
||||
(visit-pattern-1 b2g s i sub-pattern)))
|
||||
|
Loading…
Reference in New Issue
Block a user