Skip to content

Commit

Permalink
Support 4+ quotes at the end of multline literal
Browse files Browse the repository at this point in the history
  • Loading branch information
zhelenskiy committed May 22, 2024
1 parent 055c8d3 commit fe03019
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ development=true

#Publication
group=com.zhelenskiy
version=0.0.11
version=0.0.12
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ internal fun <T : Token> openingMultiLineStringQuoteCharHandler(
val oldSelection = textFieldState.selection
if (!oldSelection.collapsed || oldSelection.end < 2) return@f null
if (textFieldState.text[oldSelection.end - 1] != '"' || textFieldState.text[oldSelection.end - 2] != '"') return@f null
val ending = if (oldSelection.end >= 3 && textFieldState.text[oldSelection.end - 3] == '"') "" else "\"\"\""
openingBracketEventHandler(
textFieldState = textFieldState,
openingChar = '"',
openingBracket = "\"",
closingBracket = "\"\"\"",
closingBracket = ending,
addNewLinesForSelection = { false },
indent = indent,
)(keyboardEvent)
Expand Down
2 changes: 2 additions & 0 deletions library/src/commonMain/kotlin/kotlinlang/tokens/Literals.kt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ internal fun KotlinLexer.readMultiLineLiteral(): List<KotlinToken>? = buildList
}
val end = readString("\"\"\"")
if (end != null) {
val afterEnd = readWhile { it == '"' }
if (afterEnd.isNotEmpty()) add(Text.RegularLiteral(afterEnd))
mergeLastRegularLiterals()
add(Text.MultiLineStringLiteralEnd)
break
Expand Down
20 changes: 20 additions & 0 deletions library/src/commonTest/kotlin/LexerTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,26 @@ class LexerTests {
)

interpolationTests(quote, MultiLineStringLiteralStart, MultiLineStringLiteralEnd)

for (quotNumber in 0..20) {
verifyOutput(
input = "\"".repeat(quotNumber + 6),
expectedTokens = listOfNotNull(
MultiLineStringLiteralStart,
RegularLiteral("\"".repeat(quotNumber)).takeIf { quotNumber > 0 },
MultiLineStringLiteralEnd
)
)
verifyOutput(
input = "\"".repeat(quotNumber + 6) +"+3",
expectedTokens = listOfNotNull(
MultiLineStringLiteralStart,
RegularLiteral("\"".repeat(quotNumber)).takeIf { quotNumber > 0 },
MultiLineStringLiteralEnd,
Add, IntegralNumberLiteral("3")
)
)
}
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion sample/sample.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'sample'
spec.version = '0.0.11'
spec.version = '0.0.12'
spec.homepage = 'h'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit fe03019

Please sign in to comment.