Permalink
Browse files

Refactor Pod configuration and make it more correct. thou++

  • Loading branch information...
1 parent 94aa2b7 commit c07eba2ca9e1fd195e0d061154982ca61d10eacf @tadzik tadzik committed Aug 14, 2012
Showing with 22 additions and 18 deletions.
  1. +4 −0 src/Perl6/Actions.pm
  2. +14 −14 src/Perl6/Grammar.pm
  3. +4 −4 src/Perl6/Pod.pm
View
@@ -380,6 +380,10 @@ class Perl6::Actions is HLL::Actions {
make $<pod_block>.ast;
}
+ method pod_configuration($/) {
+ make Perl6::Pod::make_config($/);
+ }
+
method pod_block:sym<delimited>($/) {
make Perl6::Pod::any_block($/);
}
View
@@ -213,7 +213,7 @@ grammar Perl6::Grammar is HLL::Grammar {
# not a block, just a directive
token pod_content:sym<config> {
<pod_newline>*
- ^^ \h* '=config' \h+ $<type>=\S+ [ [\n '=']? \h+ <colonpair> ]+
+ ^^ \h* '=config' \h+ $<type>=\S+ <pod_configuration>
<pod_newline>+
}
@@ -259,12 +259,15 @@ grammar Perl6::Grammar is HLL::Grammar {
proto token pod_block { <...> }
+ token pod_configuration($spaces = '') {
+ [ [\n $spaces '=']? \h+ <colonpair> ]*
+ }
+
token pod_block:sym<delimited_raw> {
^^
$<spaces> = [ \h* ]
'=begin' \h+ $<type>=[ 'code' | 'comment' ] {}
- [ [\n '=']? \h+ <colonpair> ]*
- <pod_newline>+
+ <pod_configuration($<spaces>)> <pod_newline>+
[
$<pod_content> = [ .*? ]
^^ $<spaces> '=end' \h+ $<type> <pod_newline>
@@ -288,8 +291,7 @@ grammar Perl6::Grammar is HLL::Grammar {
<pod_code_parent> { $*ALLOW_CODE := 1 }
|| <identifier>
]
- [ [\n '=']? \h+ <colonpair> ]*
- <pod_newline>+
+ <pod_configuration($<spaces>)> <pod_newline>+
[
<pod_content> *
^^ $<spaces> '=end' \h+ $<type> <pod_newline>
@@ -300,7 +302,7 @@ grammar Perl6::Grammar is HLL::Grammar {
token pod_block:sym<delimited_table> {
^^ \h* '=begin' \h+ 'table'
- [ [\n '=']? \h+ <colonpair> ]* <pod_newline>+
+ <pod_configuration($<spaces>)> <pod_newline>+
[
<table_row>*
^^ \h* '=end' \h+ 'table' <pod_newline>
@@ -334,21 +336,19 @@ grammar Perl6::Grammar is HLL::Grammar {
<pod_code_parent> { $*ALLOW_CODE := 1 }
|| <identifier>
]
- [ [\n '=']? \h+ <colonpair> ]*
- <pod_newline>
+ <pod_configuration($<spaces>)> <pod_newline>
$<pod_content> = <pod_textcontent>?
}
token pod_block:sym<paragraph_raw> {
^^ \h* '=for' \h+ $<type>=[ 'code' | 'comment' ]
- [ [\n '=']? \h+ <colonpair> ]*
- <pod_newline>
+ <pod_configuration($<spaces>)> <pod_newline>
$<pod_content> = [ \h* <!before '=' \w> \N+ \n ]+
}
token pod_block:sym<paragraph_table> {
^^ \h* '=for' \h+ 'table'
- [ [\n '=']? \h+ <colonpair> ]* <pod_newline>
+ <pod_configuration($<spaces>)> <pod_newline>
[ <!before \h* \n> <table_row>]*
}
@@ -364,19 +364,19 @@ grammar Perl6::Grammar is HLL::Grammar {
<pod_code_parent> { $*ALLOW_CODE := 1 }
|| <identifier>
]
- [ [\n '=']? \h+ <colonpair> ]*
+ <pod_configuration($<spaces>)>
\s
$<pod_content> = <pod_textcontent>?
}
token pod_block:sym<abbreviated_raw> {
^^ \h* '=' $<type>=[ 'code' | 'comment' ]
- [ [\n '=']? \h+ <colonpair> ]* \s
+ <pod_configuration($<spaces>)> \s
$<pod_content> = [ \h* <!before '=' \w> \N+ \n ]*
}
token pod_block:sym<abbreviated_table> {
- ^^ \h* '=table' [ [\n '=']? \h+ <colonpair> ]* <pod_newline>
+ ^^ \h* '=table' <pod_configuration($<spaces>)> <pod_newline>
[ <!before \h* \n> <table_row>]*
}
View
@@ -14,7 +14,7 @@ class Perl6::Pod {
my @children := [];
my $type;
my $leveled;
- my $config := make_config($/);
+ my $config := $<pod_configuration>.ast;
if $<type>.Str ~~ /^item \d*$/ {
$type := 'Pod::Item';
@@ -58,7 +58,7 @@ class Perl6::Pod {
}
our sub raw_block($/) {
- my $config := make_config($/);
+ my $config := $<pod_configuration>.ast;
my $str := $*W.add_constant('Str', 'str', ~$<pod_content>);
my $content := serialize_array([$str.compile_time_value]);
my $type := $<type>.Str eq 'code' ?? 'Pod::Block::Code'
@@ -74,7 +74,7 @@ class Perl6::Pod {
my $type := $*W.add_constant('Str', 'str', ~$<type>);
return serialize_object(
'Pod::Config', :type($type.compile_time_value),
- :config(make_config($/))
+ :config($<pod_configuration>.ast)
).compile_time_value
}
@@ -118,7 +118,7 @@ class Perl6::Pod {
return $r;
}
our sub table($/) {
- my $config := make_config($/);
+ my $config := $<pod_configuration>.ast;
my @rows := [];
for $<table_row> {

0 comments on commit c07eba2

Please sign in to comment.