Skip to content

Commit

Permalink
rpmMacros: process areas surrounded by pairs of curly bracket
Browse files Browse the repository at this point in the history
The original code processed the line ended with \ only.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Dec 22, 2023
1 parent 293f11e commit d7efad9
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");

Check warning on line 15 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L15

Added line #L15 was not covered by tests
addLanguageRegexTable (language, "contline");
addLanguageRegexTable (language, "mbody");
addLanguageRegexTable (language, "mbody0");

Check warning on line 18 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L17-L18

Added lines #L17 - L18 were not covered by tests

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",

Check warning on line 42 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L42

Added line #L42 was not covered by tests
"^[^\n]+",
"", "", "", NULL);
addLanguageTagMultiTableRegex (language, "comment",

Check warning on line 45 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L45

Added line #L45 was not covered by tests
"^[\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",

Check warning on line 63 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L63

Added line #L63 was not covered by tests
"^([^\\\\{}#]+)",
"", "", "", NULL);
addLanguageTagMultiTableRegex (language, "mbody",

Check warning on line 66 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L66

Added line #L66 was not covered by tests
"^#",
"", "", "{tenter=comment}", NULL);
addLanguageTagMultiTableRegex (language, "mbody",

Check warning on line 69 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L69

Added line #L69 was not covered by tests
"^([{])",
"", "", "{tenter=mbody0}", NULL);
addLanguageTagMultiTableRegex (language, "mbody",

Check warning on line 72 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L72

Added line #L72 was not covered by tests
"^([}])",
"", "", "{tleave}"
"{{\n"
" dup :line @1 _matchloc2line eq {\n"
" pop\n"
" } {\n"
" @1 end:\n"
" } ifelse\n"
"}}", NULL);
addLanguageTagMultiTableRegex (language, "mbody",

Check warning on line 82 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L82

Added line #L82 was not covered by tests
"^\\\\.",
"", "", "", NULL);
addLanguageTagMultiTableRegex (language, "mbody0",

Check warning on line 85 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L85

Added line #L85 was not covered by tests
"^[^\\\\{}#]+",
"", "", "", NULL);
addLanguageTagMultiTableRegex (language, "mbody0",

Check warning on line 88 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L88

Added line #L88 was not covered by tests
"^[{]",
"", "", "{tenter=mbody0}", NULL);
addLanguageTagMultiTableRegex (language, "mbody0",

Check warning on line 91 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L91

Added line #L91 was not covered by tests
"^#",
"", "", "{tenter=comment}", NULL);
addLanguageTagMultiTableRegex (language, "mbody0",

Check warning on line 94 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L94

Added line #L94 was not covered by tests
"^\\\\.",
"", "", "", NULL);
addLanguageTagMultiTableRegex (language, "mbody0",

Check warning on line 97 in optlib/rpmMacros.c

View check run for this annotation

Codecov / codecov/patch

optlib/rpmMacros.c#L97

Added line #L97 was not covered by tests
"^([}])",
"", "", "{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 d7efad9

Please sign in to comment.