Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement DOC phasers. Fix compilation options. Add a simple Pod::To:…

…:Text
  • Loading branch information...
commit 8797ffa0df14b406868f94f9370437a8b737eeb0 1 parent 0c0d929
Tadeusz Sośnierz tadzik authored
36 Pod/To/Text.pm
View
@@ -0,0 +1,36 @@
+module Pod::To::Text;
+
+sub pod2text($pod) is export {
+ given $pod {
+ when Pod::Heading { heading2text($pod) }
+ when Pod::Block::Code { code2text($pod) }
+ when Pod::Block::Named { named2text($pod) }
+ when Pod::Item { item2text($pod) }
+ when Positional { $pod.map({pod2text($_)}).join }
+ default { $pod.Str ~ "\n\n" }
+ }
+}
+
+sub heading2text($pod) {
+ given $pod.level {
+ when 1 { pod2text($pod.content) }
+ when 2 { ' ' ~ pod2text($pod.content) }
+ default { ' ' ~ pod2text($pod.content) }
+ }
+}
+
+sub code2text($pod) {
+ " " ~ $pod.content.subst(/\n/, "\n ", :g) ~ "\n\n"
+}
+
+sub item2text($pod) {
+ ' * ' ~ $pod.content.Str ~ "\n"
+}
+
+sub named2text($pod) {
+ $pod.name eq 'pod'
+ ?? pod2text($pod.content)
+ !! $pod.content ~ "\n"
+}
+
+# vim: ft=perl6
11 src/Perl6/Actions.pm
View
@@ -118,10 +118,10 @@ class Perl6::Actions is HLL::Actions {
method comp_unit($/, $key?) {
our $?RAKUDO_HLL;
-
+
# Checks.
$*ST.assert_stubs_defined();
-
+
# Get the block for the unit mainline code.
my $unit := $*UNIT;
my $mainline := PAST::Stmts.new(
@@ -135,7 +135,7 @@ class Perl6::Actions is HLL::Actions {
elsif %*COMPILING<%?OPTIONS><n> {
$mainline := wrap_option_n_code($mainline);
}
-
+
# Unit needs to have a load-init holding the deserialization or
# fixup code for this compilation unit.
$unit.loadinit().push($*ST.to_past());
@@ -711,6 +711,11 @@ class Perl6::Actions is HLL::Actions {
method statement_prefix:sym<INIT>($/) { $*ST.add_phaser($/, ($<blorst>.ast)<code_object>, 'INIT'); }
method statement_prefix:sym<END>($/) { $*ST.add_phaser($/, ($<blorst>.ast)<code_object>, 'END'); }
+ method statement_prefix:sym<DOC>($/) {
+ $*ST.add_phaser($/, ($<blorst>.ast)<code_object>, ~$<phase>)
+ if %*COMPILING<%?OPTIONS><doc>;
+ }
+
method statement_prefix:sym<do>($/) {
make PAST::Op.new( :pasttype('call'), $<blorst>.ast );
}
2  src/Perl6/Compiler.nqp
View
@@ -8,6 +8,8 @@ class Perl6::Compiler is HLL::Compiler {
nqp::shift($argiter) if $argiter && !pir::defined(%options<e>);
$hll_ns<$!ARGITER> := $argiter;
my $super := pir::find_method__PPs(HLL::Compiler, 'command_eval');
+ my %*COMPILING;
+ %*COMPILING<%?OPTIONS> := %options;
$super(self, |@args, |%options);
}
}
5 src/Perl6/Grammar.pm
View
@@ -334,7 +334,6 @@ grammar Perl6::Grammar is HLL::Grammar {
:my $*UNIT;
:my $*UNIT_OUTER;
:my $*EXPORT;
- :my $*COMPILING := 1;
# A place for Pod
:my $*POD_BLOCKS := [];
@@ -681,6 +680,10 @@ grammar Perl6::Grammar is HLL::Grammar {
token statement_prefix:sym<try> { <sym> <blorst> }
token statement_prefix:sym<gather>{ <sym> <blorst> }
token statement_prefix:sym<do> { <sym> <blorst> }
+ token statement_prefix:sym<DOC> {
+ <sym> \s <.ws> $<phase>=['BEGIN' || 'CHECK' || 'INIT']
+ <blorst>
+ }
token blorst {
\s <.ws> [ <?[{]> <block> | <statement> ]
3  src/main.nqp
View
@@ -17,6 +17,9 @@ sub MAIN(@ARGS) {
my @clo := $comp.commandline_options();
@clo.push('parsetrace');
@clo.push('setting=s');
+ @clo.push('n');
+ @clo.push('p');
+ @clo.push('doc');
# Set up END block list, which we'll run at exit.
my @*END_PHASERS := [];
5 tools/build/Makefile.in
View
@@ -238,7 +238,7 @@ HARNESS_WITH_FUDGE = $(PERL) t/harness --fudge --keep-exit-code --icu=$(HAS_ICU)
STAGESTATS = @stagestats@
# the default target, TODO: make libraries in 'lib' a variable.
-all: check-versions $(PERL6_EXE) $(SETTING) Test.pir
+all: check-versions $(PERL6_EXE) $(SETTING) Test.pir Pod/To/Text.pir
# the install target
install: all
@@ -318,6 +318,9 @@ $(SETTING): $(PERL6_M_PBC) $(PERL6_EXE) $(CORE_SOURCES)
Test.pir: Test.pm $(PERL6_EXE) $(SETTING)
./$(PERL6_EXE) --target=pir --output=Test.pir Test.pm
+Pod/To/Text.pir: Pod/To/Text.pm $(PERL6_EXE) $(SETTING)
+ ./$(PERL6_EXE) --target=pir --output=Pod/To/Text.pir Pod/To/Text.pm
+
test : coretest
fulltest: coretest stresstest
Please sign in to comment.
Something went wrong with that request. Please try again.