forked from pmichaud/pmtcl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create FileGlob as subclass of StringGlob, but adds alternation
- Loading branch information
Showing
5 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class FileGlob::Actions is StringGlob::Actions; | ||
|
||
method metachar:sym<{>($/) { | ||
my $ast := PAST::Regex.new( :pasttype<alt>, :node($/) ); | ||
for $<word> { | ||
$ast.push(PAST::Regex.new( ~$_, :pasttype<literal>, :node($/) ) ); | ||
} | ||
make $ast; | ||
} | ||
|
||
# vim: filetype=perl6: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class FileGlob::Compiler is HLL::Compiler { | ||
INIT { | ||
FileGlob::Compiler.parsegrammar(FileGlob::Grammar); | ||
FileGlob::Compiler.parseactions(FileGlob::Actions); | ||
FileGlob::Compiler.language('FileGlob'); | ||
} | ||
} | ||
|
||
# vim: filetype=perl6: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
grammar FileGlob::Grammar is StringGlob::Grammar; | ||
|
||
# This is how globs do alternation | ||
token metachar:sym<{> { | ||
'{' ~ '}' [ <word> ** ',' ] | ||
} | ||
|
||
token word { <-[,}]>+ } | ||
|
||
token barechar { <-[\\\[*+?{]> } | ||
|
||
# vim: filetype=perl6: |
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