clerk/journal/semantic/context.go (view raw)
| 1 | package semantic |
| 2 | |
| 3 | import ( |
| 4 | "olexsmir.xyz/clerk/journal" |
| 5 | "olexsmir.xyz/clerk/journal/ast" |
| 6 | ) |
| 7 | |
| 8 | // Context holds workspace-level semantic data built from parsed journal files. |
| 9 | type Context struct { |
| 10 | // Files in dependency order (includes before includers). |
| 11 | Files []*journal.ParsedFile |
| 12 | |
| 13 | Accounts map[string]*AccountInfo |
| 14 | Commodities map[string]*CommodityInfo |
| 15 | } |
| 16 | |
| 17 | type AccountInfo struct { |
| 18 | // len == 0 = account is used but never declared (undeclared) |
| 19 | // len > 1 = account is declared more than once (duplicated) |
| 20 | // len > 0 = account appears in a posting |
| 21 | Directives []*ast.AccountDirective |
| 22 | Usages []AccountUsage |
| 23 | } |
| 24 | |
| 25 | // AccountUsage is a single posting that references an account. |
| 26 | type AccountUsage struct { |
| 27 | FileIndex int |
| 28 | Posting *ast.Posting |
| 29 | } |
| 30 | |
| 31 | // CommodityInfo tracks all declarations and usages for one commodity. |
| 32 | type CommodityInfo struct { |
| 33 | Directives []*ast.CommodityDirective |
| 34 | Usages []CommodityUsage |
| 35 | } |
| 36 | |
| 37 | // CommodityUsage is a single amount that references a commodity. |
| 38 | type CommodityUsage struct { |
| 39 | FileIndex int |
| 40 | Amount *ast.Amount |
| 41 | } |