Skip to content

Commit

Permalink
Merge pull request #2806 from jonatanklosko/jk-elixir-sigils
Browse files Browse the repository at this point in the history
Update Elixir tokenization of sigil modifiers
  • Loading branch information
hediet authored Dec 8, 2021
2 parents 0afd248 + 1126efe commit 86cff74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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

0 comments on commit 86cff74

Please sign in to comment.