Created
July 30, 2011 17:48
-
-
Save tadzik/1115781 to your computer and use it in GitHub Desktop.
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
diff --git a/src/Perl6/Actions.pm b/src/Perl6/Actions.pm | |
index d24b452..3c2f968 100644 | |
--- a/src/Perl6/Actions.pm | |
+++ b/src/Perl6/Actions.pm | |
@@ -1136,6 +1136,12 @@ class Perl6::Actions is HLL::Actions { | |
type => $type, | |
package => $*ST.find_symbol(['$?CLASS'])), | |
sigiltype($sigil), $descriptor, |@default); | |
+ | |
+ # Document it | |
+ if $*DOC { | |
+ my $true := $*ST.add_constant('Int', 'int', 1)<compile_time_value>; | |
+ $*ST.apply_trait('&trait_mod:<is>', $attr, $*DOC, :docs($true)); | |
+ } | |
# If no twigil, note $foo is an alias to $!foo. | |
if $twigil eq '' { | |
@@ -1241,6 +1247,10 @@ class Perl6::Actions is HLL::Actions { | |
} | |
my $code := $*ST.create_code_object($block, 'Sub', $signature, | |
$*MULTINESS eq 'proto'); | |
+ if $*DOC { | |
+ my $true := $*ST.add_constant('Int', 'int', 1)<compile_time_value>; | |
+ $*ST.apply_trait('&trait_mod:<is>', $code, $*DOC, :docs($true)); | |
+ } | |
# Install PAST block so that it gets capture_lex'd correctly and also | |
# install it in the lexpad. | |
diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm | |
index 01f4bda..454bbea 100644 | |
--- a/src/Perl6/Grammar.pm | |
+++ b/src/Perl6/Grammar.pm | |
@@ -136,7 +136,7 @@ grammar Perl6::Grammar is HLL::Grammar { | |
} | |
token comment:sym<#=(...)> { | |
- '#=' <!ws> $<attachment=<quote_EXPR> | |
+ '#=' <!ws> $<attachment>=<quote_EXPR> | |
} | |
token comment:sym<#=> { | |
@@ -1219,6 +1219,8 @@ grammar Perl6::Grammar is HLL::Grammar { | |
rule scoped($*SCOPE) {<.end_keyword> [ | |
:my $*TYPENAME := ''; | |
+ :my $*DOC := $*DECLARATOR; | |
+ { $*DECLARATOR := '' } | |
[ | |
| <DECL=variable_declarator> | |
| <DECL=routine_declarator> | |
@@ -1272,6 +1274,8 @@ grammar Perl6::Grammar is HLL::Grammar { | |
rule routine_def($d) { | |
:my $*IN_DECL := $d; | |
:my $*METHODTYPE; | |
+ :my $*DOC := $*DECLARATOR; | |
+ { $*DECLARATOR := '' } | |
<deflongname>? | |
<.newpad> | |
[ '(' <multisig> ')' ]? | |
@@ -1286,6 +1290,8 @@ grammar Perl6::Grammar is HLL::Grammar { | |
rule method_def($d) { | |
:my $*IN_DECL := $d; | |
:my $*METHODTYPE := $d; | |
+ :my $*DOC := $*DECLARATOR; | |
+ { $*DECLARATOR := '' } | |
[ | |
<.newpad> | |
[ | |
diff --git a/src/core/Routine.pm b/src/core/Routine.pm | |
index 14ed05d..addeb33 100644 | |
--- a/src/core/Routine.pm | |
+++ b/src/core/Routine.pm | |
@@ -1,4 +1,5 @@ | |
my class Routine { | |
+ has $!docs; | |
method of() { self.signature.returns } | |
method returns() { self.signature.returns } | |
method rw() { $!rw } | |
@@ -14,4 +15,8 @@ my class Routine { | |
pir::perl6ize_type__PP(nqp::getattr(self, Code, '$!dispatchees')) !! | |
(self,) | |
} | |
+ | |
+ method WHY() { | |
+ $!docs | |
+ } | |
} | |
diff --git a/src/core/traits.pm b/src/core/traits.pm | |
index bee817c..a02b59d 100644 | |
--- a/src/core/traits.pm | |
+++ b/src/core/traits.pm | |
@@ -54,6 +54,11 @@ multi trait_mod:<is>(Routine:D \$r, :$export!) { | |
} | |
} | |
+multi trait_mod:<is>(Routine:D $docee, Mu:D $doc, :$docs!) { | |
+ my $d = $doc; #XXX Bug | |
+ $docee does role { method WHY() { $d } } | |
+} | |
+ | |
proto trait_mod:<does>(|$) { * } | |
multi trait_mod:<does>(Mu:U $doee, Mu:U $role) { | |
$doee.HOW.add_role($doee, $role) |
Author
tadzik
commented
Jul 30, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment