DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
POD - Plain Old Documentation
#!/usr/bin/env tt
# Author:: Daniel Brumbaugh Keeney (http://rubyforge.org/users/db-keen)
# Copyright:: 2008 Daniel Brumbaugh Keeney
# License:: GPLv3+
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
grammar Pod
rule podfile
ignored_stuff
paragraph+
end
rule pod_content
directive+
end
rule command_paragraph
'=' (
head_directive /
item_directive /
alternate_content_directive /
cut_directive /
over_directive /
pod_directive
) "\n"
end
rule pod_directive
'pod' ( space ( !newline_sequence . )* )? newline_sequence blank_line+
<PodDirectiveNode>
end
rule over_directive
content:(paragraph+) '=back'
<OverDirectiveNode>
end
rule cut_directive
'cut' ignored_stuff
<CutDirectiveNode>
end
rule ignored_stuff
( !command_paragraph ( !newline_sequence . )* newline_sequence? )*
<IgnoredStuffNode>
end
rule item_directive
'item' space+ liststyle:( !space . )+ space+ content:( !newline_sequence . )+
end
rule head_directive
'head' [1234] space content:( !newline_sequence . )+
end
rule alternate_content_directive
'begin' space+ format:( !newline_sequence . )+ newline_sequence
content:( !"=end" . )+
'=end' space+ format_again:( !newline_sequence . )+
end
rule inline_formatting
uppercase_letter '<'
(
content:( !'>' . )+ /
thickly_wrapped_inline_formatting
) '>'
end
# This rule is not in compliance with spec. The actual pod
# specification cannot be implemented in Treetop. Luckily, I wrote
# a rule in ruby to replace this one.
rule thickly_wrapped_inline_formatting
'<' (
space content:( !( space+ ">>" ) . )+ space+ /
thickly_wrapped_inline_formatting
) '>'
end
rule paragraph
verbatim_paragraph /
command_paragraph /
ordinary_paragraph
end
rule ordinary_paragraph
!space
!( '=' [a-zA-Z] )
non_blank_line+
blank_line+
<OrdinaryParagraph>
end
rule verbatim_paragraph
[ \t]
non_blank_line+
blank_line+
<VerbatimParagraph>
end
rule data_paragraph
non_blank_line+
blank_line+
<DataParagraph>
end
rule uppercase_letter
[ABCDEFGHIJKLMNOPQRSTUVWXYZ]
end
rule space
[\t ]
end
rule newline_sequence
"\r\n" / [\n\r]
end
rule blank_line
space* ( !. / newline_sequence )
end
rule non_blank_line
space* ( !newline_sequence . )+ ( !. / newline_sequence )
end
end




