This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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