Merge pull request #4041 from leandrocp/lp/elixir-multiletter-sigils

Elixir - Add support for multi-letter uppercase sigils
This commit is contained in:
Henning Dieterichs 2023-07-07 16:37:18 +02:00 коммит произвёл GitHub
Родитель 83b3cf23ca 2df7a51aa1
Коммит b9cda7e6a8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 43 добавлений и 9 удалений

Просмотреть файл

@ -303,6 +303,17 @@ testTokenization('elixir', [
]
}
],
// Sigils (multi-letter uppercase)
[
{
line: '~DX/foo/',
tokens: [
{ startIndex: 0, type: 'sigil.delimiter.elixir' },
{ startIndex: 4, type: 'sigil.elixir' },
{ startIndex: 7, type: 'sigil.delimiter.elixir' }
]
}
],
// Sigils (no interpolation)
[
{
@ -314,6 +325,17 @@ testTokenization('elixir', [
]
}
],
// Sigils (multi-letter uppercase no interpolation)
[
{
line: '~WW/foo#{1}/',
tokens: [
{ startIndex: 0, type: 'sigil.delimiter.elixir' },
{ startIndex: 4, type: 'sigil.elixir' },
{ startIndex: 11, type: 'sigil.delimiter.elixir' }
]
}
],
// Sigils (modifiers)
[
{
@ -325,6 +347,17 @@ testTokenization('elixir', [
]
}
],
// Sigils (multi-letter uppercase with modifiers)
[
{
line: '~DX/custom/az09',
tokens: [
{ startIndex: 0, type: 'sigil.delimiter.elixir' },
{ startIndex: 4, type: 'sigil.elixir' },
{ startIndex: 10, type: 'sigil.delimiter.elixir' }
]
}
],
// Module attributes
[
{

Просмотреть файл

@ -333,7 +333,8 @@ export const language = <languages.IMonarchLanguage>{
// See https://elixir-lang.org/getting-started/sigils.html
// Sigils allow for typing values using their textual representation.
// All sigils start with ~ followed by a letter indicating sigil type
// All sigils start with ~ followed by a letter or
// multi-letter uppercase starting at Elixir v1.15.0, indicating sigil type
// and then a delimiter pair enclosing the textual representation.
// Optional modifiers are allowed after the closing delimiter.
// For instance a regular expressions can be written as:
@ -353,16 +354,16 @@ export const language = <languages.IMonarchLanguage>{
sigils: [
[/~[a-z]@sigilStartDelimiter/, { token: '@rematch', next: '@sigil.interpol' }],
[/~[A-Z]@sigilStartDelimiter/, { token: '@rematch', next: '@sigil.noInterpol' }]
[/~([A-Z]+)@sigilStartDelimiter/, { token: '@rematch', next: '@sigil.noInterpol' }]
],
sigil: [
[/~([a-zA-Z])\{/, { token: '@rematch', switchTo: '@sigilStart.$S2.$1.{.}' }],
[/~([a-zA-Z])\[/, { token: '@rematch', switchTo: '@sigilStart.$S2.$1.[.]' }],
[/~([a-zA-Z])\(/, { token: '@rematch', switchTo: '@sigilStart.$S2.$1.(.)' }],
[/~([a-zA-Z])\</, { token: '@rematch', switchTo: '@sigilStart.$S2.$1.<.>' }],
[/~([a-z]|[A-Z]+)\{/, { token: '@rematch', switchTo: '@sigilStart.$S2.$1.{.}' }],
[/~([a-z]|[A-Z]+)\[/, { token: '@rematch', switchTo: '@sigilStart.$S2.$1.[.]' }],
[/~([a-z]|[A-Z]+)\(/, { token: '@rematch', switchTo: '@sigilStart.$S2.$1.(.)' }],
[/~([a-z]|[A-Z]+)\</, { token: '@rematch', switchTo: '@sigilStart.$S2.$1.<.>' }],
[
/~([a-zA-Z])(@sigilSymmetricDelimiter)/,
/~([a-z]|[A-Z]+)(@sigilSymmetricDelimiter)/,
{ token: '@rematch', switchTo: '@sigilStart.$S2.$1.$2.$2' }
]
],
@ -475,7 +476,7 @@ export const language = <languages.IMonarchLanguage>{
// Fallback to the generic sigil by default
'sigilStart.interpol': [
[
/~([a-zA-Z])@sigilStartDelimiter/,
/~([a-z]|[A-Z]+)@sigilStartDelimiter/,
{
token: 'sigil.delimiter',
switchTo: '@sigilContinue.$S2.$S3.$S4.$S5'
@ -498,7 +499,7 @@ export const language = <languages.IMonarchLanguage>{
'sigilStart.noInterpol': [
[
/~([a-zA-Z])@sigilStartDelimiter/,
/~([a-z]|[A-Z]+)@sigilStartDelimiter/,
{
token: 'sigil.delimiter',
switchTo: '@sigilContinue.$S2.$S3.$S4.$S5'