Skip to content

Commit

Permalink
Fix issue with quotes inside tripple quoted string (Issue #26) (#35)
Browse files Browse the repository at this point in the history
This ensures that a triple quoted string is not closed until the
last quote. Before this patch, it would try to start closing the
triple quote starting the first quote it encounters.
  • Loading branch information
shaeberling authored Dec 23, 2020
1 parent 25c8a55 commit 66f983e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/Kotlin.JSON-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@
"name": "punctuation.definition.string.begin.kotlin"
}
},
"end": "\"\"\"",
"end": "\"\"\"(?!\")",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.kotlin"
Expand Down
2 changes: 1 addition & 1 deletion dist/Kotlin.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ repository:
- {match: '\b([0-9][0-9_]*([fFLuU]|[uU]L)?)\b', name: constant.numeric.integer.kotlin}
string:
patterns:
- {begin: '"""', beginCaptures: {'0': {name: punctuation.definition.string.begin.kotlin}}, end: '"""', endCaptures: {'0': {name: punctuation.definition.string.end.kotlin}}, name: string.quoted.triple.kotlin, patterns: [{include: '#string-content'}]}
- {begin: '"""', beginCaptures: {'0': {name: punctuation.definition.string.begin.kotlin}}, end: '"""(?!")', endCaptures: {'0': {name: punctuation.definition.string.end.kotlin}}, name: string.quoted.triple.kotlin, patterns: [{include: '#string-content'}]}
- {begin: '(?!'')"(?!'')', beginCaptures: {'0': {name: punctuation.definition.string.begin.kotlin}}, end: '"', endCaptures: {'0': {name: punctuation.definition.string.end.kotlin}}, name: string.quoted.double.kotlin, patterns: [{include: '#string-content'}]}
repository:
string-content: {patterns: [{match: '\\[0\\tnr"'']', name: constant.character.escape.kotlin}, {match: '\\(x[\da-fA-F]{2}|u[\da-fA-F]{4}|.)', name: constant.character.escape.unicode.kotlin}, {begin: '\$(\{)', beginCaptures: {'1': {name: punctuation.section.block.begin.kotlin}}, end: '\}', endCaptures: {'0': {name: punctuation.section.block.end.kotlin}}, name: entity.string.template.element.kotlin}, {match: '\$[a-zA-Z_]\w*', name: entity.string.template.element.kotlin}]}
Expand Down
2 changes: 1 addition & 1 deletion dist/Kotlin.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@
</dict>
</dict>
<key>end</key>
<string>"""</string>
<string>"""(?!")</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down
2 changes: 1 addition & 1 deletion src/literals.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ repository:
beginCaptures:
'0':
name: punctuation.definition.string.begin.kotlin
end: '"""'
end: '"""(?!")'
endCaptures:
'0':
name: punctuation.definition.string.end.kotlin
Expand Down
10 changes: 9 additions & 1 deletion test/literals.test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,12 @@
//^^^ source.kotlin
// ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin
// ^^^ source.kotlin meta.group.kotlin
// ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin
// ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin

foo(""""."""")
//^^^ source.kotlin
// ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin
// ^^^ source.kotlin meta.group.kotlin string.quoted.triple.kotlin punctuation.definition.string.begin.kotlin
// ^^^ source.kotlin meta.group.kotlin string.quoted.triple.kotlin
// ^^^ source.kotlin meta.group.kotlin string.quoted.triple.kotlin punctuation.definition.string.end.kotlin
// ^ source.kotlin meta.group.kotlin punctuation.section.group.end.kotlin
8 changes: 7 additions & 1 deletion test/regression/26.test.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// SYNTAX TEST "source.kotlin" "Double quotes in character value."
// SYNTAX TEST "source.kotlin" "Double quotes in character value and quadrupel double quotes"

foo('"')
// ^ -string.quoted.double.kotlin

val same = '"' == '"'
// ^ -string.quoted.double.kotlin
// ^ -string.quoted.double.kotlin

foo(""""."""")
//^^^^ source.kotlin
// ^ -punctuation.definition.string.end.kotlin
// ^ -punctuation.definition.string.begin.kotlin
// ^^ -string.quoted.double.kotlin

0 comments on commit 66f983e

Please sign in to comment.