[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#27659: 26.0.50; Add string-matched-text: string-match + match-string
From: |
Michael Heerdegen |
Subject: |
bug#27659: 26.0.50; Add string-matched-text: string-match + match-string |
Date: |
Sat, 22 Jul 2017 03:46:27 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
Hi Philipp,
nice idea! I have some questions:
+(pcase-defmacro rx (&rest regexps)
+ "Build a `pcase' pattern matching `rx' regexps.
+The REGEXPS are interpreted as by `rx'.
Should we tell what the semantics of multiple REGEXPS is? I guess they
are implicitly wrapped inside rx-`and' (but FWIW, the doc of `rx' also
fails to tell that).
+Within the case code, the match data is bound as usual, but you
This makes it sound like match data is bound pcase-branch-locally.
This isn't the case, right?
+In addition to the usual `rx' constructs, REGEXPS can contain the
+following constructs:
+
+ (let VAR FORM...) creates a new explicitly numbered submatch
+ that matches FORM and binds the match to
+ VAR.
This made me wonder what FORM should be. I think it means any rx
symbolic expression, so the name FORM seems misleading.
+(ert-deftest pcase-tests-rx ()
+ (should (equal (pcase "a 1 2 3 1 b"
+ ((rx (let u (+ digit)) space
+ (let v (+ digit)) space
+ (let v (+ digit)) space
+ (backref-var u))
+ (list u v)))
+ '("1" "3"))))
+
I don't understand the example (or test). Is v first bound to 2, and
after that rebound to 3? This seems at least surprising, since let
behaves differently in pcase, e.g.
(pcase 'foo
((and (let x 1) (let x 2)) x))
==> nil
Hmm, in general I see the risk of confusing this `let' with `pcase' let.
It seems to be something very different. Maybe you could just pick a
different name, `bind' maybe?
Michael.
- bug#27659: 26.0.50; Add string-matched-text: string-match + match-string, (continued)
bug#27659: 26.0.50; Add string-matched-text: string-match + match-string,
Michael Heerdegen <=