1
+ Prism . languages . elixir = {
2
+ // Negative look-ahead is needed for string interpolation
3
+ 'comment' : / # (? ! \{ ) .* / ,
4
+ // ~r"""foo""", ~r'''foo''', ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
5
+ 'regex' : / ~ [ r R ] (?: ( " " " | ' ' ' | [ \/ | " ' ] ) (?: \\ .| (? ! \1) [ ^ \\ ] ) + \1| \( (?: \\ \) | [ ^ ) ] ) + \) | \[ (?: \\ \] | [ ^ \] ] ) + \] | \{ (?: \\ \} | [ ^ } ] ) + \} | < (?: \\ > | [ ^ > ] ) + > ) [ u i s m x f r ] * / ,
6
+ 'string' : [
7
+ {
8
+ // ~s"""foo""", ~s'''foo''', ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo}, ~s<foo>
9
+ pattern : / ~ [ c C s S w W ] (?: ( " " " | ' ' ' | [ \/ | " ' ] ) (?: \\ .| (? ! \1) [ ^ \\ ] ) + \1| \( (?: \\ \) | [ ^ ) ] ) + \) | \[ (?: \\ \] | [ ^ \] ] ) + \] | \{ (?: \\ \} | # \{ [ ^ } ] + \} | [ ^ } ] ) + \} | < (?: \\ > | [ ^ > ] ) + > ) [ c s a ] ? / ,
10
+ inside : {
11
+ // See interpolation below
12
+ }
13
+ } ,
14
+ {
15
+ pattern : / ( " " " | ' ' ' ) [ \s \S ] * ?\1/ ,
16
+ inside : {
17
+ // See interpolation below
18
+ }
19
+ } ,
20
+ {
21
+ // Multi-line strings are allowed
22
+ pattern : / ( " | ' ) (?: \\ [ \s \S ] | (? ! \1) [ ^ \\ ] ) * \1/ ,
23
+ inside : {
24
+ // See interpolation below
25
+ }
26
+ }
27
+ ] ,
28
+ 'atom' : {
29
+ // Look-behind prevents bad highlighting of the :: operator
30
+ pattern : / ( ^ | [ ^ : ] ) : \w + / ,
31
+ lookbehind : true ,
32
+ alias : 'symbol'
33
+ } ,
34
+ // Look-ahead prevents bad highlighting of the :: operator
35
+ 'attr-name' : / \w + : (? ! : ) / ,
36
+ 'capture' : {
37
+ // Look-behind prevents bad highlighting of the && operator
38
+ pattern : / ( ^ | [ ^ & ] ) & (?: [ ^ & \s \d ( ) ] [ ^ \s ( ) ] * | (? = \( ) ) / ,
39
+ lookbehind : true ,
40
+ alias : 'function'
41
+ } ,
42
+ 'argument' : {
43
+ // Look-behind prevents bad highlighting of the && operator
44
+ pattern : / ( ^ | [ ^ & ] ) & \d + / ,
45
+ lookbehind : true ,
46
+ alias : 'variable'
47
+ } ,
48
+ 'attribute' : {
49
+ pattern : / @ [ \S ] + / ,
50
+ alias : 'variable'
51
+ } ,
52
+ 'number' : / \b (?: 0 [ b o x ] [ a - f \d _ ] + | \d [ \d _ ] * ) (?: \. [ \d _ ] + ) ? (?: e [ + - ] ? [ \d _ ] + ) ? \b / i,
53
+ 'keyword' : / \b (?: a f t e r | a l i a s | a n d | c a s e | c a t c h | c o n d | d e f (?: c a l l b a c k | e x c e p t i o n | i m p l | m o d u l e | p | p r o t o c o l | s t r u c t ) ? | d o | e l s e | e n d | f n | f o r | i f | i m p o r t | n o t | o r | r e q u i r e | r e s c u e | t r y | u n l e s s | u s e | w h e n ) \b / ,
54
+ 'boolean' : / \b (?: t r u e | f a l s e | n i l ) \b / ,
55
+ 'operator' : [
56
+ / \b i n \b | & & ? | \| [ | > ] ? | \\ \\ | : : | \. \. \. ? | \+ \+ ? | - [ - > ] ? | < [ - = > ] | > = | ! = = ? | \B ! | = (?: = = ? | [ > ~ ] ) ? | [ * \/ ^ ] / ,
57
+ {
58
+ // We don't want to match <<
59
+ pattern : / ( [ ^ < ] ) < (? ! < ) / ,
60
+ lookbehind : true
61
+ } ,
62
+ {
63
+ // We don't want to match >>
64
+ pattern : / ( [ ^ > ] ) > (? ! > ) / ,
65
+ lookbehind : true
66
+ }
67
+ ] ,
68
+ 'punctuation' : / < < | > > | [ . , % \[ \] { } ( ) ] /
69
+ } ;
70
+
71
+ Prism . languages . elixir . string . forEach ( function ( o ) {
72
+ o . inside = {
73
+ 'interpolation' : {
74
+ pattern : / # \{ [ ^ } ] + \} / ,
75
+ inside : {
76
+ 'delimiter' : {
77
+ pattern : / ^ # \{ | \} $ / ,
78
+ alias : 'punctuation'
79
+ } ,
80
+ rest : Prism . util . clone ( Prism . languages . elixir )
81
+ }
82
+ }
83
+ } ;
84
+ } ) ;
0 commit comments