Skip to content

Commit 13baaeb

Browse files
committed
Elixir: improve matching atom keywords using the branch feature
1 parent e3b9a4e commit 13baaeb

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
@@ -2299,18 +2299,38 @@ contexts:
22992299
scope: constant.other.keyword.elixir
23002300
captures:
23012301
1: punctuation.definition.constant.end.elixir
2302-
# Look for ':' behind the closing double/single quote.
2303-
- match: (?x)(?=(["']) (?>\\. | (?!\1).)* \1:{{no_colon_suffix}})
2304-
comment: keyword string
2305-
push:
2306-
- match: (.)
2307-
scope: punctuation.definition.constant.begin.elixir
2308-
set:
2309-
- meta_scope: meta.string.elixir constant.other.keyword.elixir
2310-
- include: escaped_or_interpolated
2311-
- match: '\1:'
2312-
scope: punctuation.definition.constant.end.elixir
2313-
pop: 1
2302+
# FIXME: this doesn't quite work. It shouldn't be necessary to have two branches...
2303+
- match: (?=(["'])(?!\1\1))
2304+
branch_point: string_atom_keyword_branch
2305+
branch: [string_atom_keyword_pop, fail_string_atom_keyword_branch]
2306+
2307+
fail_string_atom_keyword_branch:
2308+
# - include: string
2309+
# - include: if_empty_pop
2310+
- match: ''
2311+
fail: string_atom_keyword_branch
2312+
2313+
string_atom_keyword_pop:
2314+
- match: \"
2315+
scope: punctuation.definition.constant.begin.elixir
2316+
set:
2317+
- meta_scope: meta.string.elixir constant.other.keyword.elixir
2318+
- include: escaped_or_interpolated
2319+
- match: \":{{no_colon_suffix}}
2320+
scope: punctuation.definition.constant.end.elixir
2321+
pop: 1
2322+
- match: \"
2323+
fail: string_atom_keyword_branch
2324+
- match: \'
2325+
scope: punctuation.definition.constant.begin.elixir
2326+
set:
2327+
- meta_scope: meta.string.elixir constant.other.keyword.elixir
2328+
- include: escaped_or_interpolated
2329+
- match: \':{{no_colon_suffix}}
2330+
scope: punctuation.definition.constant.end.elixir
2331+
pop: 1
2332+
- match: \'
2333+
fail: string_atom_keyword_branch
23142334

23152335
atom_symbol:
23162336
- 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)