[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Make regexp handling more regular
From: |
Juri Linkov |
Subject: |
Re: Make regexp handling more regular |
Date: |
Thu, 03 Dec 2020 23:02:10 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) |
>>> Currently the match data is like a dynamically bound variable accessible
>>> to the callee. But maybe the match data should be only lexically-bound?
>>> (This is just a vague idea, I don't know how to implement this.)
>> Yes, I wondered whether one could use some lexical magic here, but I
>> didn't quite see what that would look like.
>
> Actually, currently the match-data is *not* like a dynamically-scoped
> var, but like a global var. And we don't really need it to be lexically
> scoped, we would be already well-served with a dynamically-scoped var.
Notably in Ruby e.g. /(.)(.)(.)/.match("foo") returns a MatchData object:
#<MatchData "foo" 1:"f" 2:"o" 3:"o">
Shouldn't a function like string-match (or rather some new function)
return a #<MatchData> object too? Or the current list returned
by the function 'match-data' is sufficient?
Binding it to a variable will avoid the need to have global data
(unless global data is a requirement for performance). Then:
(let ((match-data (string-match regexp string)))
(list (match-beginning subexp match-data)
(match-end subexp match-data)))
with an additional arg MATCH-DATA added to match-processing functions:
(match-beginning SUBEXP &optional MATCH-DATA)
(match-end SUBEXP &optional MATCH-DATA)
(match-string NUM &optional STRING MATCH-DATA)
- Re: Make regexp handling more regular, (continued)
Re: Make regexp handling more regular, Lars Ingebrigtsen, 2020/12/03
Re: Make regexp handling more regular, Daniel MartÃn, 2020/12/02
Re: Make regexp handling more regular, Juri Linkov, 2020/12/02
Re: Make regexp handling more regular, Adam Porter, 2020/12/02