Open pchiusano opened 1 year ago
Some implementation notes of how this could be done. In Util.Text.Pattern.hs
, I'd just change:
-- Stack used to track captures and to support backtracking.
-- A `try` will push a `Mark` that allows the old state
-- (both the list of captures and the current remainder)
-- to be restored on failure.
data Stack = Empty !Captures | Mark !Captures !Text !Stack
-- A difference list for representing the captures of a pattern.
-- So that capture lists can be appended in O(1).
type Captures = [Text] -> [Text]
Change Captures
to [(Text,Word64)] -> [(Text,Word64)]
, then get everything typechecking in that file.
Then tweak the existing Pattern.run
builtin to throw out the starting indices. Then introduce Pattern.run.indexed
.
@runarorama We are re-triaging this and wanted to check the current status.
Have not gotten around to this due to Unison library work
Idea for new builtin, discussed with @runarorama
Returns the starting index of each capture.
Also possible: returns
[(Nat,Nat)]
for the captures (start index and length).