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