From d7efad9775672c44aea9e0754e80bb6924f92abb Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Fri, 22 Dec 2023 09:05:19 +0900 Subject: [PATCH] rpmMacros: process areas surrounded by pairs of curly bracket The original code processed the line ended with \ only. Signed-off-by: Masatake YAMATO --- .../lua.d}/args.ctags | 0 Units/parser-rpmMacros.r/lua.d/expected.tags | 1 + Units/parser-rpmMacros.r/lua.d/input.macros | 39 +++++++++++ Units/parser-rpmMacros.r/simple.d/args.ctags | 3 + .../simple.d}/expected.tags | 0 .../simple.d}/input-0.macros | 0 .../simple.d}/input-1.macros | 0 .../simple.d}/input-2.macros | 0 .../simple.d}/input.macros | 0 optlib/rpmMacros.c | 67 ++++++++++++++++--- optlib/rpmMacros.ctags | 43 +++++++++--- 11 files changed, 134 insertions(+), 19 deletions(-) rename Units/{parser-rpmMacros.d => parser-rpmMacros.r/lua.d}/args.ctags (100%) create mode 100644 Units/parser-rpmMacros.r/lua.d/expected.tags create mode 100644 Units/parser-rpmMacros.r/lua.d/input.macros create mode 100644 Units/parser-rpmMacros.r/simple.d/args.ctags rename Units/{parser-rpmMacros.d => parser-rpmMacros.r/simple.d}/expected.tags (100%) rename Units/{parser-rpmMacros.d => parser-rpmMacros.r/simple.d}/input-0.macros (100%) rename Units/{parser-rpmMacros.d => parser-rpmMacros.r/simple.d}/input-1.macros (100%) rename Units/{parser-rpmMacros.d => parser-rpmMacros.r/simple.d}/input-2.macros (100%) rename Units/{parser-rpmMacros.d => parser-rpmMacros.r/simple.d}/input.macros (100%) diff --git a/Units/parser-rpmMacros.d/args.ctags b/Units/parser-rpmMacros.r/lua.d/args.ctags similarity index 100% rename from Units/parser-rpmMacros.d/args.ctags rename to Units/parser-rpmMacros.r/lua.d/args.ctags diff --git a/Units/parser-rpmMacros.r/lua.d/expected.tags b/Units/parser-rpmMacros.r/lua.d/expected.tags new file mode 100644 index 0000000000..b42d8296b3 --- /dev/null +++ b/Units/parser-rpmMacros.r/lua.d/expected.tags @@ -0,0 +1 @@ +add_sysuser input.macros /^%add_sysuser(-) %{lua:$/;" m signature:(-) end:39 diff --git a/Units/parser-rpmMacros.r/lua.d/input.macros b/Units/parser-rpmMacros.r/lua.d/input.macros new file mode 100644 index 0000000000..085bd32960 --- /dev/null +++ b/Units/parser-rpmMacros.r/lua.d/input.macros @@ -0,0 +1,39 @@ +# +# Taken from rpm/macros.in +# + +# Add a sysuser user/group to a package. Takes a sysusers.d(5) line as +# arguments, eg `%add_sysuser g mygroup 515`. +# -b option omits the "Provides: " to support formatting the entry outside +# spec context. +%add_sysuser(-) %{lua: + if arg[1] == '-b' then + prefix = '' + table.remove(arg, 1) + else + prefix = 'Provides: ' + end + if #arg < 2 then + error('not enough arguments') + end + if arg[1] == 'g' then + type = 'group' + elseif arg[1] == 'u' then + type = 'user' + else + error('invalid sysuser type: '..arg[1]) + end + name = arg[2] + line = table.concat(arg, ' ') + -- \0-pad source string to avoid '=' in the output + llen = line:len() + ulen = math.ceil(4 * (llen / 3)) + plen = 4 * math.ceil(llen / 3) + pad = string.rep('\\0', plen-ulen) + enc = rpm.b64encode(line..pad, 0); + + print(string.format('%s%s(%s) = %s\\n', prefix, type, name, enc)) + if type == 'user' then + print(string.format('%s%s(%s)\\n', prefix, 'group', name)) + end +} diff --git a/Units/parser-rpmMacros.r/simple.d/args.ctags b/Units/parser-rpmMacros.r/simple.d/args.ctags new file mode 100644 index 0000000000..0ddd743779 --- /dev/null +++ b/Units/parser-rpmMacros.r/simple.d/args.ctags @@ -0,0 +1,3 @@ +--sort=no +--fields=+eS +--map-RpmMacros=+.macros diff --git a/Units/parser-rpmMacros.d/expected.tags b/Units/parser-rpmMacros.r/simple.d/expected.tags similarity index 100% rename from Units/parser-rpmMacros.d/expected.tags rename to Units/parser-rpmMacros.r/simple.d/expected.tags diff --git a/Units/parser-rpmMacros.d/input-0.macros b/Units/parser-rpmMacros.r/simple.d/input-0.macros similarity index 100% rename from Units/parser-rpmMacros.d/input-0.macros rename to Units/parser-rpmMacros.r/simple.d/input-0.macros diff --git a/Units/parser-rpmMacros.d/input-1.macros b/Units/parser-rpmMacros.r/simple.d/input-1.macros similarity index 100% rename from Units/parser-rpmMacros.d/input-1.macros rename to Units/parser-rpmMacros.r/simple.d/input-1.macros diff --git a/Units/parser-rpmMacros.d/input-2.macros b/Units/parser-rpmMacros.r/simple.d/input-2.macros similarity index 100% rename from Units/parser-rpmMacros.d/input-2.macros rename to Units/parser-rpmMacros.r/simple.d/input-2.macros diff --git a/Units/parser-rpmMacros.d/input.macros b/Units/parser-rpmMacros.r/simple.d/input.macros similarity index 100% rename from Units/parser-rpmMacros.d/input.macros rename to Units/parser-rpmMacros.r/simple.d/input.macros diff --git a/optlib/rpmMacros.c b/optlib/rpmMacros.c index 539fdb63ab..1d9c5a4c02 100644 --- a/optlib/rpmMacros.c +++ b/optlib/rpmMacros.c @@ -12,34 +12,44 @@ static void initializeRpmMacrosParser (const langType language) { addLanguageRegexTable (language, "main"); + addLanguageRegexTable (language, "comment"); addLanguageRegexTable (language, "contline"); + addLanguageRegexTable (language, "mbody"); + addLanguageRegexTable (language, "mbody0"); addLanguageTagMultiTableRegex (language, "main", - "^#[^\n]*\n?", - "", "", "", NULL); + "^#", + "", "", "{tenter=comment}", NULL); addLanguageTagMultiTableRegex (language, "main", - "^%([_a-zA-Z0-9]+)(\\([^)]*\\))*[^\n]*([^\n])\n?", + "^%([_a-zA-Z0-9]+)(\\([^)]*\\))*[^{\n\\\\]*([\n]|[\\\\][\n]|[{]|[\\\\])", "\\1", "m", "" "{{\n" " \\2 false ne {\n" " . \\2 signature:\n" " } if\n" - " \\3 (\\\\) eq {\n" - " % push the current tag for attaching end: later\n" - " .\n" - " % Skip next line if \\ is at the enf of the current line.\n" - " /contline _tenter\n" + " \\3 ({) eq {\n" + " .\n" + " /mbody _tenter\n" + " } if\n" + " \\3 (\\\\\\n) eq {\n" + " .\n" + " /contline _tenter\n" " } if\n" "}}", NULL); addLanguageTagMultiTableRegex (language, "main", "^.", "", "", "", NULL); + addLanguageTagMultiTableRegex (language, "comment", + "^[^\n]+", + "", "", "", NULL); + addLanguageTagMultiTableRegex (language, "comment", + "^[\n]", + "", "", "{tleave}", NULL); addLanguageTagMultiTableRegex (language, "contline", "^(\n)", - "", "", "" + "", "", "{tleave}" "{{\n" " @1 end:\n" - " _tleave\n" "}}", NULL); addLanguageTagMultiTableRegex (language, "contline", "^[^\n]*([^\n])\n?", @@ -50,6 +60,43 @@ static void initializeRpmMacrosParser (const langType language) " _tleave\n" " } if\n" "}}", NULL); + addLanguageTagMultiTableRegex (language, "mbody", + "^([^\\\\{}#]+)", + "", "", "", NULL); + addLanguageTagMultiTableRegex (language, "mbody", + "^#", + "", "", "{tenter=comment}", NULL); + addLanguageTagMultiTableRegex (language, "mbody", + "^([{])", + "", "", "{tenter=mbody0}", NULL); + addLanguageTagMultiTableRegex (language, "mbody", + "^([}])", + "", "", "{tleave}" + "{{\n" + " dup :line @1 _matchloc2line eq {\n" + " pop\n" + " } {\n" + " @1 end:\n" + " } ifelse\n" + "}}", NULL); + addLanguageTagMultiTableRegex (language, "mbody", + "^\\\\.", + "", "", "", NULL); + addLanguageTagMultiTableRegex (language, "mbody0", + "^[^\\\\{}#]+", + "", "", "", NULL); + addLanguageTagMultiTableRegex (language, "mbody0", + "^[{]", + "", "", "{tenter=mbody0}", NULL); + addLanguageTagMultiTableRegex (language, "mbody0", + "^#", + "", "", "{tenter=comment}", NULL); + addLanguageTagMultiTableRegex (language, "mbody0", + "^\\\\.", + "", "", "", NULL); + addLanguageTagMultiTableRegex (language, "mbody0", + "^([}])", + "", "", "{tleave}", NULL); } extern parserDefinition* RpmMacrosParser (void) diff --git a/optlib/rpmMacros.ctags b/optlib/rpmMacros.ctags index 47c996c7da..43a3c3f912 100644 --- a/optlib/rpmMacros.ctags +++ b/optlib/rpmMacros.ctags @@ -27,25 +27,50 @@ --kinddef-RpmMacros=m,macro,macros --_tabledef-RpmMacros=main +--_tabledef-RpmMacros=comment --_tabledef-RpmMacros=contline +--_tabledef-RpmMacros=mbody +--_tabledef-RpmMacros=mbody0 ---_mtable-regex-RpmMacros=main/^#[^\n]*\n?// ---_mtable-regex-RpmMacros=main/^%([_a-zA-Z0-9]+)(\([^)]*\))*[^\n]*([^\n])\n?/\1/m/{{ +--_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 { - % push the current tag for attaching end: later - . - % Skip next line if \ is at the enf of the current line. - /contline _tenter + \3 ({) eq { + . + /mbody _tenter + } if + \3 (\\\n) eq { + . + /contline _tenter } if }} --_mtable-regex-RpmMacros=main/.// ---_mtable-regex-RpmMacros=contline/(\n)//{{ +--_mtable-regex-RpmMacros=contline/(\n)//{tleave}{{ @1 end: - _tleave }} --_mtable-regex-RpmMacros=contline/^[^\n]*([^\n])\n?///{{ \1 (\\) eq not {