Skip to content

Commit

Permalink
Adds recognition of char literals (Fixes #36) (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Animeshz authored Feb 7, 2021
1 parent 66f983e commit e2b7595
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
20 changes: 20 additions & 0 deletions dist/Kotlin.JSON-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,26 @@
"include": "#string-content"
}
]
},
{
"begin": "'",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.kotlin"
}
},
"end": "'",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.kotlin"
}
},
"name": "string.quoted.single.kotlin",
"patterns": [
{
"include": "#string-content"
}
]
}
],
"repository": {
Expand Down
1 change: 1 addition & 0 deletions dist/Kotlin.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ repository:
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.double.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.single.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}]}
'null':
Expand Down
31 changes: 31 additions & 0 deletions dist/Kotlin.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,37 @@
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>'</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.begin.kotlin</string>
</dict>
</dict>
<key>end</key>
<string>'</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.end.kotlin</string>
</dict>
</dict>
<key>name</key>
<string>string.quoted.single.kotlin</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#string-content</string>
</dict>
</array>
</dict>
</array>
<key>repository</key>
<dict>
Expand Down
13 changes: 13 additions & 0 deletions src/literals.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ repository:
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.single.kotlin
patterns:
-
include: '#string-content'
repository:
string-content:
patterns:
Expand Down
12 changes: 11 additions & 1 deletion test/literals.test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,19 @@
foo('"')
//^^^ source.kotlin
// ^ source.kotlin meta.group.kotlin punctuation.section.group.begin.kotlin
// ^^^ source.kotlin meta.group.kotlin
// ^ source.kotlin meta.group.kotlin string.quoted.single.kotlin punctuation.definition.string.begin.kotlin
// ^ source.kotlin meta.group.kotlin string.quoted.single.kotlin
// ^ source.kotlin meta.group.kotlin string.quoted.single.kotlin punctuation.definition.string.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.single.kotlin punctuation.definition.string.begin.kotlin
// ^^ source.kotlin meta.group.kotlin string.quoted.single.kotlin constant.character.escape.kotlin
// ^ source.kotlin meta.group.kotlin string.quoted.single.kotlin punctuation.definition.string.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
Expand Down

0 comments on commit e2b7595

Please sign in to comment.