|
| 1 | +# |
| 2 | +# xs.ctags --- interface description file format used to create an extension interface between Perl and C code |
| 3 | +# |
| 4 | +# Copyright (c) 2022, Red Hat, Inc. |
| 5 | +# Copyright (c) 2022, Masatake YAMATO |
| 6 | +# |
| 7 | +# Author: Masatake YAMATO < [email protected]> |
| 8 | +# |
| 9 | +# This program is free software; you can redistribute it and/or |
| 10 | +# modify it under the terms of the GNU General Public License |
| 11 | +# as published by the Free Software Foundation; either version 2 |
| 12 | +# of the License, or (at your option) any later version. |
| 13 | +# |
| 14 | +# This program is distributed in the hope that it will be useful, |
| 15 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +# GNU General Public License for more details. |
| 18 | +# |
| 19 | +# You should have received a copy of the GNU General Public License |
| 20 | +# along with this program; if not, write to the Free Software |
| 21 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 22 | +# USA. |
| 23 | +# |
| 24 | +# References: |
| 25 | +# |
| 26 | +# - https://perldoc.perl.org/perlxs |
| 27 | +# |
| 28 | + |
| 29 | +# |
| 30 | +# TODO: |
| 31 | +# |
| 32 | +# - tagging the prefix trimmed function names |
| 33 | +# - capture aliases |
| 34 | +# - capture signatures of functions, |
| 35 | +# - make reftag for INCLUDE'ed files |
| 36 | +# - separators |
| 37 | +# |
| 38 | + |
| 39 | +--langdef=XS |
| 40 | +--map-XS=+.xs |
| 41 | + |
| 42 | +# |
| 43 | +# Kind definitions |
| 44 | +# |
| 45 | + |
| 46 | +--kinddef-XS=m,module,modules |
| 47 | +--kinddef-XS=p,package,packages |
| 48 | +--kinddef-XS=f,function,functions |
| 49 | + |
| 50 | +# |
| 51 | +# Tables declaration |
| 52 | +# |
| 53 | + |
| 54 | +--_tabledef-XS=init |
| 55 | +--_tabledef-XS=main |
| 56 | +--_tabledef-XS=func |
| 57 | +--_tabledef-XS=keywords |
| 58 | + |
| 59 | +# |
| 60 | +# Prelude |
| 61 | +# |
| 62 | + |
| 63 | +--_prelude-XS={{ |
| 64 | + /scope false def |
| 65 | + /xsstart false def |
| 66 | + /prefix false def |
| 67 | +}} |
| 68 | + |
| 69 | +# |
| 70 | +# Tables definitions |
| 71 | +# |
| 72 | + |
| 73 | +# keywords table |
| 74 | +--_mtable-regex-XS=keywords/(?:REQUIRE|BOOT|CASE|PREINIT|INPUT|INIT|CODE|PPCODE|OUTPUT|CLEANUP|ALIAS|ATTRS|PROTOTYPES|PROTOTYPE|VERSIONCHECK|INCLUDE|INCLUDE_COMMAND|SCOPE|INTERFACE|INTERFACE_MACRO|C_ARGS|POSTCALL|OVERLOAD|FALLBACK|EXPORT_XSUB_SYMBOLS)[^\n]*\n//{pcre2} |
| 75 | + |
| 76 | +# init table |
| 77 | +--_mtable-regex-XS=init/((?:.*?)[\n])[ \t]*(MODULE[ \t]*=)//{pcre2}{tjump=main}{_guest=C,1start,1end}{_advanceTo=2start}{{ |
| 78 | + /xsstart 2 /start _matchloc def |
| 79 | +}} |
| 80 | + |
| 81 | +# main table |
| 82 | +--_mtable-regex-XS=main/[ \t]*MODULE[ \t]*=[ \t]*([^ \t\n]+)([ \t]*PACKAGE[ \t]*=[ \t]*([^ \t\n]+))?([ \t]*PREFIX[ \t]*=[ \t]*([^ \t\n]+))?[^\n]*\n/\1/m/{{ |
| 83 | + \3 false ne { |
| 84 | + % Make a tag for the package and set it to the scope. |
| 85 | + \3 /package 3 /start _matchloc _tag _commit dup . scope: |
| 86 | + } { |
| 87 | + % Make a tag for the module and set it to the scope. |
| 88 | + . |
| 89 | + } ifelse |
| 90 | + /scope exch def |
| 91 | + |
| 92 | + % Record the prefix. |
| 93 | + \5 false ne { |
| 94 | + /prefix \5 def |
| 95 | + } if |
| 96 | +}} |
| 97 | + |
| 98 | +--_mtable-regex-XS=main/[\t ]+[^\n]*\n// |
| 99 | +--_mtable-extend-XS=main+keywords |
| 100 | +--_mtable-regex-XS=main/([A-Za-z_].*?)[\t ]*\n//{tenter=func}{pcre2}{{ |
| 101 | + % return type |
| 102 | + \1 |
| 103 | +}} |
| 104 | + |
| 105 | +--_mtable-regex-XS=main/[^\n]*\n// |
| 106 | +--_mtable-regex-XS=main/()//{tquit}{{ |
| 107 | + xsstart false ne { |
| 108 | + (CPreProcessor) xsstart 1 /start _matchloc _makepromise pop |
| 109 | + } if |
| 110 | +}} |
| 111 | + |
| 112 | +# func table |
| 113 | +--_mtable-extend-XS=func+keywords |
| 114 | +--_mtable-regex-XS=func/([A-Za-z_][a-zA-Z0-9_]*)[ \t]*\(/\1/f/{tleave}{{ |
| 115 | + % function name |
| 116 | + count 0 gt { |
| 117 | + % TODO prefix handling |
| 118 | + % Fill the scope: field. |
| 119 | + . scope scope: |
| 120 | + % if a return type is on the stack, set it to typeref: field. |
| 121 | + % Should we consdier "struct", "union", and "enum" here? |
| 122 | + . exch typeref: |
| 123 | + } if |
| 124 | +}} |
| 125 | +--_mtable-regex-XS=func/[^\n]*\n//{tleave} |
| 126 | +--_mtable-regex-XS=func/.//{tleave} |
0 commit comments