rdoc-perl_pod 1.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,5 @@
1
+ === 1.0 / 2010-12-19
2
+
3
+ * Major enhancement
4
+ * Split from rdoc
5
+
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/rdoc/discover.rb
6
+ lib/rdoc/parser/perl_pod.rb
7
+ test/test_rdoc_parser_perl.rb
@@ -0,0 +1,33 @@
1
+ = rdoc-perl_pod
2
+
3
+ * https://github.com/rdoc/rdoc-perl_pod
4
+
5
+ == DESCRIPTION:
6
+
7
+ A parser for Perl's POD documentation format. Allows Perl and Ruby
8
+ documentation to be used together.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * No maintainer
13
+ * Parses .pl and .pm files
14
+
15
+ == SYNOPSIS:
16
+
17
+ After installing rdoc-perl_pod use RDoc on some .pl or .pm files
18
+
19
+ == REQUIREMENTS:
20
+
21
+ * RDoc
22
+ * Perl files
23
+
24
+ == INSTALL:
25
+
26
+ * gem install rdoc-perl_pod
27
+
28
+ == LICENSE:
29
+
30
+ Unknown
31
+
32
+ Copyright (c) Huge Sasse
33
+
@@ -0,0 +1,22 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :git
7
+ Hoe.plugin :isolate
8
+ Hoe.plugin :minitest
9
+ Hoe.plugins.delete :rubyforge
10
+
11
+ Hoe.spec 'rdoc-perl_pod' do
12
+ developer 'Eric Hodel', 'drbrain@segment7.net'
13
+ developer 'Hugh Sasse', 'hgs@dmu.ac.uk'
14
+
15
+ extra_deps << ['rdoc', '~> 3']
16
+ extra_dev_deps << ['isolate', '~> 3']
17
+
18
+ self.rubyforge_name = 'rdoc'
19
+ self.isolate_dir = 'tmp/isolated'
20
+ end
21
+
22
+ # vim: syntax=Ruby
@@ -0,0 +1,6 @@
1
+ begin
2
+ gem 'rdoc', '~> 3'
3
+ require 'rdoc/parser/perl_pod'
4
+ rescue Gem::LoadError
5
+ end
6
+
@@ -0,0 +1,163 @@
1
+ require 'rdoc'
2
+ require 'rdoc/parser'
3
+
4
+ ##
5
+ # This is an attamept to write a basic parser for Perl's POD (Plain old
6
+ # Documentation) format. Ruby code must co-exist with Perl, and some tasks
7
+ # are easier in Perl than Ruby because of existing libraries.
8
+ #
9
+ # One difficult is that Perl POD has no means of identifying the classes
10
+ # (packages) and methods (subs) with which it is associated, it is more like
11
+ # literate programming in so far as it just happens to be in the same place as
12
+ # the code, but need not be.
13
+ #
14
+ # We would like to support all the markup the POD provides so that it will
15
+ # convert happily to HTML. At the moment I don't think I can do that: time
16
+ # constraints.
17
+
18
+ class RDoc::Parser::PerlPOD < RDoc::Parser
19
+
20
+ VERSION = '1.0'
21
+
22
+ parse_files_matching(/.p[lm]$/)
23
+
24
+ ##
25
+ # Prepare to parse a perl file
26
+
27
+ def initialize(top_level, file_name, content, options, stats)
28
+ super
29
+
30
+ preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
31
+
32
+ preprocess.handle @content do |directive, param|
33
+ warn "Unrecognized directive '#{directive}' in #{@file_name}"
34
+ end
35
+ end
36
+
37
+ ##
38
+ # Extract the Pod(-like) comments from the code. At its most basic there
39
+ # will ne no need to distinguish between the different types of header, etc.
40
+ #
41
+ # This uses a simple finite state machine, in a very procedural pattern. I
42
+ # could "replace case with polymorphism" but I think it would obscure the
43
+ # intent, scatter the code all over tha place. This machine is necessary
44
+ # because POD requires that directives be preceded by blank lines, so
45
+ # reading line by line is necessary, and preserving state about what is seen
46
+ # is necesary.
47
+
48
+ def scan
49
+ @top_level.comment ||= ""
50
+ state=:code_blank
51
+ line_number = 0
52
+ line = nil
53
+
54
+ # This started out as a really long nested case statement,
55
+ # which also led to repetitive code. I'd like to avoid that
56
+ # so I'm using a "table" instead.
57
+
58
+ # Firstly we need some procs to do the transition and processing
59
+ # work. Because these are procs they are closures, and they can
60
+ # use variables in the local scope.
61
+ #
62
+ # First, the "nothing to see here" stuff.
63
+ code_noop = lambda do
64
+ if line =~ /^\s+$/
65
+ state = :code_blank
66
+ end
67
+ end
68
+
69
+ pod_noop = lambda do
70
+ if line =~ /^\s+$/
71
+ state = :pod_blank
72
+ end
73
+ @top_level.comment += filter(line)
74
+ end
75
+
76
+ begin_noop = lambda do
77
+ if line =~ /^\s+$/
78
+ state = :begin_blank
79
+ end
80
+ @top_level.comment += filter(line)
81
+ end
82
+
83
+ # Now for the blocks that process code and comments...
84
+
85
+ transit_to_pod = lambda do
86
+ case line
87
+ when /^=(?:pod|head\d+)/
88
+ state = :pod_no_blank
89
+ @top_level.comment += filter(line)
90
+ when /^=over/
91
+ state = :over_no_blank
92
+ @top_level.comment += filter(line)
93
+ when /^=(?:begin|for)/
94
+ state = :begin_no_blank
95
+ end
96
+ end
97
+
98
+ process_pod = lambda do
99
+ case line
100
+ when /^\s*$/ then
101
+ state = :pod_blank
102
+ @top_level.comment += filter(line)
103
+ when /^=cut/ then
104
+ state = :code_no_blank
105
+ when /^=end/ then
106
+ $stderr.puts "'=end' unexpected at #{line_number} in #{@file_name}"
107
+ else
108
+ @top_level.comment += filter(line)
109
+ end
110
+ end
111
+
112
+ process_begin = lambda do
113
+ case line
114
+ when /^\s*$/ then
115
+ state = :begin_blank
116
+ @top_level.comment += filter(line)
117
+ when /^=end/ then
118
+ state = :code_no_blank
119
+ when /^=cut/
120
+ $stderr.puts "'=cut' unexpected at #{line_number} in #{@file_name}"
121
+ else
122
+ @top_level.comment += filter(line)
123
+ end
124
+ end
125
+
126
+ transitions = { :code_no_blank => code_noop,
127
+ :code_blank => transit_to_pod,
128
+ :pod_no_blank => pod_noop,
129
+ :pod_blank => process_pod,
130
+ :begin_no_blank => begin_noop,
131
+ :begin_blank => process_begin,
132
+ }
133
+
134
+ @content.each_line do |l|
135
+ line = l
136
+ line_number += 1
137
+ transitions[state].call
138
+ end
139
+
140
+ @top_level
141
+ end
142
+
143
+ ##
144
+ # Filter the perl markup that does the same as the rdoc filtering. Only
145
+ # basic for now. Will probably need a proper parser to cope with C<<...>>
146
+ # etc.
147
+
148
+ def filter(comment)
149
+ return '' if comment =~ /^=pod\s*$/
150
+ comment.gsub!(/^=pod/, '==')
151
+
152
+ comment.gsub!(/^=head(\d+)/) do
153
+ "=" * $1.to_i
154
+ end
155
+ comment.gsub!(/=item/, '');
156
+ comment.gsub!(/C<(.*?)>/, '<tt>\1</tt>');
157
+ comment.gsub!(/I<(.*?)>/, '<i>\1</i>');
158
+ comment.gsub!(/B<(.*?)>/, '<b>\1</b>');
159
+ comment
160
+ end
161
+
162
+ end
163
+
@@ -0,0 +1,74 @@
1
+ require 'stringio'
2
+ require 'tempfile'
3
+ require 'rubygems'
4
+ require 'minitest/autorun'
5
+ require 'rdoc'
6
+ require 'rdoc/options'
7
+ require 'rdoc/parser/perl_pod'
8
+
9
+ class TestRdocParserPerlPOD < MiniTest::Unit::TestCase
10
+
11
+ def setup
12
+ @tempfile = Tempfile.new self.class.name
13
+ filename = @tempfile.path
14
+
15
+ @top_level = RDoc::TopLevel.new filename
16
+ @fn = filename
17
+ @options = RDoc::Options.new
18
+ @stats = RDoc::Stats.new 0
19
+ end
20
+
21
+ def teardown
22
+ @tempfile.close
23
+ end
24
+
25
+ def test_uncommented_perl
26
+ content = <<-EOF
27
+ while (<>) {
28
+ tr/a-z/A-Z;
29
+ print
30
+ }
31
+ EOF
32
+
33
+ comment = util_get_comment content
34
+ assert_equal "", comment
35
+ end
36
+
37
+ def test_perl_without_pod
38
+ content = <<-EOF
39
+ #!/usr/local/bin/perl
40
+ #
41
+ #This is a pointless perl program because it does -p.
42
+ #
43
+ while(<>) {print;}:
44
+ EOF
45
+
46
+ comment = util_get_comment content
47
+ assert_equal "", comment
48
+ end
49
+
50
+ def test_simple_pod_no_structure
51
+ content = <<-EOF
52
+ =begin pod
53
+
54
+ This just contains plain old documentation
55
+
56
+ =end
57
+ EOF
58
+ comment = util_get_comment content
59
+ assert_equal 'This just contains plain old documentation', comment
60
+ end
61
+
62
+ # Get the comment of the @top_level when it has processed the input.
63
+ def util_get_comment(content)
64
+ parser = util_parser content
65
+ parser.scan.comment
66
+ end
67
+
68
+ # create a new parser with the supplied content.
69
+ def util_parser(content)
70
+ RDoc::Parser::PerlPOD.new @top_level, @fn, content, @options, @stats
71
+ end
72
+
73
+ end
74
+
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdoc-perl_pod
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - Eric Hodel
13
+ - Hugh Sasse
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain:
17
+ - |
18
+ -----BEGIN CERTIFICATE-----
19
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
20
+ YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
21
+ ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
22
+ cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
23
+ FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
24
+ LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
25
+ U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
26
+ Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
27
+ mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
28
+ g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
29
+ sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
30
+ BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
31
+ kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
32
+ bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
33
+ DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
34
+ UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
35
+ 14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
36
+ x52qPcexcYZR7w==
37
+ -----END CERTIFICATE-----
38
+
39
+ date: 2010-12-23 00:00:00 -08:00
40
+ default_executable:
41
+ dependencies:
42
+ - !ruby/object:Gem::Dependency
43
+ name: rdoc
44
+ prerelease: false
45
+ requirement: &id001 !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ~>
49
+ - !ruby/object:Gem::Version
50
+ hash: 5
51
+ segments:
52
+ - 3
53
+ version: "3"
54
+ type: :runtime
55
+ version_requirements: *id001
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest
58
+ prerelease: false
59
+ requirement: &id002 !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 15
65
+ segments:
66
+ - 2
67
+ - 0
68
+ - 0
69
+ version: 2.0.0
70
+ type: :development
71
+ version_requirements: *id002
72
+ - !ruby/object:Gem::Dependency
73
+ name: isolate
74
+ prerelease: false
75
+ requirement: &id003 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ hash: 5
81
+ segments:
82
+ - 3
83
+ version: "3"
84
+ type: :development
85
+ version_requirements: *id003
86
+ - !ruby/object:Gem::Dependency
87
+ name: hoe
88
+ prerelease: false
89
+ requirement: &id004 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 19
95
+ segments:
96
+ - 2
97
+ - 7
98
+ - 0
99
+ version: 2.7.0
100
+ type: :development
101
+ version_requirements: *id004
102
+ description: |-
103
+ A parser for Perl's POD documentation format. Allows Perl and Ruby
104
+ documentation to be used together.
105
+ email:
106
+ - drbrain@segment7.net
107
+ - hgs@dmu.ac.uk
108
+ executables: []
109
+
110
+ extensions: []
111
+
112
+ extra_rdoc_files:
113
+ - History.txt
114
+ - Manifest.txt
115
+ - README.txt
116
+ files:
117
+ - History.txt
118
+ - Manifest.txt
119
+ - README.txt
120
+ - Rakefile
121
+ - lib/rdoc/discover.rb
122
+ - lib/rdoc/parser/perl_pod.rb
123
+ - test/test_rdoc_parser_perl.rb
124
+ has_rdoc: true
125
+ homepage: https://github.com/rdoc/rdoc-perl_pod
126
+ licenses: []
127
+
128
+ post_install_message:
129
+ rdoc_options:
130
+ - --main
131
+ - README.txt
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ hash: 3
140
+ segments:
141
+ - 0
142
+ version: "0"
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ requirements: []
153
+
154
+ rubyforge_project: rdoc
155
+ rubygems_version: 1.3.7
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: A parser for Perl's POD documentation format
159
+ test_files:
160
+ - test/test_rdoc_parser_perl.rb
Binary file