clerk/journal/ast/directives.go (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com add support of subdirectives and it's highlights, 1 month ago
olexsmir@gmail.com add support of subdirectives and it's highlights, 1 month ago
| 1 | package ast |
| 2 | |
| 3 | import "olexsmir.xyz/clerk/journal/token" |
| 4 | |
| 5 | type AccountDirective struct { |
| 6 | Account Account |
| 7 | Subdirectives []AccountSubdirective // indented block lines, in order |
| 8 | Comment *Comment |
| 9 | Span token.Span |
| 10 | } |
| 11 | |
| 12 | func (AccountDirective) entryNode() {} |
| 13 | |
| 14 | type AccountSubdirective struct { |
| 15 | Name string // "alias" / "type" / "note" / "" for comment lines |
| 16 | NameSpan token.Span // keyword span; for comment lines, the marker span |
| 17 | Value string // text after the keyword; "" for comment lines |
| 18 | ValueSpan token.Span // value span; zero for comment lines and empty values |
| 19 | Comment *Comment // inline comment after the value; for comment lines, the line itself |
| 20 | } |
| 21 | |
| 22 | type CommodityDirective struct { |
| 23 | Commodity string |
| 24 | CommoditySpan token.Span // span of the commodity token |
| 25 | FormatSub *FormatSubDirective // display format; nil when not given |
| 26 | BlockComments []*Comment // indented comment-only lines inside the block |
| 27 | Comment *Comment // optional inline comment |
| 28 | Span token.Span |
| 29 | } |
| 30 | |
| 31 | func (CommodityDirective) entryNode() {} |
| 32 | |
| 33 | // FormatSubDirective is a commodity display format, either inline on the |
| 34 | // directive line ("commodity $1,000.00") or as a "format" subdirective. |
| 35 | type FormatSubDirective struct { |
| 36 | Amount Amount |
| 37 | KeywordSpan token.Span // span of the "format" keyword; zero when inline |
| 38 | Comment *Comment // inline comment; subdirective form only |
| 39 | } |
| 40 | |
| 41 | type PayeeDirective struct { |
| 42 | Name *Payee |
| 43 | Comment *Comment |
| 44 | Span token.Span |
| 45 | } |
| 46 | |
| 47 | func (PayeeDirective) entryNode() {} |
| 48 | |
| 49 | type TagDirective struct { |
| 50 | Name string |
| 51 | Comment *Comment // optional inline comment |
| 52 | Span token.Span |
| 53 | } |
| 54 | |
| 55 | func (TagDirective) entryNode() {} |
| 56 | |
| 57 | type IncludeDirective struct { |
| 58 | Path string |
| 59 | Comment *Comment // optional inline comment |
| 60 | Span token.Span |
| 61 | } |
| 62 | |
| 63 | func (IncludeDirective) entryNode() {} |
| 64 | |
| 65 | type AliasDirective struct { |
| 66 | From, To Account |
| 67 | Comment *Comment // optional inline comment |
| 68 | Span token.Span |
| 69 | } |
| 70 | |
| 71 | func (AliasDirective) entryNode() {} |
| 72 | |
| 73 | type YearDirective struct { |
| 74 | Year int |
| 75 | Comment *Comment // optional inline comment |
| 76 | Span token.Span |
| 77 | } |
| 78 | |
| 79 | func (YearDirective) entryNode() {} |
| 80 | |
| 81 | type DecimalMarkDirective struct { |
| 82 | Mark byte // '.' ',' |
| 83 | Comment *Comment // optional inline comment |
| 84 | Span token.Span |
| 85 | } |
| 86 | |
| 87 | func (DecimalMarkDirective) entryNode() {} |
| 88 | |
| 89 | type DefaultCommodityDirective struct { |
| 90 | Amount Amount |
| 91 | Comment *Comment // optional inline comment |
| 92 | Span token.Span |
| 93 | } |
| 94 | |
| 95 | func (DefaultCommodityDirective) entryNode() {} |
| 96 | |
| 97 | type MarketPriceDirective struct { |
| 98 | DateTime DateTime |
| 99 | Commodity string |
| 100 | Amount Amount |
| 101 | Comment *Comment // optional inline comment |
| 102 | Span token.Span |
| 103 | } |
| 104 | |
| 105 | func (MarketPriceDirective) entryNode() {} |
| 106 | |
| 107 | type ConversionDirective struct { |
| 108 | From Amount |
| 109 | To Amount |
| 110 | Comment *Comment // optional inline comment |
| 111 | Span token.Span |
| 112 | } |
| 113 | |
| 114 | func (ConversionDirective) entryNode() {} |
| 115 | |
| 116 | type ApplyDirective struct { |
| 117 | Expr string // text after apply e.g "tag foo" |
| 118 | Comment *Comment |
| 119 | Span token.Span |
| 120 | } |
| 121 | |
| 122 | func (ApplyDirective) entryNode() {} |
| 123 | |
| 124 | type EndDirective struct { |
| 125 | Expr string // text after end e.g "tag" |
| 126 | Comment *Comment // optional inline comment |
| 127 | Span token.Span |
| 128 | } |
| 129 | |
| 130 | func (EndDirective) entryNode() {} |
| 131 | |
| 132 | type CommentBlockDirective struct { |
| 133 | Header string // text after "comment" on the same line |
| 134 | Content string |
| 135 | Comment *Comment // optional inline comment |
| 136 | Span token.Span |
| 137 | } |
| 138 | |
| 139 | func (CommentBlockDirective) entryNode() {} |
| 140 | |
| 141 | type IgnoredDirective struct { |
| 142 | Text string // content after N (commodity symbol or text) |
| 143 | Comment *Comment // optional inline comment |
| 144 | Span token.Span |
| 145 | } |
| 146 | |
| 147 | func (IgnoredDirective) entryNode() {} |