Skip to content

Commit

Permalink
Allow macros within changelog body (#15)
Browse files Browse the repository at this point in the history
This resolves issue #11 where the %autochangelog macro is throwing a
parsing error.
  • Loading branch information
tlusk authored Dec 19, 2022
1 parent aa44f04 commit 2d81e58
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/grammars/RpmSpecParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ filesBody ::= (filesDirective|COMMENT|EOL|<<ifExpr filesBody>>|macroDefinition|m
filesDirective ::= FILES_DIRECTIVE_TOKEN (filesDirective|anything)* {pin=1}

changelogSection ::= changelog changelogBody {pin=1}
changelogBody ::= (EOL|changelogItem)*
changelogBody ::= (EOL|changelogItem|fullMacro)*
changelogItem ::= (changelogHeader EOL changelogEntry*)
changelogHeader ::= CL_HEADER_TOKEN changelogDate changelogAuthor changelogEmail? '-'? changelogVersion? {pin=1}
changelogDate ::= IDENTIFIER IDENTIFIER INTEGER_LITERAL INTEGER_LITERAL
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<b>Changes in version 2.1.0:</b>
<ul>
<li>Build against IntelliJ 2022.3 and Java 17</li>
<li>Allow macros such as %autochangelog within the changelog section</li>
</ul><br>
</html>
]]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class RpmSpecParsingTest : ParsingTestCase("", "spec", RpmSpecParserDefinition()
doTest(true)
}

fun testAutoSpecTestData() {
doTest(true)
}

override fun getTestDataPath(): String = "src/test/resources/spec"

override fun skipSpaces(): Boolean = false
Expand Down
47 changes: 47 additions & 0 deletions src/test/resources/spec/AutoSpecTestData.RpmSpec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
RPM SPEC File(0,129)
RpmSpecPackageBodyImpl(PACKAGE_BODY)(0,77)
RpmSpecTagImpl(TAG)(0,28)
PsiElement(RpmSpecTokenType.IDENTIFIER)('Name')(0,4)
PsiElement(RpmSpecTokenType.:)(':')(4,5)
PsiWhiteSpace(' ')(5,16)
RpmSpecTagValueImpl(TAG_VALUE)(16,28)
PsiElement(RpmSpecTokenType.CODE)('test-package')(16,28)
PsiElement(RpmSpecTokenType.EOL)('\n')(28,29)
RpmSpecTagImpl(TAG)(29,57)
PsiElement(RpmSpecTokenType.IDENTIFIER)('Version')(29,36)
PsiElement(RpmSpecTokenType.:)(':')(36,37)
PsiWhiteSpace(' ')(37,45)
RpmSpecTagValueImpl(TAG_VALUE)(45,57)
RpmSpecFullMacroImpl(FULL_MACRO)(45,57)
PsiElement(RpmSpecTokenType.%)('%')(45,46)
RpmSpecMacroImpl(MACRO)(46,57)
PsiElement(RpmSpecTokenType.IDENTIFIER)('autorelease')(46,57)
PsiElement(RpmSpecTokenType.EOL)('\n')(57,58)
RpmSpecTagImpl(TAG)(58,75)
PsiElement(RpmSpecTokenType.IDENTIFIER)('Release')(58,65)
PsiElement(RpmSpecTokenType.:)(':')(65,66)
PsiWhiteSpace(' ')(66,74)
RpmSpecTagValueImpl(TAG_VALUE)(74,75)
PsiElement(RpmSpecTokenType.INTEGER_LITERAL)('1')(74,75)
PsiElement(RpmSpecTokenType.EOL)('\n')(75,76)
PsiElement(RpmSpecTokenType.EOL)('\n')(76,77)
RpmSpecOtherSectionsImpl(OTHER_SECTIONS)(77,104)
RpmSpecGenericSectionImpl(GENERIC_SECTION)(77,104)
PsiElement(RpmSpecTokenType.SHELL_SECTION)('%build')(77,83)
PsiElement(RpmSpecTokenType.EOL)('\n')(83,84)
RpmSpecGenericBodyImpl(GENERIC_BODY)(84,104)
PsiElement(RpmSpecTokenType.IDENTIFIER)('echo')(84,88)
PsiWhiteSpace(' ')(88,89)
PsiElement(RpmSpecTokenType.CODE)('"Hello')(89,95)
PsiWhiteSpace(' ')(95,96)
PsiElement(RpmSpecTokenType.CODE)('World"')(96,102)
PsiElement(RpmSpecTokenType.EOL)('\n')(102,103)
PsiElement(RpmSpecTokenType.EOL)('\n')(103,104)
RpmSpecChangelogSectionImpl(CHANGELOG_SECTION)(104,129)
PsiElement(RpmSpecTokenType.changelog)('%changelog')(104,114)
RpmSpecChangelogBodyImpl(CHANGELOG_BODY)(114,129)
PsiElement(RpmSpecTokenType.EOL)('\n')(114,115)
RpmSpecFullMacroImpl(FULL_MACRO)(115,129)
PsiElement(RpmSpecTokenType.%)('%')(115,116)
RpmSpecMacroImpl(MACRO)(116,129)
PsiElement(RpmSpecTokenType.IDENTIFIER)('autochangelog')(116,129)
9 changes: 9 additions & 0 deletions src/test/resources/spec/AutoSpecTestData.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Name: test-package
Version: %autorelease
Release: 1

%build
echo "Hello World"

%changelog
%autochangelog
47 changes: 47 additions & 0 deletions src/test/resources/spec/AutoSpecTestData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
RPM SPEC File(0,129)
RpmSpecPackageBodyImpl(PACKAGE_BODY)(0,77)
RpmSpecTagImpl(TAG)(0,28)
PsiElement(RpmSpecTokenType.IDENTIFIER)('Name')(0,4)
PsiElement(RpmSpecTokenType.:)(':')(4,5)
PsiWhiteSpace(' ')(5,16)
RpmSpecTagValueImpl(TAG_VALUE)(16,28)
PsiElement(RpmSpecTokenType.CODE)('test-package')(16,28)
PsiElement(RpmSpecTokenType.EOL)('\n')(28,29)
RpmSpecTagImpl(TAG)(29,57)
PsiElement(RpmSpecTokenType.IDENTIFIER)('Version')(29,36)
PsiElement(RpmSpecTokenType.:)(':')(36,37)
PsiWhiteSpace(' ')(37,45)
RpmSpecTagValueImpl(TAG_VALUE)(45,57)
RpmSpecFullMacroImpl(FULL_MACRO)(45,57)
PsiElement(RpmSpecTokenType.%)('%')(45,46)
RpmSpecMacroImpl(MACRO)(46,57)
PsiElement(RpmSpecTokenType.IDENTIFIER)('autorelease')(46,57)
PsiElement(RpmSpecTokenType.EOL)('\n')(57,58)
RpmSpecTagImpl(TAG)(58,75)
PsiElement(RpmSpecTokenType.IDENTIFIER)('Release')(58,65)
PsiElement(RpmSpecTokenType.:)(':')(65,66)
PsiWhiteSpace(' ')(66,74)
RpmSpecTagValueImpl(TAG_VALUE)(74,75)
PsiElement(RpmSpecTokenType.INTEGER_LITERAL)('1')(74,75)
PsiElement(RpmSpecTokenType.EOL)('\n')(75,76)
PsiElement(RpmSpecTokenType.EOL)('\n')(76,77)
RpmSpecOtherSectionsImpl(OTHER_SECTIONS)(77,104)
RpmSpecGenericSectionImpl(GENERIC_SECTION)(77,104)
PsiElement(RpmSpecTokenType.SHELL_SECTION)('%build')(77,83)
PsiElement(RpmSpecTokenType.EOL)('\n')(83,84)
RpmSpecGenericBodyImpl(GENERIC_BODY)(84,104)
PsiElement(RpmSpecTokenType.IDENTIFIER)('echo')(84,88)
PsiWhiteSpace(' ')(88,89)
PsiElement(RpmSpecTokenType.CODE)('"Hello')(89,95)
PsiWhiteSpace(' ')(95,96)
PsiElement(RpmSpecTokenType.CODE)('World"')(96,102)
PsiElement(RpmSpecTokenType.EOL)('\n')(102,103)
PsiElement(RpmSpecTokenType.EOL)('\n')(103,104)
RpmSpecChangelogSectionImpl(CHANGELOG_SECTION)(104,129)
PsiElement(RpmSpecTokenType.changelog)('%changelog')(104,114)
RpmSpecChangelogBodyImpl(CHANGELOG_BODY)(114,129)
PsiElement(RpmSpecTokenType.EOL)('\n')(114,115)
RpmSpecFullMacroImpl(FULL_MACRO)(115,129)
PsiElement(RpmSpecTokenType.%)('%')(115,116)
RpmSpecMacroImpl(MACRO)(116,129)
PsiElement(RpmSpecTokenType.IDENTIFIER)('autochangelog')(116,129)

0 comments on commit 2d81e58

Please sign in to comment.