diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-10-12 23:57:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-12 23:57:57 +0100 |
| commit | df9ca2ecf356db57fa6dec7e67f3ac2fd6f22d0e (patch) | |
| tree | e4ae3d84fdb249895546d913fd6c7170cf86f12a | |
| parent | b21d28e1172cf198268c1bef0ae5baeb15651107 (diff) | |
| parent | 3a16cf490615499a37529e9e0972f874b44b2b18 (diff) | |
| download | perlweeklychallenge-club-df9ca2ecf356db57fa6dec7e67f3ac2fd6f22d0e.tar.gz perlweeklychallenge-club-df9ca2ecf356db57fa6dec7e67f3ac2fd6f22d0e.tar.bz2 perlweeklychallenge-club-df9ca2ecf356db57fa6dec7e67f3ac2fd6f22d0e.zip | |
Merge pull request #748 from jmaslak/joelle-29-1-1
Properly handle nested strings.
| -rwxr-xr-x | challenge-029/joelle-maslak/perl6/ch-1.p6 | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/challenge-029/joelle-maslak/perl6/ch-1.p6 b/challenge-029/joelle-maslak/perl6/ch-1.p6 index 0234c8deb9..77d02a1039 100755 --- a/challenge-029/joelle-maslak/perl6/ch-1.p6 +++ b/challenge-029/joelle-maslak/perl6/ch-1.p6 @@ -22,8 +22,9 @@ grammar Expansion { token element { <string> | <curly> } token string { <-[ \{ \} ]>+ } token curly { \{ <option>+ % ',' \} } - token option { <innerstr> | <curly> } - token innerstr { <-[ \{ \} \, ]>* } + token option { <innerele>* } + token innerele { <innerstr> | <curly> } + token innerstr { <-[ \{ \} \, ]>+ } } @@ -44,7 +45,7 @@ sub expand($str) { # descends the tree. Have I mentioned how much I love Perl 6 grammars? # # Note that string token is different than the innerstr, which looks -# like duplicated code (I'm willing to live with a couple lines here) +# like duplicated code (I'm willing to live with a few lines here) # but is not quite since string and innerstring *are* different - the # outter strings (outside any curlies) allows commas. sub expansion(@arr is copy, $tree) { @@ -54,6 +55,11 @@ sub expansion(@arr is copy, $tree) { @arr = expansion(@arr, $ele); } return @arr; + } elsif $tree<innerele>:exists { + for @($tree<innerele>) -> $ele { + @arr = expansion(@arr, $ele); + } + return @arr; } elsif $tree<string>:exists { return @arr.map: { $_ ~ $tree<string> }; } elsif $tree<innerstr>:exists { |
