Skip to content

Commit

Permalink
Save Regex source for .gist/.perl
Browse files Browse the repository at this point in the history
  • Loading branch information
hoelzro committed Jun 2, 2015
1 parent 73480ff commit c79bcc5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Perl6/Actions.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -3444,6 +3444,10 @@ Compilation unit '$file' contained the following violations:
# Install in needed scopes.
install_method($/, $name, $scope, $code, $outer) if $name ne '';

# Bind original source to $!source
my $Regex := $*W.find_symbol(['Regex']);
nqp::bindattr($code, $Regex, '$!source', ~$/);

# Return a reference to the code object
reference_to_code_object($code, $past);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Perl6/Metamodel/BOOTSTRAP.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2521,11 +2521,13 @@ BEGIN {
# class Regex is Method {
# has Mu $!caps;
# has Mu $!nfa;
# has Mu $!alt_nfas
# has Mu $!alt_nfas;
# has Mu $!source;
Regex.HOW.add_parent(Regex, Method);
Regex.HOW.add_attribute(Regex, scalar_attr('$!caps', Mu, Regex));
Regex.HOW.add_attribute(Regex, scalar_attr('$!nfa', Mu, Regex));
Regex.HOW.add_attribute(Regex, scalar_attr('$!alt_nfas', Mu, Regex));
Regex.HOW.add_attribute(Regex, scalar_attr('$!source', Mu, Regex));
Regex.HOW.add_method(Regex, 'SET_CAPS', nqp::getstaticcode(sub ($self, $caps) {
nqp::bindattr(nqp::decont($self), Regex, '$!caps', $caps)
}));
Expand Down
11 changes: 10 additions & 1 deletion src/core/Regex.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ my class Regex { # declared in BOOTSTRAP
# class Regex is Method {
# has Mu $!caps;
# has Mu $!nfa;
# has Mu $!alt_nfas
# has Mu $!alt_nfas;
# has Mu $!source;

multi method ACCEPTS(Regex:D \SELF: Mu \topic) {
my $dollar_slash := nqp::getlexrelcaller(
Expand Down Expand Up @@ -42,6 +43,14 @@ my class Regex { # declared in BOOTSTRAP
$dollar_slash = $dollar_underscore.match(self);
$dollar_slash.Bool()
}

method gist(Regex:D:) {
nqp::isnull($!source) ?? '' !! $!source
}

method perl(Regex:D:) {
nqp::isnull($!source) ?? '' !! $!source
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit c79bcc5

Please sign in to comment.