Skip to content

Commit

Permalink
Explain the tricky details of patternize.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcurtis committed Jul 24, 2010
1 parent d29a1b8 commit e754f90
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Tree/Pattern.nqp
Expand Up @@ -9,12 +9,19 @@ INIT {
class Tree::Pattern is Capture {
sub patternize ($value) {
if ($value ~~ Regex::Method) {
# Regexes are subs, but we just want to treat them as a normal
# pattern.
$value;
} elsif (pir::isa__IPP($value, Sub)) {
# We have to check for Sub-ness before we check for ACCEPTs.
# Otherwise, some HLLs may get weird results if they add an
# ACCEPTS method to Sub.
Tree::Pattern::Closure.new($value);
} elsif (pir::can__IPS($value, 'ACCEPTS')) {
# Things with accepts are treated as patterns.
$value;
} else {
# If all else fails, let's try iseq.
Tree::Pattern::Constant.new($value);
}
}
Expand Down

0 comments on commit e754f90

Please sign in to comment.