1# 2# 3# Copyright (c) 2016, Red Hat, Inc. 4# Copyright (c) 2016, Masatake YAMATO 5# 6# Author: Masatake YAMATO <yamato@redhat.com> 7# 8# This program is free software; you can redistribute it and/or 9# modify it under the terms of the GNU General Public License 10# as published by the Free Software Foundation; either version 2 11# of the License, or (at your option) any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17# 18# You should have received a copy of the GNU General Public License 19# along with this program; if not, write to the Free Software 20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 21# USA. 22# 23# This module extracts headers of Pod file. 24# 25# References: 26# - https://perldoc.perl.org/perlpod 27# - https://perldoc.perl.org/perlpodspec 28# 29--langdef=Pod 30--map-Pod=+.pod 31 32--kinddef-Pod=c,chapter,chapters 33--kinddef-Pod=s,section,sections 34--kinddef-Pod=S,subsection,subsections 35--kinddef-Pod=t,subsubsection,subsubsections 36 37# Separator definitions must come after kind definitions. 38# This is the limitation of optlib2c. 39--_scopesep-Pod=*/*:"" 40 41--_prelude-Pod={{ 42 /kindTable [ 43 /chapter /section /subsection /subsubsection 44 ] def 45 46 % numstr:str TOLEVEL int 47 /tolevel { 48 0 get ?1 sub 49 } def 50 51 /depthForCork { 52 :kind kindTable exch _aindex pop 53 } def 54 55 % endline:int goal:int scopePopUpTo - 56 /scopePopUpTo 57 { 58 { 59 _scopetop { 60 dup 61 % endline goal scope scope 62 depthForCork 2 index ge { 63 % endline goal scope 64 2 index end: 65 _scopepop 66 } { 67 pop 68 exit 69 } ifelse 70 } { 71 exit 72 } ifelse 73 } loop 74 pop 75 pop 76 } def 77}} 78 79--regex-Pod=/^=head([1-4])[ \t]+(.+)//{{ 80 \2 81 kindTable \1 tolevel get 82 2 /start _matchloc 83 _tag _commit 84 dup :line 1 sub \1 tolevel scopePopUpTo 85 _scopetop { 86 1 index exch scope: _scopepush 87 } { 88 _scopepush 89 } ifelse 90}} 91