Skip to content

Commit

Permalink
Merge branch 'topic/bbannier/bif'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Jan 27, 2025
2 parents cfae9b7 + 769d689 commit a0b57ff
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 53 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected].0
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected].1
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ Install like any other Vim plugin. Examples:
* Pathogen: `git clone https://github.com/zeek/vim-zeek ~/.vim/bundle/vim-zeek`

* Vundle: `Plugin 'zeek/vim-zeek'`

## Development

This plugin contains [Vader](https://github.com/junegunn/vader.vim) tests in
`test/`. After installing Vader you can run the tests in the current buffer
with `:Vader`, or all tests with `:Vader test/*`.
4 changes: 4 additions & 0 deletions ftdetect/bif.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if has('autocmd')
augroup bif
autocmd BufNewFile,BufRead *.bif setfiletype bif
endif
23 changes: 23 additions & 0 deletions syntax/bif.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
" Vim syntax file
" Language: Bif (https://github.com/zeek/bifcl)

if exists('b:current_syntax')
unlet b:current_syntax
endif

" Inherit Zeek syntax
runtime! syntax/zeek.vim

" This file overrides Zeek syntax.
let s:current_syntax=b:current_syntax
unlet b:current_syntax

syntax include @bif_cpp syntax/cpp.vim
syntax region bifCppBlock matchgroup=bifCppDelim start=/%\+{/ end=/%\+}/ contains=@bif_cpp,bifTok fold
syntax match bifCppDelim /\(%(\|%)\)/ fold

" Allow `bifTok` in general `bifCppBlock`, but also explicit in `cParen`.
syntax region bifTok start="@" end="@" excludenl containedin=cParen

highlight default link bifTok Macro
highlight default link bifCppDelim Delimiter
100 changes: 50 additions & 50 deletions syntax/zeek.vim
Original file line number Diff line number Diff line change
Expand Up @@ -115,56 +115,56 @@ syn match zeekOperator /\v\?\$/

syn match zeekAttribute /\v\&<(redef|priority|log|optional|ordered|default|default_insert|add_func|delete_func|expire_func|read_expire|write_expire|create_expire|synchronized|persistent|rotate_interval|rotate_size|encrypt|raw_output|mergeable|error_handler|type_column|deprecated|on_change|backend|broker_store|broker_allow_complex_type|is_assigned|is_used|group)>/

highlight link zeekTodo Todo
highlight link zeekComment Comment
highlight link zeekDirective PreProc
highlight link zeekDirectiveArg Underlined

highlight link zeekBTestKeyword SpecialComment
highlight link zeekBTestOther SpecialComment

highlight link zeekString String
highlight link zeekPattern String
highlight link zeekSeparator Delimiter
highlight link zeekEscapeChar SpecialChar
highlight link zeekFmtSpec Special

highlight link zeekType Type
highlight link zeekTypeDef Typedef
highlight link zeekTypeMod StorageClass
highlight link zeekAttribute StorageClass

highlight link zeekBool Boolean
highlight link zeekInt Number
highlight link zeekFloat Float
highlight link zeekAddr Constant
highlight link zeekHost Constant
highlight link zeekPort Constant
highlight link zeekInterval Constant

highlight link zeekOperator Operator
highlight link zeekOpaqueOf Keyword
highlight link zeekOperatorWord Keyword
highlight link zeekTableOp Keyword

highlight link zeekID Identifier
highlight link zeekModuleID Identifier
highlight link zeekOpaqueID Type
highlight link zeekCall Identifier

highlight link zeekConditional Conditional
highlight link zeekControlFlow Keyword
highlight link zeekLoop Repeat
highlight link zeekLabel Label

highlight link zeekModule Keyword
highlight link zeekAssert Keyword
highlight link zeekRedef Keyword
highlight link zeekExport Keyword
highlight link zeekPrint Keyword
highlight link zeekCopy Keyword
highlight link zeekAsync Keyword
highlight link zeekKeyword Keyword
highlight default link zeekTodo Todo
highlight default link zeekComment Comment
highlight default link zeekDirective PreProc
highlight default link zeekDirectiveArg Underlined

highlight default link zeekBTestKeyword SpecialComment
highlight default link zeekBTestOther SpecialComment

highlight default link zeekString String
highlight default link zeekPattern String
highlight default link zeekSeparator Delimiter
highlight default link zeekEscapeChar SpecialChar
highlight default link zeekFmtSpec Special

highlight default link zeekType Type
highlight default link zeekTypeDef Typedef
highlight default link zeekTypeMod StorageClass
highlight default link zeekAttribute StorageClass

highlight default link zeekBool Boolean
highlight default link zeekInt Number
highlight default link zeekFloat Float
highlight default link zeekAddr Constant
highlight default link zeekHost Constant
highlight default link zeekPort Constant
highlight default link zeekInterval Constant

highlight default link zeekOperator Operator
highlight default link zeekOpaqueOf Keyword
highlight default link zeekOperatorWord Keyword
highlight default link zeekTableOp Keyword

highlight default link zeekID Identifier
highlight default link zeekModuleID Identifier
highlight default link zeekOpaqueID Type
highlight default link zeekCall Identifier

highlight default link zeekConditional Conditional
highlight default link zeekControlFlow Keyword
highlight default link zeekLoop Repeat
highlight default link zeekLabel Label

highlight default link zeekModule Keyword
highlight default link zeekAssert Keyword
highlight default link zeekRedef Keyword
highlight default link zeekExport Keyword
highlight default link zeekPrint Keyword
highlight default link zeekCopy Keyword
highlight default link zeekAsync Keyword
highlight default link zeekKeyword Keyword

" TODO Could add Structure group to enum/record (re)definitions

Expand Down
33 changes: 33 additions & 0 deletions test/syntax-bif.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
" This test cases and requires installation of the Vader testing
" framework, https://github.com/junegunn/vader.vim. After installing the plugin
" tests in the current buffer can be executed with `:Vader`. To execute all
" tests run e.g., `:Vader test/*`.

Given bif (C++ block delimiters):
%{ %}
%%{ %%}
Execute:
AssertEqual SyntaxAt(1, 1), "bifCppDelim"
AssertEqual SyntaxAt(1, 4), "bifCppDelim"
AssertEqual SyntaxAt(2, 1), "bifCppDelim"
AssertEqual SyntaxAt(2, 5), "bifCppDelim"

Given bif (Zeek arg delimiters):
%( %)
Execute:
AssertEqual SyntaxAt(1, 1), "bifCppDelim"
AssertEqual SyntaxAt(1, 4), "bifCppDelim"

Given bif (special tokens):
function foo%(...%): string %{ @ARG@; %}
function foo%(...%): string %{ printf("%s", @ARG@[1]); %}
Execute:
AssertEqual SyntaxAt(1, 33), "bifTok"
AssertEqual SyntaxAt(2, 45), "bifTok"

Given bif (C++ body):
function foo%(...%): string %{ 123; %}
function foo%(...%): string %%{ 123; %%}
Execute:
AssertEqual SyntaxAt(1, 33), "cppNumber"
AssertEqual SyntaxAt(2, 34), "cppNumber"
File renamed without changes.

0 comments on commit a0b57ff

Please sign in to comment.