Skip to content

Commit af89810

Browse files
committed
Prohibit multiline blocks starting with // to reduce JPSG false 'Malformed template near' errors
1 parent 6878044 commit af89810

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

core/src/main/java/io/timeandspace/jpsg/Generator.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,13 @@ class Generator {
615615

616616
@JvmStatic
617617
fun compileBlock(insideBlockRegex: String, keyword: String): CheckingPattern {
618-
val checkingBlock = "/[*/]\\s*$keyword[^/*]*+[*/]/"
618+
val checkingBlockBlockCommentOpening = "/\\*\\s*$keyword[^/*]*+[*/]/"
619+
// Don't allow blocks starting with `//` to be multiline (the only difference of the
620+
// checkingBlockDoubleSlash regex from checkingBlockBlockCommentOpening is exclusion of
621+
// '\n'). This is to reduce false-positive "Malformed template near" errors by JPSG on
622+
// normal // comments that happen to start with "if" or "with".
623+
val checkingBlockDoubleSlash = "//\\s*$keyword[^/*\\n]*+[*/]/"
624+
val checkingBlock = "($checkingBlockBlockCommentOpening|$checkingBlockDoubleSlash)"
619625
val block = "/[*/]\\s*" + removeSubGroupNames(insideBlockRegex) + "\\s*[*/]/"
620626
return compile(justBlockOrWholeLine(checkingBlock), justBlockOrWholeLine(block))
621627
}

0 commit comments

Comments
 (0)