Skip to content

Instantly share code, notes, and snippets.

@TinoDidriksen
Created March 27, 2025 10:56
Show Gist options
  • Select an option

  • Save TinoDidriksen/889ffb7d0b27565ea70d2d4aeef519a6 to your computer and use it in GitHub Desktop.

Select an option

Save TinoDidriksen/889ffb7d0b27565ea70d2d4aeef519a6 to your computer and use it in GitHub Desktop.
"<Abc=def>"
"Abc=def" tags #1->0
"<Abc=def=ghi>"
"Abc=def=ghi" tags #2->0
"<Abc=def=ghi=jkl>"
"Abc=def=ghi=jkl" tags #3->0
"<Abc=def=ghi=jkl=mno>"
"Abc=def=ghi=jkl=mno" tags #4->0
# Base case with 2 tokens
SplitCohort (
"<$1>"v "$3"v <mv-begin> * c->p
"<$2>"v "$4"v <mv-end> * 2->1
) ("<([^=]+)=([^=]+)>"r "([^<][^=]*)=([^=]+)"r) ;
# Split tail if there are 3+ tokens. Temporary MWE- marker.
SplitCohort (
"<MWE-$1>"v "$3"v * c->p
"<$2>"v "$4"v <mv-end> * 2->1
) ("<((?:[^=]+=){2,})([^=]+)>"r "((?:[^<][^=]*=){2,})([^=]+)"r) ;
# Split middle tokens, repeating until 2 remain
SplitCohort Repeat (
"<MWE-$1>"v "$3"v * c->p
"<$2>"v "$4"v * 2->1
) ("<MWE-((?:[^=]+=){2,})([^=]+)=>"r "((?:[^<][^=]*=){2,})([^=]+)="r) ;
# Final split. Removes MWE- marker.
SplitCohort (
"<$1>"v "$3"v <mv-begin> * c->p
"<$2>"v "$4"v * 2->1
) ("<MWE-([^=]+)=([^=]+)=>"r "([^<][^=]*)=([^=]+)="r) ;
; "<Abc=def>"
; "Abc=def" tags SPLITCOHORT:2
"<Abc>"
"Abc" <mv-begin> tags #1->0 SPLITCOHORT:2
"<def>"
"def" <mv-end> tags #2->1 SPLITCOHORT:2
; "<Abc=def=ghi>"
; "Abc=def=ghi" tags SPLITCOHORT:8
; "<MWE-Abc=def=>"
; "Abc=def=" tags SPLITCOHORT:8 SPLITCOHORT:20
"<Abc>"
"Abc" <mv-begin> tags #3->0 SPLITCOHORT:20
"<def>"
"def" tags #4->3 SPLITCOHORT:20
"<ghi>"
"ghi" <mv-end> tags #5->3 SPLITCOHORT:8
; "<Abc=def=ghi=jkl>"
; "Abc=def=ghi=jkl" tags SPLITCOHORT:8
; "<MWE-Abc=def=ghi=>"
; "Abc=def=ghi=" tags SPLITCOHORT:8 SPLITCOHORT:14
; "<MWE-Abc=def=>"
; "Abc=def=" tags SPLITCOHORT:14 SPLITCOHORT:20
"<Abc>"
"Abc" <mv-begin> tags #6->0 SPLITCOHORT:20
"<def>"
"def" tags #7->6 SPLITCOHORT:20
"<ghi>"
"ghi" tags #8->6 SPLITCOHORT:14
"<jkl>"
"jkl" <mv-end> tags #9->6 SPLITCOHORT:8
; "<Abc=def=ghi=jkl=mno>"
; "Abc=def=ghi=jkl=mno" tags SPLITCOHORT:8
; "<MWE-Abc=def=ghi=jkl=>"
; "Abc=def=ghi=jkl=" tags SPLITCOHORT:8 SPLITCOHORT:14
; "<MWE-Abc=def=ghi=>"
; "Abc=def=ghi=" tags SPLITCOHORT:14 SPLITCOHORT:14
; "<MWE-Abc=def=>"
; "Abc=def=" tags SPLITCOHORT:14 SPLITCOHORT:20
"<Abc>"
"Abc" <mv-begin> tags #10->0 SPLITCOHORT:20
"<def>"
"def" tags #11->10 SPLITCOHORT:20
"<ghi>"
"ghi" tags #12->10 SPLITCOHORT:14
"<jkl>"
"jkl" tags #13->10 SPLITCOHORT:14
"<mno>"
"mno" <mv-end> tags #14->10 SPLITCOHORT:8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment