Skip to content

Commit c782be8

Browse files
azizkprincemaple
authored andcommitted
Elixir: fixed capture expressions
* `& 1` -> don't match as a capture argument number * `& &1.func/1` -> can be a captured remote function * `&some.thing.good/1` -> several chained members * `&@module.func/1` -> captured remote function
1 parent d2cb363 commit c782be8

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

syntaxes/Elixir.sublime-syntax

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,21 +2432,31 @@ contexts:
24322432
## Captures
24332433

24342434
capture:
2435-
- match: (&)\s*(\d+)(?!\.(?![.\D]))
2435+
- include: capture_arg_number
2436+
- include: capture_remote_func
2437+
2438+
capture_arg_number:
2439+
- match: (&)(\d+)(?!\.(?![.\D]))
24362440
captures:
24372441
1: punctuation.definition.capture.elixir constant.other.capture.elixir
24382442
2: constant.other.capture.elixir
2443+
2444+
capture_remote_func:
24392445
- match: \&
24402446
scope: keyword.operator.capture.elixir
24412447
push:
24422448
- match: (?=(?>do|fn|true|false|nil){{no_id_key_suffix}})
24432449
pop: 1
24442450
- include: if_closing_token_pop
24452451
- match: (?=\.(?!\.))
2446-
set:
2452+
push:
24472453
- include: dot_operator
24482454
- include: capture_name_pop
24492455
- include: member_or_call_pop
2456+
- match: (?=&\d+\s*\.(?!\.))
2457+
push:
2458+
- include: capture_arg_number
2459+
- include: if_empty_pop
24502460
- include: capture_name_pop
24512461
- include: special_form
24522462
- match: (?={{identifier}}\s*\.(?!\.|\s*\())
@@ -2468,6 +2478,9 @@ contexts:
24682478
)
24692479
comment: exit if module/atom is not followed by `.` or `.(`
24702480
pop: 1
2481+
- match: '@(?!/)'
2482+
scope: keyword.operator.attribute.elixir
2483+
push: module_attribute_pop
24712484
- include: atom_symbol
24722485
- include: atom_keyword
24732486
- include: module_name

tests/syntax_test_misc.ex

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,12 @@ end[]
595595
#^^^ constant.other.capture
596596

597597
& 1/&1
598-
# ^ -punctuation.definition.capture constant.other.capture
599-
# ^ punctuation.definition.capture constant.other.capture
598+
# ^^ constant.other.capture
599+
# ^ punctuation.definition.capture
600600
# ^ keyword.operator.arithmetic
601-
# ^ -punctuation.definition.capture constant.other.capture
602-
# ^ -punctuation.definition.capture -constant.other.capture
603-
#^ punctuation.definition.capture constant.other.capture
601+
# ^ constant.numeric.integer
602+
# ^^^ -punctuation.definition.capture -constant.other.capture
603+
#^ keyword.operator.capture
604604

605605
& &1..&2; & &1 .. &2
606606
# ^^ constant.other.capture
@@ -622,8 +622,8 @@ end[]
622622
# ^^^^^ constant.other.module
623623
&:"\"Quoted\"\.Module\\".t()
624624
# ^ variable.function
625+
# ^ punctuation.accessor.dot
625626
# ^^^^^^^^^^^^^^^^^^^^ constant.other.module
626-
# FIXME: ^ punctuation.accessor.dot
627627
&:erlang.apply/2
628628
# ^ punctuation.accessor.arity
629629
# ^^^^^ variable.other.capture
@@ -651,6 +651,39 @@ end[]
651651
# ^^^^ variable.other.member
652652
# ^ punctuation.accessor.dot
653653
# ^^ constant.other.capture
654+
& &1.func/2
655+
# ^ constant.numeric.arity
656+
# ^ punctuation.accessor.arity
657+
# ^^^^ variable.other.capture
658+
# ^ punctuation.accessor.dot
659+
# ^^ constant.other.capture
660+
# ^ punctuation.definition.capture
661+
& &1.prop.func/1
662+
# ^ constant.numeric.arity
663+
# ^ punctuation.accessor.arity
664+
# ^^^^ variable.other.capture
665+
# ^ punctuation.accessor.dot
666+
# ^^^^ variable.other.member
667+
# ^ punctuation.accessor.dot
668+
# ^^ constant.other.capture
669+
# ^ punctuation.definition.capture
670+
671+
&some.thing/1
672+
# ^ constant.numeric.arity
673+
# ^ punctuation.accessor.arity
674+
# ^^^^^ variable.other.capture
675+
# ^ punctuation.accessor.dot
676+
# ^^^^ variable.other
677+
#^ keyword.operator.capture
678+
&some.thing.good/1
679+
# ^ constant.numeric.arity
680+
# ^ punctuation.accessor.arity
681+
# ^^^^ variable.other.capture
682+
# ^ punctuation.accessor.dot
683+
# ^^^^^ variable.other.member
684+
# ^ punctuation.accessor.dot
685+
# ^^^^ variable.other
686+
#^ keyword.operator.capture
654687

655688
&<%= num %>
656689
# ^ keyword.operator.comparison
@@ -672,8 +705,8 @@ end[]
672705
# ^^^ keyword.operator.logical
673706
# ^^ constant.other.capture
674707
# ^^ keyword.operator.comparison
675-
# ^ constant.other.capture -constant.numeric
676-
#^ constant.other.capture
708+
# ^ constant.numeric.integer
709+
#^ keyword.operator.capture
677710

678711
&mod.&/1; &Mod.&/1
679712
# ^ variable.other.capture
@@ -683,6 +716,15 @@ end[]
683716
# ^ punctuation.accessor.dot
684717
# ^^^ variable.other
685718

719+
&@module.func/1
720+
# ^ constant.numeric.arity
721+
# ^ punctuation.accessor.arity
722+
# ^^^^ variable.other.capture
723+
# ^ punctuation.accessor.dot
724+
# ^^^^^^ variable.other.constant
725+
# ^ keyword.operator.attribute
726+
#^ keyword.operator.capture.elixir
727+
686728
&x."a func"
687729
# ^^^^^^^^ meta.member
688730
# ^ punctuation.accessor.dot

0 commit comments

Comments
 (0)