aboutsummaryrefslogtreecommitdiffstats
path: root/syntax/beancount.vim
blob: fd7d18a27214a7944404bd649d21dbee010c5957 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
" Vim syntax file
" Language: beancount
" Maintainer: Nathan Grigg
" Latest Revision: 2014-10-07

" if exists("b:current_syntax")
"     finish
" endif

syntax clear
" Basics.
syn region beanComment start="\s*;" end="$" keepend contains=beanMarker
syn match beanMarker "\v(\{\{\{|\}\}\})\d?" contained
syn region beanString start='"' skip='\\"' end='"' contained
syn match beanAmount "\v[-+]?[[:digit:].,]+" nextgroup=beanCurrency contained
            \ skipwhite
syn match beanCurrency "\v\w+" contained
" Account name: alphanumeric with at least one colon.
syn match beanAccount "\v[[:alnum:]]+:[[:alnum:]:]+" contained


" Most directives start with a date.
syn match beanDate "^\v\d{4}-\d{2}-\d{2}" skipwhite
            \ nextgroup=beanOpen,beanTxn,beanClose,beanNote,beanBalance,beanEvent,beanPad
" Options and events have two string arguments. The first, we are matching as
" beanOptionTitle and the second as a regular string.
syn region beanOption matchgroup=beanKeyword start="^option" end="$"
            \ contains=beanOptionTitle,beanComment
syn region beanEvent matchgroup=beanKeyword start="event" end="$" contained
            \ contains=beanOptionTitle,beanComment
syn region beanOptionTitle start='"' skip='\\"' end='"' contained
            \ nextgroup=beanString skipwhite
syn region beanOpen matchgroup=beanKeyword start="open" end="$"
            \ contains=beanAccount,beanCurrency,beanComment
syn region beanClose matchgroup=beanKeyword start="close" end="$"
            \ contains=beanAccount,beanComment
syn region beanNote matchgroup=beanKeyword start="\vnote|document" end="$"
            \ contains=beanAccount,beanString,beanComment
syn region beanBalance matchgroup=beanKeyword start="balance" end="$"
            \ contains=beanAccount,beanAmount,beanComment
syn keyword beanKeyword pushtag poptag
syn region beanPad matchgroup=beanKeyword start="^pad" end="$"
            \ contains=beanAccount,beanComment

syn region beanTxn matchgroup=beanKeyword start="\v(txn)?\s+[*!]" skip="^\s"
            \ end="^" contains=beanString,beanPost,beanComment contained
syn region beanPost start="^\v\s+" end="$"
            \ contains=beanAccount,beanAmount,beanComment,beanCost,beanPrice
syn region beanCost start="{" end="}" contains=beanAmount contained
syn match beanPrice "\V@@\?" nextgroup=beanAmount contained
" TODO: tags and links

highlight default link beanKeyword Keyword
highlight default link beanOptionTitle Keyword
highlight default link beanDate Keyword
highlight default link beanString String
highlight default link beanComment Comment
highlight default link beanAccount Identifier
highlight default link beanAmount Number
highlight default link beanCurrency Number
highlight default link beanCost Number
highlight default link beanPrice Number