Skip to content

Commit

Permalink
create FileGlob as subclass of StringGlob, but adds alternation
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpilot committed Dec 23, 2009
1 parent a112f2a commit 32cde5f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build/Makefile.in
Expand Up @@ -20,6 +20,9 @@ GEN_SOURCES = \
src/StringGlob/Actions.pir \
src/StringGlob/Compiler.pir \
src/StringGlob/Grammar.pir \
src/FileGlob/Actions.pir \
src/FileGlob/Compiler.pir \
src/FileGlob/Grammar.pir \
src/Partcl/Actions.pir \
src/Partcl/Compiler.pir \
src/Partcl/Grammar.pir \
Expand Down
11 changes: 11 additions & 0 deletions src/FileGlob/Actions.pm
@@ -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:
9 changes: 9 additions & 0 deletions src/FileGlob/Compiler.pm
@@ -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:
12 changes: 12 additions & 0 deletions src/FileGlob/Grammar.pm
@@ -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:
3 changes: 3 additions & 0 deletions src/Partcl.pir
Expand Up @@ -37,6 +37,9 @@
.include 'src/StringGlob/Grammar.pir'
.include 'src/StringGlob/Actions.pir'
.include 'src/StringGlob/Compiler.pir'
.include 'src/FileGlob/Grammar.pir'
.include 'src/FileGlob/Actions.pir'
.include 'src/FileGlob/Compiler.pir'
.include 'src/init.pir'
.include 'src/options.pir'

Expand Down

0 comments on commit 32cde5f

Please sign in to comment.