Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created January 31, 2014 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grondilu/8743717 to your computer and use it in GitHub Desktop.
Save grondilu/8743717 to your computer and use it in GitHub Desktop.
grammar BraceExpansion {
token TOP { ( <.normalchar>+ | <alt> )* }
token normalchar { \\. | <-[ { , } ]> }
token alt {
'{' ~ '}' <TOP>* % \,
}
}
sub crosswalk($/) {
[X~] $0.map: -> $/ { [$<alt><TOP>».&crosswalk] or ~$/ }
}
sub brace-expand($s) { crosswalk BraceExpansion.parse($s) }
sub bxtest(*@s) {
for @s -> $s {
say "\n$s";
for brace-expand($s) {
say " ", $_;
}
}
}
bxtest Q:to/END/.lines;
~/{Downloads,Pictures}/*.{jpg,gif,png}
It{{em,alic}iz,erat}e{d,}, please.
{,{,gotta have{ ,\, again\, }}more }cowbell!
{}} some {\\{edge,edgy} }{ cases, here\\\}
a{b{1,2}c
a{1,2}b}c
a{1,{2},3}b
a{b{1,2}c{}}
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment