Created
August 7, 2011 23:23
-
-
Save tadzik/1130921 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/Pod/To/Text.pm b/Pod/To/Text.pm | |
index a563bcc..cc4b05e 100644 | |
--- a/Pod/To/Text.pm | |
+++ b/Pod/To/Text.pm | |
@@ -53,7 +53,7 @@ sub declarator2text($pod) { | |
when nqp::p6bool(nqp::istype($_.HOW, Metamodel::ModuleHOW)) { | |
'module' | |
} | |
- } ~ ' ' ~ $pod.WHEREFORE.perl ~ ': ' ~ $pod.WHEREFORE.WHY ~ "\n" | |
+ } ~ ' ' ~ $pod.WHEREFORE.perl ~ ': ' ~ $pod.WHEREFORE.WHY.content ~ "\n" | |
} | |
# vim: ft=perl6 | |
diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm | |
index e944b6f..0cfcd00 100644 | |
--- a/src/Perl6/Grammar.pm | |
+++ b/src/Perl6/Grammar.pm | |
@@ -1,6 +1,7 @@ | |
use NQPP6Regex; | |
use QRegex; | |
use Perl6::SymbolTable; | |
+use Perl6::Pod; | |
grammar Perl6::Grammar is HLL::Grammar { | |
method TOP() { | |
@@ -144,6 +145,25 @@ grammar Perl6::Grammar is HLL::Grammar { | |
{ $*DECLARATOR_DOCS := ~$<attachment> } | |
} | |
+ token attach_docs { | |
+ { | |
+ $*DECLARATOR_DOCS := ''; | |
+ if $*DOC ne '' { | |
+ my $cont := Perl6::Pod::serialize_aos( | |
+ [$*DOC] | |
+ )<compile_time_value>; | |
+ my $block := $*ST.add_constant( | |
+ 'Pod::Block::Declarator', 'type_new', | |
+ :nocache, :content($cont), | |
+ ); | |
+ $*DOCEE := $block<compile_time_value>; | |
+ say($block<compile_time_value>, " describes ", $*DOC); | |
+ $*POD_BLOCKS.push($*DOCEE); | |
+ } | |
+ } | |
+ <?> | |
+ } | |
+ | |
token pod_content_toplevel { | |
<pod_block> | |
} | |
@@ -1051,7 +1071,8 @@ grammar Perl6::Grammar is HLL::Grammar { | |
:my $*IN_DECL := 'package'; | |
:my $*CURPAD; | |
:my $*DOC := $*DECLARATOR_DOCS; | |
- { $*DECLARATOR_DOCS := '' } | |
+ :my $*DOCEE; | |
+ <.attach_docs> | |
# Meta-object will live in here; also set default REPR (a trait | |
# may override this, e.g. is repr('...')). | |
@@ -1215,8 +1236,10 @@ grammar Perl6::Grammar is HLL::Grammar { | |
rule scoped($*SCOPE) {<.end_keyword> [ | |
:my $*TYPENAME := ''; | |
+ | |
:my $*DOC := $*DECLARATOR_DOCS; | |
- { $*DECLARATOR_DOCS := '' } | |
+ :my $*DOCEE; | |
+ <.attach_docs> | |
[ | |
| <DECL=variable_declarator> | |
| <DECL=routine_declarator> | |
@@ -1271,7 +1294,8 @@ grammar Perl6::Grammar is HLL::Grammar { | |
:my $*IN_DECL := $d; | |
:my $*METHODTYPE; | |
:my $*DOC := $*DECLARATOR_DOCS; | |
- { $*DECLARATOR_DOCS := '' } | |
+ :my $*DOCEE; | |
+ <.attach_docs> | |
<deflongname>? | |
<.newpad> | |
[ '(' <multisig> ')' ]? | |
@@ -1287,7 +1311,8 @@ grammar Perl6::Grammar is HLL::Grammar { | |
:my $*IN_DECL := $d; | |
:my $*METHODTYPE := $d; | |
:my $*DOC := $*DECLARATOR_DOCS; | |
- { $*DECLARATOR_DOCS := '' } | |
+ :my $*DOCEE; | |
+ <.attach_docs> | |
[ | |
<.newpad> | |
[ | |
diff --git a/src/Perl6/Pod.pm b/src/Perl6/Pod.pm | |
index df0587c..8747afb 100644 | |
--- a/src/Perl6/Pod.pm | |
+++ b/src/Perl6/Pod.pm | |
@@ -2,18 +2,10 @@ | |
class Perl6::Pod { | |
our sub document($what, $with) { | |
if $with ne '' { | |
+ say("Documenting stuff using ", $*DOCEE); | |
+ say("Stuff of type ", pir::typeof($what)); | |
my $true := $*ST.add_constant('Int', 'int', 1)<compile_time_value>; | |
- my $doc := $*ST.add_constant('Str', 'str', $with)<compile_time_value>; | |
- $*ST.apply_trait('&trait_mod:<is>', $what, $doc, :docs($true)); | |
- | |
- # add it to $=POD | |
- my $cont := serialize_array([$doc])<compile_time_value>; | |
- my $block := $*ST.add_constant( | |
- 'Pod::Block::Declarator', 'type_new', | |
- :nocache, | |
- :WHEREFORE($what), :content($cont), | |
- ); | |
- $*POD_BLOCKS.push($block<compile_time_value>); | |
+ $*ST.apply_trait('&trait_mod:<is>', $what, $*DOCEE, :docs($true)); | |
} | |
} | |
diff --git a/src/core/Pod.pm b/src/core/Pod.pm | |
index 5446608..a997af5 100644 | |
--- a/src/core/Pod.pm | |
+++ b/src/core/Pod.pm | |
@@ -18,6 +18,9 @@ my package Pod { | |
class Block::Declarator is Block { | |
has $.WHEREFORE; | |
+ method set_docee($d) { | |
+ $!WHEREFORE = $d | |
+ } | |
} | |
class Block::Table is Block { | |
diff --git a/src/core/traits.pm b/src/core/traits.pm | |
index 3239fb4..0c35989 100644 | |
--- a/src/core/traits.pm | |
+++ b/src/core/traits.pm | |
@@ -61,10 +61,12 @@ multi trait_mod:<is>(Mu:D $docee, $doc, :$docs!) { | |
method set_docs($d) { $!WHY = $d } | |
} | |
$docee.set_docs($doc); | |
+ $doc.set_docee($docee); | |
} | |
multi trait_mod:<is>(Mu:U $docee, $doc, :$docs!) { | |
$docee.HOW.set_docs($doc); | |
+ $doc.set_docee($docee); | |
} | |
diff --git a/tools/build/Makefile.in b/tools/build/Makefile.in | |
index a3ad550..4295af8 100644 | |
--- a/tools/build/Makefile.in | |
+++ b/tools/build/Makefile.in | |
@@ -299,7 +299,7 @@ $(PERL6_ST_PBC): $(NQP_EXE) $(PERL6_ML_PBC) src/Perl6/SymbolTable.pm | |
src/Perl6/SymbolTable.pm | |
$(PARROT) $(PARROT_ARGS) -o $(PERL6_ST_PBC) $(PERL6_ST) | |
-$(PERL6_G_PBC): $(NQP_EXE) $(PERL6_ST_PBC) src/Perl6/Grammar.pm | |
+$(PERL6_G_PBC): $(NQP_EXE) $(PERL6_ST_PBC) src/Perl6/Grammar.pm $(PERL6_P_PBC) | |
$(NQP_EXE) --target=pir --output=$(PERL6_G) --encoding=utf8 \ | |
src/Perl6/Grammar.pm | |
$(PARROT) $(PARROT_ARGS) -o $(PERL6_G_PBC) $(PERL6_G) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
= Color screen output using ANSI escape sequences
module Term::ANSIColor;
= emit ANSI sequence for the given string of attributes
sub color (Str $what) is export { ... }
= color the text according to the description
sub colored (Str $what, Str $how) is export { ... }
= is the color valid?
sub colorvalid (*@A) is export { ... }
= string colors from the string
sub colorstrip (*@A) is export { ... }
= transform ANSI sequences into their string descriptions
sub uncolor (Str $what) is export { ... }
for $=POD {
.WHEREFORE.WHAT.say;
}
DOC INIT {
use Pod::To::Text;
print pod2text($=POD)
}