Skip to content

Commit 2b18bd2

Browse files
committed
Merge pull request #48 from elixir-lang/better-support-for-bitwise-operations
Add better support for bitwise operations
2 parents 1725858 + 8712e9f commit 2b18bd2

File tree

2 files changed

+134
-33
lines changed

2 files changed

+134
-33
lines changed

grammars/elixir.cson

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,6 @@
8585
'match': '\\b(__(CALLER|ENV|MODULE|DIR)__)\\b(?![?!])'
8686
'name': 'variable.language.elixir'
8787
}
88-
{
89-
'captures':
90-
'1':
91-
'name': 'punctuation.definition.variable.elixir'
92-
'match': '(@)[a-zA-Z_]\\w*'
93-
'name': 'variable.other.readwrite.module.elixir'
94-
}
95-
{
96-
'captures':
97-
'1':
98-
'name': 'punctuation.definition.variable.elixir'
99-
'match': '(&)\\d*'
100-
'name': 'variable.other.anonymous.elixir'
101-
}
10288
{
10389
'match': '\\b[A-Z]\\w*\\b'
10490
'name': 'variable.other.constant.elixir'
@@ -446,14 +432,6 @@
446432
'name': 'punctuation.definition.string.end.elixir'
447433
'name': 'string.quoted.other.literal.upper.elixir'
448434
}
449-
{
450-
'captures':
451-
'1':
452-
'name': 'punctuation.definition.constant.elixir'
453-
'comment': 'symbols'
454-
'match': '(?<!:)(:)(?>[a-zA-Z_][\\w@]*(?>[?!]|=(?![>=]))?|\\<\\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\\-|\\|>|=>|~|~=|=|/|\\\\\\\\|\\*\\*?|\\.\\.?\\.?|>=?|<=?|&&?&?|\\+\\+?|\\-\\-?|\\|\\|?\\|?|\\!|@|\\%?\\{\\}|%|\\[\\]|\\^(\\^\\^)?)'
455-
'name': 'constant.other.symbol.elixir'
456-
}
457435
{
458436
'captures':
459437
'1':
@@ -515,22 +493,18 @@
515493
]
516494
}
517495
{
518-
'comment': 'matches: | ++ -- ** \\ <- <> << >> :: .. |> ~ => ->'
519-
'match': '\\+\\+|\\-\\-|\\*\\*|\\\\\\\\|\\<\\-|\\<\\>|\\<\\<|\\>\\>|\\:\\:|\\.\\.|\\|>|~|=>|->|\\|'
520-
'name': 'keyword.operator.other.elixir'
496+
'match': '(\\|\\|\\||&&&|\\^\\^\\^|<<<|>>>|~~~)'
497+
'name': 'keyword.operator.bitwise.elixir'
521498
}
522499
{
523-
'match': '\\+=|\\-=|\\|\\|=|~=|&&='
524-
'name': 'keyword.operator.assignment.augmented.elixir'
500+
'comment': 'matches: | ++ -- ** \\ <- <> << >> :: .. |> => -> <|> <~> <~ <<~ ~> ~>>'
501+
'match': '\\+\\+|\\-\\-|\\*\\*|\\\\\\\\|\\<\\-|<\\<\\~|\\<\\>|\\<\\<|\\>\\>|\\:\\:|\\.\\.|\\|>|=>|<\\|\\>|<~>|->|~>>|~>|<~'
502+
'name': 'keyword.operator.other.elixir'
525503
}
526504
{
527-
'match': '===?|!==?|<=?|>=?'
505+
'match': '===?|!==?|<=?|>=?|=~'
528506
'name': 'keyword.operator.comparison.elixir'
529507
}
530-
{
531-
'match': '(\\|\\|\\||&&&|\\^\\^\\^|<<<|>>>|~~~)'
532-
'name': 'keyword.operator.bitwise.elixir'
533-
}
534508
{
535509
'match': '(?<=[ \\t])!+|\\bnot\\b|&&|\\band\\b|\\|\\||\\bor\\b|\\bxor\\b'
536510
'name': 'keyword.operator.logical.elixir'
@@ -564,13 +538,35 @@
564538
'name': 'punctuation.section.scope.elixir'
565539
}
566540
{
567-
'match': '\\[|\\]'
541+
'match': '\\[\\]|\\[|\\]'
568542
'name': 'punctuation.section.array.elixir'
569543
}
570544
{
571545
'match': '\\(|\\)'
572546
'name': 'punctuation.section.function.elixir'
573547
}
548+
{
549+
'captures':
550+
'1':
551+
'name': 'punctuation.definition.variable.elixir'
552+
'match': '(@)[a-zA-Z_]\\w*'
553+
'name': 'variable.other.readwrite.module.elixir'
554+
}
555+
{
556+
'captures':
557+
'1':
558+
'name': 'punctuation.definition.variable.elixir'
559+
'match': '(&)\\d*'
560+
'name': 'variable.other.anonymous.elixir'
561+
}
562+
{
563+
'captures':
564+
'1':
565+
'name': 'punctuation.definition.constant.elixir'
566+
'comment': 'symbols'
567+
'match': '(?<!:)(:)(?>[a-zA-Z_][\\w@]*(?>[?!]|=(?![>=]))?|\\<\\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\\-|\\|>|=>|~|~=|=|/|\\\\\\\\|\\*\\*?|\\.\\.?\\.?|>=?|<=?|&&?&?|\\+\\+?|\\-\\-?|\\|\\|?\\|?|\\!|@|\\%?\\{\\}|%|\\[\\]|\\^(\\^\\^)?)'
568+
'name': 'constant.other.symbol.elixir'
569+
}
574570
]
575571
'repository':
576572
'escaped_char':

spec/elixir-spec.coffee

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,108 @@ describe "Elixir grammar", ->
1111
it "parses the grammar", ->
1212
expect(grammar).toBeTruthy()
1313
expect(grammar.scopeName).toBe "source.elixir"
14+
15+
it "tokenizes bitwise operators", ->
16+
{tokens} = grammar.tokenizeLine('left &&& right')
17+
expect(tokens[1]).toEqual value: '&&&', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']
18+
19+
{tokens} = grammar.tokenizeLine('left >>> right')
20+
expect(tokens[1]).toEqual value: '>>>', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']
21+
22+
{tokens} = grammar.tokenizeLine('left <<< right')
23+
expect(tokens[1]).toEqual value: '<<<', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']
24+
25+
{tokens} = grammar.tokenizeLine('left ^^^ right')
26+
expect(tokens[1]).toEqual value: '^^^', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']
27+
28+
{tokens} = grammar.tokenizeLine('left ||| right')
29+
expect(tokens[1]).toEqual value: '|||', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']
30+
31+
{tokens} = grammar.tokenizeLine('~~~exp')
32+
expect(tokens[0]).toEqual value: '~~~', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']
33+
34+
it "tokenizes comparison operators", ->
35+
{tokens} = grammar.tokenizeLine('left === right')
36+
expect(tokens[1]).toEqual value: '===', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']
37+
38+
{tokens} = grammar.tokenizeLine('left == right')
39+
expect(tokens[1]).toEqual value: '==', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']
40+
41+
{tokens} = grammar.tokenizeLine('left != right')
42+
expect(tokens[1]).toEqual value: '!=', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']
43+
44+
{tokens} = grammar.tokenizeLine('left !== right')
45+
expect(tokens[1]).toEqual value: '!==', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']
46+
47+
{tokens} = grammar.tokenizeLine('left <= right')
48+
expect(tokens[1]).toEqual value: '<=', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']
49+
50+
{tokens} = grammar.tokenizeLine('left >= right')
51+
expect(tokens[1]).toEqual value: '>=', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']
52+
53+
{tokens} = grammar.tokenizeLine('left =~ right')
54+
expect(tokens[1]).toEqual value: '=~', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']
55+
56+
it "tokenizes logical operators", ->
57+
{tokens} = grammar.tokenizeLine('left || right')
58+
expect(tokens[1]).toEqual value: '||', scopes: ['source.elixir', 'keyword.operator.logical.elixir']
59+
60+
{tokens} = grammar.tokenizeLine('left && right')
61+
expect(tokens[1]).toEqual value: '&&', scopes: ['source.elixir', 'keyword.operator.logical.elixir']
62+
63+
it "tokenizes other operators", ->
64+
{tokens} = grammar.tokenizeLine('left |> right')
65+
expect(tokens[1]).toEqual value: '|>', scopes: ['source.elixir', 'keyword.operator.other.elixir']
66+
67+
{tokens} = grammar.tokenizeLine('left ++ right')
68+
expect(tokens[1]).toEqual value: '++', scopes: ['source.elixir', 'keyword.operator.other.elixir']
69+
70+
{tokens} = grammar.tokenizeLine('left -- right')
71+
expect(tokens[1]).toEqual value: '--', scopes: ['source.elixir', 'keyword.operator.other.elixir']
72+
73+
{tokens} = grammar.tokenizeLine('left \\\\ right')
74+
expect(tokens[1]).toEqual value: '\\\\', scopes: ['source.elixir', 'keyword.operator.other.elixir']
75+
76+
{tokens} = grammar.tokenizeLine('left <- right')
77+
expect(tokens[1]).toEqual value: '<-', scopes: ['source.elixir', 'keyword.operator.other.elixir']
78+
79+
{tokens} = grammar.tokenizeLine('left <> right')
80+
expect(tokens[1]).toEqual value: '<>', scopes: ['source.elixir', 'keyword.operator.other.elixir']
81+
82+
{tokens} = grammar.tokenizeLine('left :: right')
83+
expect(tokens[1]).toEqual value: '::', scopes: ['source.elixir', 'keyword.operator.other.elixir']
84+
85+
{tokens} = grammar.tokenizeLine('left .. right')
86+
expect(tokens[1]).toEqual value: '..', scopes: ['source.elixir', 'keyword.operator.other.elixir']
87+
88+
{tokens} = grammar.tokenizeLine('left => right')
89+
expect(tokens[1]).toEqual value: '=>', scopes: ['source.elixir', 'keyword.operator.other.elixir']
90+
91+
{tokens} = grammar.tokenizeLine('left -> right')
92+
expect(tokens[1]).toEqual value: '->', scopes: ['source.elixir', 'keyword.operator.other.elixir']
93+
94+
{tokens} = grammar.tokenizeLine('left <<~ right')
95+
expect(tokens[1]).toEqual value: '<<~', scopes: ['source.elixir', 'keyword.operator.other.elixir']
96+
97+
{tokens} = grammar.tokenizeLine('left <~ right')
98+
expect(tokens[1]).toEqual value: '<~', scopes: ['source.elixir', 'keyword.operator.other.elixir']
99+
100+
{tokens} = grammar.tokenizeLine('left ~>> right')
101+
expect(tokens[1]).toEqual value: '~>>', scopes: ['source.elixir', 'keyword.operator.other.elixir']
102+
103+
{tokens} = grammar.tokenizeLine('left ~> right')
104+
expect(tokens[1]).toEqual value: '~>', scopes: ['source.elixir', 'keyword.operator.other.elixir']
105+
106+
{tokens} = grammar.tokenizeLine('left <~> right')
107+
expect(tokens[1]).toEqual value: '<~>', scopes: ['source.elixir', 'keyword.operator.other.elixir']
108+
109+
{tokens} = grammar.tokenizeLine('left <|> right')
110+
expect(tokens[1]).toEqual value: '<|>', scopes: ['source.elixir', 'keyword.operator.other.elixir']
111+
112+
it "tokenizes arrays", ->
113+
{tokens} = grammar.tokenizeLine('[]')
114+
expect(tokens[0]).toEqual value: '[]', scopes: ['source.elixir', 'punctuation.section.array.elixir']
115+
116+
{tokens} = grammar.tokenizeLine('[1,2,3]')
117+
expect(tokens[0]).toEqual value: '[', scopes: ['source.elixir', 'punctuation.section.array.elixir']
118+
expect(tokens[6]).toEqual value: ']', scopes: ['source.elixir', 'punctuation.section.array.elixir']

0 commit comments

Comments
 (0)