Skip to content

Commit

Permalink
Merge pull request #48 from elixir-lang/better-support-for-bitwise-op…
Browse files Browse the repository at this point in the history
…erations

Add better support for bitwise operations
  • Loading branch information
keathley committed Mar 3, 2016
2 parents 1725858 + 8712e9f commit 2b18bd2
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 33 deletions.
62 changes: 29 additions & 33 deletions grammars/elixir.cson
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,6 @@
'match': '\\b(__(CALLER|ENV|MODULE|DIR)__)\\b(?![?!])'
'name': 'variable.language.elixir'
}
{
'captures':
'1':
'name': 'punctuation.definition.variable.elixir'
'match': '(@)[a-zA-Z_]\\w*'
'name': 'variable.other.readwrite.module.elixir'
}
{
'captures':
'1':
'name': 'punctuation.definition.variable.elixir'
'match': '(&)\\d*'
'name': 'variable.other.anonymous.elixir'
}
{
'match': '\\b[A-Z]\\w*\\b'
'name': 'variable.other.constant.elixir'
Expand Down Expand Up @@ -446,14 +432,6 @@
'name': 'punctuation.definition.string.end.elixir'
'name': 'string.quoted.other.literal.upper.elixir'
}
{
'captures':
'1':
'name': 'punctuation.definition.constant.elixir'
'comment': 'symbols'
'match': '(?<!:)(:)(?>[a-zA-Z_][\\w@]*(?>[?!]|=(?![>=]))?|\\<\\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\\-|\\|>|=>|~|~=|=|/|\\\\\\\\|\\*\\*?|\\.\\.?\\.?|>=?|<=?|&&?&?|\\+\\+?|\\-\\-?|\\|\\|?\\|?|\\!|@|\\%?\\{\\}|%|\\[\\]|\\^(\\^\\^)?)'
'name': 'constant.other.symbol.elixir'
}
{
'captures':
'1':
Expand Down Expand Up @@ -515,22 +493,18 @@
]
}
{
'comment': 'matches: | ++ -- ** \\ <- <> << >> :: .. |> ~ => ->'
'match': '\\+\\+|\\-\\-|\\*\\*|\\\\\\\\|\\<\\-|\\<\\>|\\<\\<|\\>\\>|\\:\\:|\\.\\.|\\|>|~|=>|->|\\|'
'name': 'keyword.operator.other.elixir'
'match': '(\\|\\|\\||&&&|\\^\\^\\^|<<<|>>>|~~~)'
'name': 'keyword.operator.bitwise.elixir'
}
{
'match': '\\+=|\\-=|\\|\\|=|~=|&&='
'name': 'keyword.operator.assignment.augmented.elixir'
'comment': 'matches: | ++ -- ** \\ <- <> << >> :: .. |> => -> <|> <~> <~ <<~ ~> ~>>'
'match': '\\+\\+|\\-\\-|\\*\\*|\\\\\\\\|\\<\\-|<\\<\\~|\\<\\>|\\<\\<|\\>\\>|\\:\\:|\\.\\.|\\|>|=>|<\\|\\>|<~>|->|~>>|~>|<~'
'name': 'keyword.operator.other.elixir'
}
{
'match': '===?|!==?|<=?|>=?'
'match': '===?|!==?|<=?|>=?|=~'
'name': 'keyword.operator.comparison.elixir'
}
{
'match': '(\\|\\|\\||&&&|\\^\\^\\^|<<<|>>>|~~~)'
'name': 'keyword.operator.bitwise.elixir'
}
{
'match': '(?<=[ \\t])!+|\\bnot\\b|&&|\\band\\b|\\|\\||\\bor\\b|\\bxor\\b'
'name': 'keyword.operator.logical.elixir'
Expand Down Expand Up @@ -564,13 +538,35 @@
'name': 'punctuation.section.scope.elixir'
}
{
'match': '\\[|\\]'
'match': '\\[\\]|\\[|\\]'
'name': 'punctuation.section.array.elixir'
}
{
'match': '\\(|\\)'
'name': 'punctuation.section.function.elixir'
}
{
'captures':
'1':
'name': 'punctuation.definition.variable.elixir'
'match': '(@)[a-zA-Z_]\\w*'
'name': 'variable.other.readwrite.module.elixir'
}
{
'captures':
'1':
'name': 'punctuation.definition.variable.elixir'
'match': '(&)\\d*'
'name': 'variable.other.anonymous.elixir'
}
{
'captures':
'1':
'name': 'punctuation.definition.constant.elixir'
'comment': 'symbols'
'match': '(?<!:)(:)(?>[a-zA-Z_][\\w@]*(?>[?!]|=(?![>=]))?|\\<\\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\\-|\\|>|=>|~|~=|=|/|\\\\\\\\|\\*\\*?|\\.\\.?\\.?|>=?|<=?|&&?&?|\\+\\+?|\\-\\-?|\\|\\|?\\|?|\\!|@|\\%?\\{\\}|%|\\[\\]|\\^(\\^\\^)?)'
'name': 'constant.other.symbol.elixir'
}
]
'repository':
'escaped_char':
Expand Down
105 changes: 105 additions & 0 deletions spec/elixir-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,108 @@ describe "Elixir grammar", ->
it "parses the grammar", ->
expect(grammar).toBeTruthy()
expect(grammar.scopeName).toBe "source.elixir"

it "tokenizes bitwise operators", ->
{tokens} = grammar.tokenizeLine('left &&& right')
expect(tokens[1]).toEqual value: '&&&', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']

{tokens} = grammar.tokenizeLine('left >>> right')
expect(tokens[1]).toEqual value: '>>>', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']

{tokens} = grammar.tokenizeLine('left <<< right')
expect(tokens[1]).toEqual value: '<<<', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']

{tokens} = grammar.tokenizeLine('left ^^^ right')
expect(tokens[1]).toEqual value: '^^^', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']

{tokens} = grammar.tokenizeLine('left ||| right')
expect(tokens[1]).toEqual value: '|||', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']

{tokens} = grammar.tokenizeLine('~~~exp')
expect(tokens[0]).toEqual value: '~~~', scopes: ['source.elixir', 'keyword.operator.bitwise.elixir']

it "tokenizes comparison operators", ->
{tokens} = grammar.tokenizeLine('left === right')
expect(tokens[1]).toEqual value: '===', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']

{tokens} = grammar.tokenizeLine('left == right')
expect(tokens[1]).toEqual value: '==', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']

{tokens} = grammar.tokenizeLine('left != right')
expect(tokens[1]).toEqual value: '!=', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']

{tokens} = grammar.tokenizeLine('left !== right')
expect(tokens[1]).toEqual value: '!==', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']

{tokens} = grammar.tokenizeLine('left <= right')
expect(tokens[1]).toEqual value: '<=', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']

{tokens} = grammar.tokenizeLine('left >= right')
expect(tokens[1]).toEqual value: '>=', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']

{tokens} = grammar.tokenizeLine('left =~ right')
expect(tokens[1]).toEqual value: '=~', scopes: ['source.elixir', 'keyword.operator.comparison.elixir']

it "tokenizes logical operators", ->
{tokens} = grammar.tokenizeLine('left || right')
expect(tokens[1]).toEqual value: '||', scopes: ['source.elixir', 'keyword.operator.logical.elixir']

{tokens} = grammar.tokenizeLine('left && right')
expect(tokens[1]).toEqual value: '&&', scopes: ['source.elixir', 'keyword.operator.logical.elixir']

it "tokenizes other operators", ->
{tokens} = grammar.tokenizeLine('left |> right')
expect(tokens[1]).toEqual value: '|>', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left ++ right')
expect(tokens[1]).toEqual value: '++', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left -- right')
expect(tokens[1]).toEqual value: '--', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left \\\\ right')
expect(tokens[1]).toEqual value: '\\\\', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left <- right')
expect(tokens[1]).toEqual value: '<-', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left <> right')
expect(tokens[1]).toEqual value: '<>', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left :: right')
expect(tokens[1]).toEqual value: '::', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left .. right')
expect(tokens[1]).toEqual value: '..', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left => right')
expect(tokens[1]).toEqual value: '=>', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left -> right')
expect(tokens[1]).toEqual value: '->', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left <<~ right')
expect(tokens[1]).toEqual value: '<<~', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left <~ right')
expect(tokens[1]).toEqual value: '<~', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left ~>> right')
expect(tokens[1]).toEqual value: '~>>', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left ~> right')
expect(tokens[1]).toEqual value: '~>', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left <~> right')
expect(tokens[1]).toEqual value: '<~>', scopes: ['source.elixir', 'keyword.operator.other.elixir']

{tokens} = grammar.tokenizeLine('left <|> right')
expect(tokens[1]).toEqual value: '<|>', scopes: ['source.elixir', 'keyword.operator.other.elixir']

it "tokenizes arrays", ->
{tokens} = grammar.tokenizeLine('[]')
expect(tokens[0]).toEqual value: '[]', scopes: ['source.elixir', 'punctuation.section.array.elixir']

{tokens} = grammar.tokenizeLine('[1,2,3]')
expect(tokens[0]).toEqual value: '[', scopes: ['source.elixir', 'punctuation.section.array.elixir']
expect(tokens[6]).toEqual value: ']', scopes: ['source.elixir', 'punctuation.section.array.elixir']

0 comments on commit 2b18bd2

Please sign in to comment.