Skip to content

Commit

Permalink
- change how parser is generated
Browse files Browse the repository at this point in the history
git-svn-id: https://dagolden.googlecode.com/svn/Pod-WikiDoc/trunk@1299 dfce27d5-b31c-0410-bb09-030b4413eeba
  • Loading branch information
xdg committed Sep 30, 2007
1 parent 0fd6083 commit 59779ce
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 57 deletions.
76 changes: 44 additions & 32 deletions Pod_WikiDoc_Parser.pm.PL
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use strict;
use warnings;
use File::Basename;
use File::pushd;
use IO::File;
use Parse::RecDescent;

use vars qw( $VERSION );
Expand All @@ -17,32 +18,42 @@ package main;

my $grammar = do { local $/; <DATA> };

# Find target directory
# Find target location

my ($target_dir) = dirname($ARGV[0]);
my ($target_name) = $ARGV[0];

{
# Temporarily change to target directory since PRD Precompile writes to
# current directory only
my $cd = pushd( $target_dir );
my $target_file = IO::File->new( $target_name, ">" ) or die $!;

# Generate Parser file
# Temporarily change to temp directory since PRD Precompile writes to
# current directory only
my $cd = tempd();

$Parse::RecDescent::skip = q{};
Parse::RecDescent->Precompile( $grammar, "Pod::WikiDoc::Parser" );
}
# Generate Parser file

# Text to append to precompiled parser
$Parse::RecDescent::skip = q{};
Parse::RecDescent->Precompile( $grammar, "Pod::WikiDoc::Parser" );

# interpolate version
# open it up and open destination
my $precompile = IO::File->new( "Parser.pm" ) or die $!;

my $version_text = "\n\nuse vars qw( \$VERSION );\n\$VERSION";
$version_text .= " = $VERSION\n";
# copy package statement line

print {$target_file} scalar <$precompile>;

# interpolate version and add it

my $version_text = "\nuse vars qw( \$VERSION );\n\$VERSION";
$version_text .= " = $VERSION\n\n";

print {$target_file} $version_text;

# copy precompiled parser

print {$target_file} <$precompile>;

# assemble intro pod

my $docs_text = <<'END_DOCS';
=begin wikidoc
= NAME
Expand Down Expand Up @@ -100,21 +111,27 @@ included below for reference for those interested in the topic:
= AUTHOR
David A Golden (DAGOLDEN)
dagolden@cpan.org
David A. Golden (DAGOLDEN)
[http://dagolden.com/]
= COPYRIGHT AND LICENSE
= COPYRIGHT
Copyright (c) 2005, 2006, 2007 by David A. Golden
Copyright (c) 2005 by David A Golden
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
[http://www.apache.org/licenses/LICENSE-2.0]
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
Files produced as output though the use of this software, including
generated copies of boilerplate templates provided with this software,
shall not be considered Derivative Works, but shall be considered the
original work of the Licensor.
The full text of the license can be found in the
LICENSE file included with this module.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end wikidoc
Expand All @@ -124,13 +141,8 @@ END_DOCS

# Append version and grammar for reference

open my $fh, ">>", $ARGV[0]
or warn "Couldn't append grammar to Pod::WikiDoc::Parser";
if ( $fh ) {
print $fh $version_text, "\n\n__END__\n\n", $docs_text;
print $fh "\n\n=begin grammar\n\n", $grammar, "\n\n=end grammar\n\n";
close $fh;
}
print {$target_file} "\n\n__END__\n\n", $docs_text;
print {$target_file} "\n\n=begin grammar\n\n", $grammar, "\n\n=end grammar\n\n";

exit;

Expand Down
35 changes: 20 additions & 15 deletions lib/Pod/WikiDoc/Parser.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package Pod::WikiDoc::Parser;

use vars qw( $VERSION );
$VERSION = 0.18

use Parse::RecDescent;

{ my $ERRORS;
Expand Down Expand Up @@ -8631,13 +8635,8 @@ package Pod::WikiDoc::Parser; sub new { my $self = bless( {
}, 'Parse::RecDescent' );
}

use vars qw( $VERSION );
$VERSION = 0.18


__END__
=begin wikidoc
= NAME
Expand Down Expand Up @@ -8695,21 +8694,27 @@ included below for reference for those interested in the topic:
= AUTHOR
David A Golden (DAGOLDEN)
dagolden@cpan.org
David A. Golden (DAGOLDEN)
[http://dagolden.com/]
= COPYRIGHT AND LICENSE
= COPYRIGHT
Copyright (c) 2005, 2006, 2007 by David A. Golden
Copyright (c) 2005 by David A Golden
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
[http://www.apache.org/licenses/LICENSE-2.0]
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
Files produced as output though the use of this software, including
generated copies of boilerplate templates provided with this software,
shall not be considered Derivative Works, but shall be considered the
original work of the Licensor.
The full text of the license can be found in the
LICENSE file included with this module.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end wikidoc
Expand Down
26 changes: 16 additions & 10 deletions lib/Pod/WikiDoc/Parser.pod
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,27 @@ Text::WikiFormat

=head1 AUTHOR

David A Golden (DAGOLDEN)
David A. Golden (DAGOLDEN)

dagolden@cpan.org
=head1 COPYRIGHT AND LICENSE

L<http://dagolden.com/>
Copyright (c) 2005, 2006, 2007 by David A. Golden

=head1 COPYRIGHT
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
L<http://www.apache.org/licenses/LICENSE-2.0>

Copyright (c) 2005 by David A Golden
Files produced as output though the use of this software, including
generated copies of boilerplate templates provided with this software,
shall not be considered Derivative Works, but shall be considered the
original work of the Licensor.

This program is free software; you can redistribute
it andE<sol>or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


=begin grammar
Expand Down

0 comments on commit 59779ce

Please sign in to comment.