Skip to content

Commit

Permalink
Merge pull request #3890 from masatake/rpmMacros--curly-bracket-areas
Browse files Browse the repository at this point in the history
rpmMacros: process areas surrounded by pairs of curly bracket
  • Loading branch information
masatake authored Dec 22, 2023
2 parents 293f11e + d7efad9 commit 1c85a6f
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 19 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions Units/parser-rpmMacros.r/lua.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_sysuser input.macros /^%add_sysuser(-) %{lua:$/;" m signature:(-) end:39
39 changes: 39 additions & 0 deletions Units/parser-rpmMacros.r/lua.d/input.macros
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions Units/parser-rpmMacros.r/simple.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--sort=no
--fields=+eS
--map-RpmMacros=+.macros
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 57 additions & 10 deletions optlib/rpmMacros.c
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand All @@ -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)
Expand Down
43 changes: 34 additions & 9 deletions optlib/rpmMacros.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1c85a6f

Please sign in to comment.