lambdaisland / lambdaisland/regal
Support backreferences
Nobody has claimed this yet.
- Dominant language
- Clojure
- Stars
- 345
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
As discussed on the lambdaisland channel of the clojurians slack (https://clojurians.slack.com/archives/C1DV21X9P/p1643329544995089)
I'm trying to replicate this in regal using a backrefernce to match any 3 or more of the same consecutive character:
;;=> ["1111" "1"]``` But can't seem to get it: ```(regal/regex [:cat [:capture :any] [:repeat ::_ 3 nil]] {:resolver (fn [x] "\\1")}) ;;=> #"(.)(?:\\1){3,}" (regal/regex [:capture [:capture :any] [:repeat ::_ 3 nil]] {:resolver (fn [x] "\1")}) ;;=> #"((.){3,})" (regal/regex [:capture [:capture :any] [:repeat ::_ 3 nil]] {:resolver (fn [x] "\\\\1")}) ;;=> #"((.)(?:\\\\1){3,})"``` Any tips?
@plexus Responded:
(ns repl-sessions.poke (:require [lambdaisland.regal :as regal] [lambdaisland.regal.parse :as regal-parse])) (regal-parse/parse #"(.)\1{3,}") ;; => [:cat ;; [:capture :any] ;; [:repeat [:lambdaisland.regal.parse/not-implemented [:BackReference "1"]] 3]]backreferences aren't implemented, but seems like a common enough feature that they should be. Would you mind creating a ticket?
here's a workaround you can do yourself:
(defmethod regal/-regal->ir [:ref :common] [[op idx] opts] `^::regal/grouped ("\\" ~(str idx))) (regal/regex [:cat [:capture :any] [:repeat [:ref 1] 3 nil]]) ;; => #"(.)\1{3,}"
It was also questioned if all engines, Java, ECMA, Re2 support this. It looks the like the first two do but Re2 doesn't
https://github.com/google/re2/issues/101
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with regal-parse/parse and the parsed :BackReference example, then inspect how regal emits regexes through regal/-regal->ir. Check Java, ECMA, and Re2 behavior described in the issue; done means backreferences are represented and emitted correctly where supported, with unsupported engines handled explicitly.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 34/100