Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Elixir tokenization of sigil modifiers #2806

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/basic-languages/elixir/elixir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ testTokenization('elixir', [
]
}
],
// Sigils (modifiers)
[
{
line: '~X/custom/az09',
tokens: [
{ startIndex: 0, type: 'sigil.delimiter.elixir' },
{ startIndex: 3, type: 'sigil.elixir' },
{ startIndex: 9, type: 'sigil.delimiter.elixir' }
]
}
],
// Module attributes
[
{
Expand Down
15 changes: 8 additions & 7 deletions src/basic-languages/elixir/elixir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const language = <languages.IMonarchLanguage>{
// Matches any of the operator names:
// <<< >>> ||| &&& ^^^ ~~~ === !== ~>> <~> |~> <|> == != <= >= && || \\ <> ++ -- |> =~ -> <- ~> <~ :: .. = < > + - * / | . ^ & !
operator:
/-[->]?|!={0,2}|\*|\/|\\\\|&{1,3}|\.\.?|\^(?:\^\^)?|\+\+?|<(?:-|<<|=|>|\|>|~>?)?|=~|={1,3}|>(?:=|>>)?|\|~>|\|>|\|{1,3}|~>>?|~~~|::/,
/-[->]?|!={0,2}|\*{1,2}|\/|\\\\|&{1,3}|\.\.?|\^(?:\^\^)?|\+\+?|<(?:-|<<|=|>|\|>|~>?)?|=~|={1,3}|>(?:=|>>)?|\|~>|\|>|\|{1,3}|~>>?|~~~|::/,

// See https://hexdocs.pm/elixir/syntax-reference.html#variables
variableName: /[a-z_][a-zA-Z0-9_]*[?!]?/,
Expand All @@ -125,6 +125,7 @@ export const language = <languages.IMonarchLanguage>{
sigilSymmetricDelimiter: /"""|'''|"|'|\/|\|/,
sigilStartDelimiter: /@sigilSymmetricDelimiter|<|\{|\[|\(/,
sigilEndDelimiter: /@sigilSymmetricDelimiter|>|\}|\]|\)/,
sigilModifiers: /[a-zA-Z0-9]*/,

decimal: /\d(?:_?\d)*/,
hex: /[0-9a-fA-F](_?[0-9a-fA-F])*/,
Expand Down Expand Up @@ -387,7 +388,7 @@ export const language = <languages.IMonarchLanguage>{

'sigilContinue.interpol.s': [
[
/(@sigilEndDelimiter)[a-zA-Z]*/,
/(@sigilEndDelimiter)@sigilModifiers/,
{
cases: {
'$1==$S5': { token: 'string.delimiter', next: '@pop' },
Expand All @@ -412,7 +413,7 @@ export const language = <languages.IMonarchLanguage>{
// Ignore escaped sigil end
[/(^|[^\\])\\@sigilEndDelimiter/, 'string'],
[
/(@sigilEndDelimiter)[a-zA-Z]*/,
/(@sigilEndDelimiter)@sigilModifiers/,
{
cases: {
'$1==$S5': { token: 'string.delimiter', next: '@pop' },
Expand All @@ -435,7 +436,7 @@ export const language = <languages.IMonarchLanguage>{

'sigilContinue.interpol.r': [
[
/(@sigilEndDelimiter)[a-zA-Z]*/,
/(@sigilEndDelimiter)@sigilModifiers/,
{
cases: {
'$1==$S5': { token: 'regexp.delimiter', next: '@pop' },
Expand All @@ -460,7 +461,7 @@ export const language = <languages.IMonarchLanguage>{
// Ignore escaped sigil end
[/(^|[^\\])\\@sigilEndDelimiter/, 'regexp'],
[
/(@sigilEndDelimiter)[a-zA-Z]*/,
/(@sigilEndDelimiter)@sigilModifiers/,
{
cases: {
'$1==$S5': { token: 'regexp.delimiter', next: '@pop' },
Expand All @@ -484,7 +485,7 @@ export const language = <languages.IMonarchLanguage>{

'sigilContinue.interpol': [
[
/(@sigilEndDelimiter)[a-zA-Z]*/,
/(@sigilEndDelimiter)@sigilModifiers/,
{
cases: {
'$1==$S5': { token: 'sigil.delimiter', next: '@pop' },
Expand All @@ -509,7 +510,7 @@ export const language = <languages.IMonarchLanguage>{
// Ignore escaped sigil end
[/(^|[^\\])\\@sigilEndDelimiter/, 'sigil'],
[
/(@sigilEndDelimiter)[a-zA-Z]*/,
/(@sigilEndDelimiter)@sigilModifiers/,
{
cases: {
'$1==$S5': { token: 'sigil.delimiter', next: '@pop' },
Expand Down