Skip to content

Commit c7c02df

Browse files
committed
Elixir: improve matching atom keywords using the branch feature
1 parent ef94093 commit c7c02df

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

syntaxes/Elixir.sublime-syntax

+32-12
Original file line numberDiff line numberDiff line change
@@ -2398,18 +2398,38 @@ contexts:
23982398
scope: constant.other.keyword.elixir
23992399
captures:
24002400
1: punctuation.definition.constant.end.elixir
2401-
# Look for ':' behind the closing double/single quote.
2402-
- match: (?x)(?=(["']) (?>\\. | (?!\1).)* \1:{{no_colon_suffix}})
2403-
comment: keyword string
2404-
push:
2405-
- match: (.)
2406-
scope: punctuation.definition.constant.begin.elixir
2407-
set:
2408-
- meta_scope: meta.string.elixir constant.other.keyword.elixir
2409-
- include: escaped_or_interpolated
2410-
- match: '\1:'
2411-
scope: punctuation.definition.constant.end.elixir
2412-
pop: 1
2401+
# FIXME: this doesn't quite work. It shouldn't be necessary to have two branches...
2402+
- match: (?=(["'])(?!\1\1))
2403+
branch_point: string_atom_keyword_branch
2404+
branch: [string_atom_keyword_pop, fail_string_atom_keyword_branch]
2405+
2406+
fail_string_atom_keyword_branch:
2407+
# - include: string
2408+
# - include: if_empty_pop
2409+
- match: ''
2410+
fail: string_atom_keyword_branch
2411+
2412+
string_atom_keyword_pop:
2413+
- match: \"
2414+
scope: punctuation.definition.constant.begin.elixir
2415+
set:
2416+
- meta_scope: meta.string.elixir constant.other.keyword.elixir
2417+
- include: escaped_or_interpolated
2418+
- match: \":{{no_colon_suffix}}
2419+
scope: punctuation.definition.constant.end.elixir
2420+
pop: 1
2421+
- match: \"
2422+
fail: string_atom_keyword_branch
2423+
- match: \'
2424+
scope: punctuation.definition.constant.begin.elixir
2425+
set:
2426+
- meta_scope: meta.string.elixir constant.other.keyword.elixir
2427+
- include: escaped_or_interpolated
2428+
- match: \':{{no_colon_suffix}}
2429+
scope: punctuation.definition.constant.end.elixir
2430+
pop: 1
2431+
- match: \'
2432+
fail: string_atom_keyword_branch
24132433

24142434
atom_symbol:
24152435
- match: :(?!:(?!:))

tests/syntax_test_atoms.ex

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
# ^^^^ constant.other.symbol
2121
#^ keyword.operator.pin
2222

23-
# NB: this can only fixed by using ST4's branch look-ahead feature.
2423
["abc #{"def"} ghi": :"abc #{"def"} ghi"]
24+
# ^^^^^ constant.other.symbol
2525
# ^^^^^^^^ meta.interpolation.elixir
26+
# ^^^^^^ constant.other.symbol
27+
# ^ -constant.other
28+
# ^^^^^^ constant.other.keyword
2629
# ^^^^^^^^ meta.interpolation.elixir
27-
#^^^^^
30+
#^^^^^ constant.other.keyword
2831

2932
[a@?: :a@?]
3033
# ^^^^ constant.other.symbol

0 commit comments

Comments
 (0)