Skip to content

Commit 7982966

Browse files
sgruszkachrisbra
authored andcommitted
runtime(bpftrace): add base syntax plugin
Problem: No syntax highlighting for bpftrace files. Solution: Add basic syntax rules, which cover comments, keywords, strings, numbers, macros and probes (the bpftrace specific items). closes: #18999 Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent de37e74 commit 7982966

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

.github/MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ runtime/syntax/asy.vim @avidseeker
454454
runtime/syntax/autohotkey.vim @mmikeww
455455
runtime/syntax/awk.vim @dkearns
456456
runtime/syntax/basic.vim @dkearns
457+
runtime/syntax/bpftrace.vim @sgruszka
457458
runtime/syntax/bst.vim @tpope
458459
runtime/syntax/bzl.vim @dbarnett
459460
runtime/syntax/bzr.vim @hdima

runtime/syntax/bpftrace.vim

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
" Vim syntax file
2+
" Language: bpftrace
3+
" Maintainer: Stanislaw Gruszka <stf_xl@wp.pl>
4+
" Last Change: 2025 Dec 22
5+
6+
" Quit when a syntax file was already loaded
7+
if exists("b:current_syntax")
8+
finish
9+
endif
10+
11+
let s:cpo_save = &cpo
12+
set cpo&vim
13+
14+
syn keyword bpftraceConditional if else
15+
syn keyword bpftraceRepeat while for unroll
16+
syn keyword bpftraceStatement break continue return
17+
syn keyword bpftraceKeyword let macro import config
18+
syn keyword bpftraceOperator sizeof offsetof
19+
20+
syn keyword bpftraceProbe BEGIN END begin end
21+
syn match bpftraceProbe "\v<(bench|self|test)\ze:"
22+
syn match bpftraceProbe "\v<(fentry|fexit|kfunc|kretfunc|kprobe|kretprobe)\ze:"
23+
syn match bpftraceProbe "\v<(profile|interval|iterator|hardware|software|uprobe|uretprobe)\ze:"
24+
syn match bpftraceProbe "\v<(usdt|tracepoint|rawtracepoint|watchpoint|asyncwatchpoint)\ze:"
25+
syn match bpftraceProbe "\v(^|[^:])<\zs(h|i|it|f|fr|k|kr|p|rt|s|t|u|ur|U|w|aw)\ze:"
26+
27+
syn keyword bpftraceType bool int8 int16 int32 int64
28+
syn keyword bpftraceType uint8 uint16 uint32 uint64
29+
syn keyword bpftraceType struct
30+
31+
syn match bpftraceMacro "\<\h\w*\ze\_s*("
32+
33+
syn match bpftraceNumber display "[+-]\=\<\d\+\>"
34+
syn match bpftraceNumber display "\<0x\x\+\>"
35+
36+
syn keyword bpftraceBoolean true false
37+
38+
syn region bpftraceString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell extend
39+
40+
syn keyword bpftraceTodo contained TODO FIXME XXX
41+
syn match bpftraceShebang /\%^#![^[].*/
42+
syn region bpftraceCommentLine start="//" end="$" contains=bpftraceTodo,@Spell
43+
syn region bpftraceCommentBlock matchgroup=bpftraceCommentBlock start="/\*" end="\*/" contains=bpftraceTodo,@Spell
44+
45+
" Define the default highlighting.
46+
hi def link bpftraceConditional Conditional
47+
hi def link bpftraceMacro Macro
48+
hi def link bpftraceRepeat Repeat
49+
hi def link bpftraceKeyword Keyword
50+
hi def link bpftraceNumber Number
51+
hi def link bpftraceBoolean Boolean
52+
hi def link bpftraceShebang Comment
53+
hi def link bpftraceCommentLine Comment
54+
hi def link bpftraceCommentBlock Comment
55+
hi def link bpftraceString String
56+
hi def link bpftraceType Type
57+
hi def link bpftraceProbe Identifier
58+
59+
syn sync minlines=100
60+
61+
let b:current_syntax = "bpftrace"
62+
63+
let &cpo = s:cpo_save
64+
unlet s:cpo_save
65+
66+
" vim: ts=8 sw=8 noexpandtab

0 commit comments

Comments
 (0)