robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40370 from zeertzjq/vim-8513982313be457f5

master
4.4 KiB95 linesraw
1" Vim syntax file
2" Language: beancount
3" Maintainer: Nathan Grigg
4" Latest Revision: 2024-11-25
5" 2026 Jun 22 by Vim Project: allow non-ASCII account names
6
7if exists("b:current_syntax")
8    finish
9endif
10
11syntax clear
12" Basics.
13syn region beanComment start="\s*;" end="$" keepend contains=beanMarker
14syn match beanMarker "\v(\{\{\{|\}\}\})\d?" contained
15syn region beanString start='"' skip='\\"' end='"' contained
16syn match beanAmount "\v[-+]?[[:digit:].,]+" nextgroup=beanCurrency contained
17            \ skipwhite
18syn match beanCurrency "\v\w+" contained
19" Account name: alphanumeric with at least one colon.
20syn match beanAccount "\v[[:alnum:]]+:\S+" contained
21syn match beanTag "\v#[-[:alnum:]]+" contained
22syn match beanLink "\v\^\S+" contained
23" We must require a space after the flag because you can have flags per
24" transaction leg, and the letter-based flags might get confused with the
25" start of an account name.
26syn match beanFlag "\v[*!&#?%PSTCURM]\s\@=" contained
27
28" Most directives start with a date.
29syn match beanDate "^\v\d{4}[-/]\d{2}[-/]\d{2}" skipwhite
30            \ nextgroup=beanOpen,beanTxn,beanClose,beanCommodity,beanNote,beanBalance,beanEvent,beanPad,beanPrice
31" Options and events have two string arguments. The first, we are matching as
32" beanOptionTitle and the second as a regular string.
33syn region beanOption matchgroup=beanKeyword start="^option" end="$"
34            \ keepend contains=beanOptionTitle,beanComment
35syn region beanOption matchgroup=beanKeyword start="^plugin" end="$"
36            \ keepend contains=beanString,beanComment
37syn region beanInclude matchgroup=beanKeyword start="^include" end="$"
38            \ keepend contains=beanString,beanComment
39syn region beanEvent matchgroup=beanKeyword start="event" end="$" contained
40            \ keepend contains=beanOptionTitle,beanComment
41syn region beanOptionTitle start='"' skip='\\"' end='"' contained
42            \ nextgroup=beanString skipwhite
43syn region beanOpen matchgroup=beanKeyword start="open" end="$" keepend
44            \ contained contains=beanAccount,beanCurrency,beanComment
45syn region beanClose matchgroup=beanKeyword start="close" end="$" keepend
46            \ contained contains=beanAccount,beanComment
47syn region beanCommodity matchgroup=beanKeyword start="commodity" end="$" keepend
48            \ contained contains=beanCurrency,beanComment
49syn region beanNote matchgroup=beanKeyword start="\vnote|document" end="$"
50            \ keepend contains=beanAccount,beanString,beanComment contained
51syn region beanBalance matchgroup=beanKeyword start="balance" end="$" contained
52            \ keepend contains=beanAccount,beanAmount,beanComment
53syn region beanPrice matchgroup=beanKeyword start="price" end="$" contained
54            \ keepend contains=beanCurrency,beanAmount
55syn region beanPushTag matchgroup=beanKeyword start="\v^(push|pop)tag" end="$"
56            \ keepend contains=beanTag
57syn region beanPad matchgroup=beanKeyword start="pad" end="$" contained
58            \ keepend contains=beanAccount,beanComment
59
60syn region beanTxn matchgroup=beanKeyword start="\v\s+(txn|[*!&#?%PSTCURM])" skip="^\s"
61            \ end="^" keepend contained fold
62            \ contains=beanString,beanPost,beanComment,beanTag,beanLink,beanMeta
63syn region beanPost start="^\v\C\s+(([*!&#?%PSTCURM]\s+)?[A-Z])@=" end="$"
64            \ contains=beanFlag,beanAccount,beanAmount,beanComment,beanCost,beanPrice
65syn region beanMeta matchgroup=beanTag start="^\v\C\s+[a-z][-_a-zA-Z0-9]*:(\s|$)@=" end="$"
66
67syn region beanCost start="{" end="}" contains=beanAmount contained
68syn match beanPrice "\V@@\?" nextgroup=beanAmount contained
69
70syn region beanHashHeaderFold
71    \ start="^\z(#\+\)"
72    \ skip="^\s*\z1#\+"
73    \ end="^\(#\)\@="
74    \ fold contains=TOP
75
76syn region beanStarHeaderFold
77    \ start="^\z(\*\+\)"
78    \ skip="^\s*\z1\*\+"
79    \ end="^\(\*\)\@="
80    \ fold contains=TOP
81
82highlight default link beanKeyword Keyword
83highlight default link beanOptionTitle Keyword
84highlight default link beanDate Keyword
85highlight default link beanString String
86highlight default link beanComment Comment
87highlight default link beanAccount Identifier
88highlight default link beanAmount Number
89highlight default link beanCurrency Number
90highlight default link beanCost Number
91highlight default link beanPrice Number
92highlight default link beanTag Tag
93highlight default link beanLink Comment
94highlight default link beanMeta Special
95highlight default link beanFlag Keyword