diff --git a/CHANGELOG.md b/CHANGELOG.md index e0cb9bfd..628dcbd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ # SnakeCharm Plugin Changelog + +## [2024.1.2] +Released on + +### Fixed +- Improve parser error message when rule/module is declared with name but lacks ':' (see [#515](https://github.com/JetBrains-Research/snakecharm/issues/515)) + ## [2024.1.1] Released on 20 April 2024 diff --git a/src/main/kotlin/com/jetbrains/snakecharm/lang/parser/SmkStatementParsing.kt b/src/main/kotlin/com/jetbrains/snakecharm/lang/parser/SmkStatementParsing.kt index 5d6c06ac..2d4eb63c 100644 --- a/src/main/kotlin/com/jetbrains/snakecharm/lang/parser/SmkStatementParsing.kt +++ b/src/main/kotlin/com/jetbrains/snakecharm/lang/parser/SmkStatementParsing.kt @@ -180,20 +180,25 @@ class SmkStatementParsing( } // Other case: `rule` / `checkpoint` / etc. + var nameIdentifierSeen = false if (atToken(PyTokenTypes.IDENTIFIER)) { // rule name //val ruleNameMarker: PsiBuilder.Marker = myBuilder.mark() nextToken() + nameIdentifierSeen = true } // XXX at the moment we continue parsing rule even if colon missed, probably better // XXX to drop rule and scroll up to next STATEMENT_BREAK/RULE/CHECKPOINT/other toplevel keyword or eof() - checkMatches(PyTokenTypes.COLON, - "${ + checkMatches( + PyTokenTypes.COLON, + if (nameIdentifierSeen) { + "':' expected" + } else { section.name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() - } - } name identifier or ':' expected" + } + " name identifier or ':' expected" + } ) // bundle val ruleStatements = myBuilder.mark() diff --git a/testData/psi/ModuleIncomplete.txt b/testData/psi/ModuleIncomplete.txt index 20124bed..c5ee6bcc 100644 --- a/testData/psi/ModuleIncomplete.txt +++ b/testData/psi/ModuleIncomplete.txt @@ -11,7 +11,7 @@ SnakemakeFile: ModuleIncomplete.smk PsiElement(Py:MODULE_KEYWORD)('module') PsiWhiteSpace(' ') PsiElement(Py:IDENTIFIER)('z') - PsiErrorElement:Module name identifier or ':' expected + PsiErrorElement:':' expected PyStatementList PsiErrorElement:Indent expected diff --git a/testData/psi/RuleIncomplete2.txt b/testData/psi/RuleIncomplete2.txt index 6187ac45..cddb100b 100644 --- a/testData/psi/RuleIncomplete2.txt +++ b/testData/psi/RuleIncomplete2.txt @@ -3,7 +3,7 @@ SnakemakeFile: RuleIncomplete2.smk PsiElement(Py:RULE_KEYWORD)('rule') PsiWhiteSpace(' ') PsiElement(Py:IDENTIFIER)('foo') - PsiErrorElement:Rule name identifier or ':' expected + PsiErrorElement:':' expected PyStatementList