Skip to content
17 changes: 9 additions & 8 deletions Elixir.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ name: Elixir
file_extensions:
- ex
- exs
first_line_match: ^#!/.*\belixir
first_line_match: ^#!/.*\b(?:elixirc?|iex)
scope: source.elixir

variables:
module_name: '\b[A-Z]\w*\b'
module_name: '\b[A-Z][a-zA-Z0-9_]*\b'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\w is exactly that

iex(3)> "0" =~ ~r/\w/
true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite, because it also matches Unicode characters like "á". The compiler rejects those and only allows ASCII characters in module names. "\w" is a nice shorthand but it does more than ASCII letters.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

id_begin: '[[:alpha:]_]'

contexts:
main:
Expand Down Expand Up @@ -59,7 +60,7 @@ contexts:
- match: ',|\)|$'
pop: true
- include: main
- match: \b(is_atom|is_binary|is_bitstring|is_boolean|is_float|is_function|is_integer|is_list|is_map|is_nil|is_number|is_pid|is_port|is_record|is_reference|is_tuple|is_exception|abs|bit_size|byte_size|div|elem|hd|length|map_size|node|rem|round|tl|trunc|tuple_size)\b
- match: \b(is_(?:atom|binary|bitstring|boolean|float|function|integer|list|map|nil|number|pid|port|record|reference|tuple|exception)|abs|bit_size|byte_size|div|elem|hd|length|map_size|node|rem|round|tl|trunc|tuple_size)\b
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

scope: keyword.guard.elixir

numeric:
Expand Down Expand Up @@ -335,13 +336,13 @@ contexts:
pop: true
- match: '{{module_name}}'
scope: entity.name.protocol.elixir
- match: '^\s*(def|defmacro)\s+([a-zA-Z_]\w*(?:!|\?)?)(?:(\()|\s*)'
- match: '^\s*(def|defmacro)\s+({{id_begin}}\w*(?:!|\?)?)(?:(\()|\s*)'
captures:
1: keyword.control.module.elixir
2: entity.name.function.public.elixir
3: punctuation.definition.parameters.elixir
push: function_body
- match: '^\s*(defp|defmacrop)\s+([a-zA-Z_]\w*(?:!|\?)?)(?:(\()|\s*)'
- match: '^\s*(defp|defmacrop)\s+({{id_begin}}\w*(?:!|\?)?)(?:(\()|\s*)'
captures:
1: keyword.control.module.elixir
2: entity.name.function.private.elixir
Expand Down Expand Up @@ -440,7 +441,7 @@ contexts:
- match: (?<!\.)\b(and|not|or|when|xor|in)\b
comment: as above, just doesn't need a 'end' and does a logic operation
scope: keyword.operator.elixir
- match: '{{module_name}}'
- match: '{{module_name}}(?!:)'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when would you do that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have a map or list containing keys starting with a capital letter: [A: 0, B: 1]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems rare, but OK :)

scope: entity.name.class.elixir
- match: '\b(nil|true|false)\b(?![?!])'
scope: constant.language.elixir
Expand Down Expand Up @@ -480,12 +481,12 @@ contexts:
pop: true
- include: interpolated_elixir
- include: escaped_char
- match: '(?<!:)(:)(?>[a-zA-Z_][\w@]*(?>[?!]|=(?![>=]))?|\<\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\-|\|>|=>|=~|=|/|\\\\|\*\*?|\.\.?\.?|>=?|<=?|&&?&?|\+\+?|\-\-?|\|\|?\|?|\!|@|\%?\{\}|%|\[\]|\^(\^\^)?)'
- match: '(?<!:)(:)(?>{{id_begin}}[\w@]*(?>[?!]|=(?![>=]))?|\<\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\-|\|>|=>|=~|=|/|\\\\|\*\*?|\.\.?\.?|>=?|<=?|&&?&?|\+\+?|\-\-?|\|\|?\|?|\!|@|\%?\{\}|%|\[\]|\^(\^\^)?)'
comment: symbols
scope: constant.other.symbol.elixir
captures:
1: punctuation.definition.constant.elixir
- match: '(?>[a-zA-Z_][\w@]*(?>[?!])?)(:)(?!:)'
- match: '(?>{{id_begin}}[\w@]*(?>[?!])?)(:)(?!:)'
comment: symbols
scope: constant.other.keywords.elixir
captures:
Expand Down