Skip to content

Commit 8ca41c1

Browse files
authored
Merge pull request elixir-editors#406 from seddy/defguard_syntax
Add defguard(p) syntax highlighting
2 parents b1b247e + fdec386 commit 8ca41c1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

spec/syntax/guard_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
require 'spec_helper'
44

5+
describe 'defguard syntax' do
6+
it 'defines `defguard` keyword as elixirGuard' do
7+
expect(<<~EOF).to include_elixir_syntax('elixirGuard', 'defguard')
8+
defguard some_guard(x) when is_integer(x)
9+
EOF
10+
end
11+
12+
it 'defines `defguardp` keyword as elixirPrivateGuard' do
13+
expect(<<~EOF).to include_elixir_syntax('elixirPrivateGuard', 'defguardp')
14+
defguardp some_private_guard(x) when is_integer(x)
15+
EOF
16+
end
17+
end
18+
519
describe 'Guard syntax' do
620
it 'guard in function' do
721
expect(<<~EOF).to include_elixir_syntax('elixirKernelFunction', 'is_atom')

syntax/elixir.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ syn region elixirDocString matchgroup=elixirSigilDelimiter start=+\%(@\w*doc\s\
141141
" Defines
142142
syn match elixirDefine '\<def\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
143143
syn match elixirPrivateDefine '\<defp\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
144+
syn match elixirGuard '\<defguard\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
145+
syn match elixirPrivateGuard '\<defguardp\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
144146
syn match elixirModuleDefine '\<defmodule\>\(:\)\@!' nextgroup=elixirModuleDeclaration skipwhite skipnl
145147
syn match elixirProtocolDefine '\<defprotocol\>\(:\)\@!' nextgroup=elixirProtocolDeclaration skipwhite skipnl
146148
syn match elixirImplDefine '\<defimpl\>\(:\)\@!' nextgroup=elixirImplDeclaration skipwhite skipnl
@@ -175,6 +177,8 @@ syn match elixirExUnitAssert "\(^\s*\)\@<=\<\(catch_exit\|catch_throw\|flunk\|r
175177
hi def link elixirBlockDefinition Keyword
176178
hi def link elixirDefine Define
177179
hi def link elixirPrivateDefine Define
180+
hi def link elixirGuard Define
181+
hi def link elixirPrivateGuard Define
178182
hi def link elixirModuleDefine Define
179183
hi def link elixirProtocolDefine Define
180184
hi def link elixirImplDefine Define

0 commit comments

Comments
 (0)