mirror of
https://github.com/janet-lang/janet
synced 2025-01-11 08:00:27 +00:00
Add quoted literal support in the match macro.
This commit is contained in:
parent
7205ee5e0a
commit
425a0fcf07
@ -2,6 +2,8 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## ??? - Unreleased
|
## ??? - Unreleased
|
||||||
|
- Allow quoted literals in the `match` macro to behave as expected in patterns.
|
||||||
|
- Fix windows net related bug for TCP servers.
|
||||||
- Allow evaluating ev streams with dofile.
|
- Allow evaluating ev streams with dofile.
|
||||||
- Fix `ev` related bug with operations on already closed file descriptors.
|
- Fix `ev` related bug with operations on already closed file descriptors.
|
||||||
- Add struct and table agnostic `getproto` function.
|
- Add struct and table agnostic `getproto` function.
|
||||||
|
@ -1685,6 +1685,8 @@
|
|||||||
already bound to `<sym>`, rather than matching and rebinding it.
|
already bound to `<sym>`, rather than matching and rebinding it.
|
||||||
|
|
||||||
Any other value pattern will only match if it is equal to `x`.
|
Any other value pattern will only match if it is equal to `x`.
|
||||||
|
Quoting a pattern with `'` will also treat the value as a literal value to match against.
|
||||||
|
|
||||||
```
|
```
|
||||||
[x & cases]
|
[x & cases]
|
||||||
|
|
||||||
@ -1736,6 +1738,10 @@
|
|||||||
(array/push x s)
|
(array/push x s)
|
||||||
(put b2g pattern @[s]))
|
(put b2g pattern @[s]))
|
||||||
|
|
||||||
|
# match quoted literal
|
||||||
|
(and (= t :tuple) (= 2 (length pattern)) (= 'quote (pattern 0)))
|
||||||
|
(break)
|
||||||
|
|
||||||
# match data structure template
|
# match data structure template
|
||||||
(or isarr (= t :struct) (= t :table))
|
(or isarr (= t :struct) (= t :table))
|
||||||
(do
|
(do
|
||||||
@ -1773,6 +1779,10 @@
|
|||||||
# match local binding
|
# match local binding
|
||||||
(= t :symbol) (break)
|
(= t :symbol) (break)
|
||||||
|
|
||||||
|
# match quoted literal
|
||||||
|
(and (= t :tuple) (= 2 (length pattern)) (= 'quote (pattern 0)))
|
||||||
|
(array/push anda ['= s pattern])
|
||||||
|
|
||||||
# match global unification
|
# match global unification
|
||||||
(and (= t :tuple) (= 2 (length pattern)) (= '@ (pattern 0)))
|
(and (= t :tuple) (= 2 (length pattern)) (= '@ (pattern 0)))
|
||||||
(if-let [x (in gun (pattern 1))]
|
(if-let [x (in gun (pattern 1))]
|
||||||
|
@ -348,4 +348,8 @@ neldb\0\0\0\xD8\x05printG\x01\0\xDE\xDE\xDE'\x03\0marshal_tes/\x02
|
|||||||
(assert (deep= @[111] (peg/match '(number :d+) "111")) "simple number capture 1")
|
(assert (deep= @[111] (peg/match '(number :d+) "111")) "simple number capture 1")
|
||||||
(assert (deep= @[255] (peg/match '(number :w+) "0xff")) "simple number capture 2")
|
(assert (deep= @[255] (peg/match '(number :w+) "0xff")) "simple number capture 2")
|
||||||
|
|
||||||
|
# quoted match test
|
||||||
|
(assert (= :yes (match 'john 'john :yes _ :nope)) "quoted literal match 1")
|
||||||
|
(assert (= :nope (match 'john ''john :yes _ :nope)) "quoted literal match 2")
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
Loading…
Reference in New Issue
Block a user