diff --git a/CHANGELOG.md b/CHANGELOG.md index b9457797..1a848951 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## ??? - 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. - Fix `ev` related bug with operations on already closed file descriptors. - Add struct and table agnostic `getproto` function. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 5639c7d5..54c3bbeb 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1685,6 +1685,8 @@ already bound to ``, rather than matching and rebinding it. 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] @@ -1736,6 +1738,10 @@ (array/push x s) (put b2g pattern @[s])) + # match quoted literal + (and (= t :tuple) (= 2 (length pattern)) (= 'quote (pattern 0))) + (break) + # match data structure template (or isarr (= t :struct) (= t :table)) (do @@ -1773,6 +1779,10 @@ # match local binding (= t :symbol) (break) + # match quoted literal + (and (= t :tuple) (= 2 (length pattern)) (= 'quote (pattern 0))) + (array/push anda ['= s pattern]) + # match global unification (and (= t :tuple) (= 2 (length pattern)) (= '@ (pattern 0))) (if-let [x (in gun (pattern 1))] diff --git a/test/suite0008.janet b/test/suite0008.janet index 3f91ace7..a53b16a4 100644 --- a/test/suite0008.janet +++ b/test/suite0008.janet @@ -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= @[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)