#
#  rpmMacros.ctags --- multitable regex parser for /usr/lib/rpm/macros files
#
#  Copyright (c) 2021 Masatake YAMATO
#  Copyright (c) 2021 Red Hat, Inc.
#
#  This source code is released for free distribution under the terms of the
#  GNU General Public License version 2 or (at your option) any later version.
#
# References:
#
# - https://rpm.org/user_doc/macros.html
#
# TODO:
#
# - Run Lua parser as a subparser
#
--langdef=RpmMacros

# This map is too generic.
# e.g. "macros.h" of C language input matches this pattern.
# --map-RpmMacros=+(macros.*)

# This one is too general.
# --map-RpmMacros=+(macros)

--kinddef-RpmMacros=m,macro,macros

--_tabledef-RpmMacros=main
--_tabledef-RpmMacros=comment
--_tabledef-RpmMacros=contline
--_tabledef-RpmMacros=mbody
--_tabledef-RpmMacros=mbody0

--_mtable-regex-RpmMacros=comment/[^\n]+//
--_mtable-regex-RpmMacros=comment/[\n]//{tleave}

--_mtable-regex-RpmMacros=mbody0/[^\\{}#]+//
--_mtable-regex-RpmMacros=mbody0/[{]//{tenter=mbody0}
--_mtable-regex-RpmMacros=mbody0/#//{tenter=comment}
--_mtable-regex-RpmMacros=mbody0/\\.//
--_mtable-regex-RpmMacros=mbody0/([}])//{tleave}

--_mtable-regex-RpmMacros=mbody/([^\\{}#]+)//
--_mtable-regex-RpmMacros=mbody/#//{tenter=comment}
--_mtable-regex-RpmMacros=mbody/([{])//{tenter=mbody0}
--_mtable-regex-RpmMacros=mbody/([}])//{tleave}{{
    dup :line @1 _matchloc2line eq {
        pop
    } {
        @1 end:
    } ifelse
}}
--_mtable-regex-RpmMacros=mbody/\\.//

--_mtable-regex-RpmMacros=main/#//{tenter=comment}
--_mtable-regex-RpmMacros=main/%([_a-zA-Z0-9]+)(\([^)]*\))*[^{\n\\]*([\n]|[\\][\n]|[{]|[\\])/\1/m/{{
    \2 false ne {
       . \2 signature:
    } if
    \3 ({) eq {
        .
        /mbody _tenter
    } if
    \3 (\\\n) eq {
        .
        /contline _tenter
    } if
}}
--_mtable-regex-RpmMacros=main/.//

--_mtable-regex-RpmMacros=contline/(\n)//{tleave}{{
   @1 end:
}}
--_mtable-regex-RpmMacros=contline/^[^\n]*([^\n])\n?///{{
    \1 (\\) eq not {
       1@ end:
       _tleave
    } if
}}
