Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertHledgerGlob(pattern string) string
- func IsGlobPattern(path string) bool
- func ResolvePath(basePath, includePath string) string
- func ResolvePathSafe(basePath, includePath string) (string, error)
- type ErrorKind
- type FileSource
- type IncludeProvenance
- type Item
- type JournalOccurrence
- type Limits
- type LoadError
- type LoadOptions
- type Loader
- func (l *Loader) ClearCache()
- func (l *Loader) ExpandGlob(basePath, pattern string) ([]string, error)
- func (l *Loader) FileSizeError(content string) *LoadError
- func (l *Loader) InvalidateFile(path string)
- func (l *Loader) Load(path string) (*ResolvedJournal, []LoadError)
- func (l *Loader) LoadFromContent(path, content string) (*ResolvedJournal, []LoadError)
- func (l *Loader) LoadWithOptions(path string, options LoadOptions) (*ResolvedJournal, []LoadError)
- func (l *Loader) SetLimits(limits Limits)
- type Occurrence
- type OccurrenceID
- type OverlayEntry
- type ResolvedItem
- type ResolvedItemKind
- type ResolvedJournal
- func (r *ResolvedJournal) AllDirectives() []ast.Directive
- func (r *ResolvedJournal) AllIncludes() []ast.Include
- func (r *ResolvedJournal) AllTransactions() []ast.Transaction
- func (r *ResolvedJournal) DefaultCommodityAt(id OccurrenceID, sourceOffset int) string
- func (r *ResolvedJournal) FormatDirectives() []ast.Directive
- func (r *ResolvedJournal) FormatsAt(id OccurrenceID, sourceOffset int) map[string]formatter.CommodityFormat
- func (r *ResolvedJournal) InvalidateOccurrences()
- func (r *ResolvedJournal) Occurrence(id OccurrenceID) *JournalOccurrence
- func (r *ResolvedJournal) OccurrencesForCanonical(path string) []JournalOccurrence
- func (r *ResolvedJournal) OccurrencesForPath(path string) []JournalOccurrence
- func (r *ResolvedJournal) SourceJournals() []*ast.Journal
Constants ¶
const ( ItemTransaction = ResolvedItemTransaction ItemPeriodicTransaction = ResolvedItemPeriodicTransaction ItemAutoPostingRule = ResolvedItemAutoPostingRule ItemDirective = ResolvedItemDirective ItemComment = ResolvedItemComment ItemInclude = ResolvedItemInclude )
Variables ¶
var (
ErrPathTraversal = errors.New("path traversal detected")
)
Functions ¶
func ConvertHledgerGlob ¶
func IsGlobPattern ¶
func ResolvePath ¶
func ResolvePathSafe ¶
Types ¶
type FileSource ¶
type IncludeProvenance ¶ added in v0.2.51
type IncludeProvenance struct {
ParentID OccurrenceID
SourcePath string
IncludeRange ast.Range
// Range is retained while loader call sites migrate to IncludeRange.
Range ast.Range
RawPattern string
MatchIndex int
Depth int
}
IncludeProvenance identifies the include site that created an occurrence. ParentID is zero only for the root occurrence.
type Item ¶ added in v0.2.51
type Item = ResolvedItem
Item is retained as a concise alias for ResolvedItem.
type JournalOccurrence ¶ added in v0.2.51
type JournalOccurrence struct {
ID OccurrenceID
Path string
CanonicalPath string
Journal *ast.Journal
InitialContext parser.Context
Checkpoints []parser.ContextCheckpoint
Via IncludeProvenance
Items []ResolvedItem
}
JournalOccurrence is one inclusion of a journal source. The same source can have several occurrences with different provenance and parser context.
type Limits ¶
func DefaultLimits ¶
func DefaultLimits() Limits
type LoadError ¶
type LoadOptions ¶ added in v0.2.51
type LoadOptions struct {
Overlays map[string]OverlayEntry
}
LoadOptions provides a per-load immutable editor-content snapshot.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader caches normalized source text. Parsed journals are occurrence-specific because parser context depends on the include site.
func (*Loader) ClearCache ¶
func (l *Loader) ClearCache()
func (*Loader) ExpandGlob ¶ added in v0.2.28
func (*Loader) FileSizeError ¶ added in v0.2.52
FileSizeError returns a file-too-large LoadError when content exceeds the configured MaxFileSizeBytes, or nil when it fits. It lets callers guard the analyze path before parsing.
func (*Loader) InvalidateFile ¶
func (*Loader) LoadFromContent ¶
func (l *Loader) LoadFromContent(path, content string) (*ResolvedJournal, []LoadError)
func (*Loader) LoadWithOptions ¶ added in v0.2.51
func (l *Loader) LoadWithOptions(path string, options LoadOptions) (*ResolvedJournal, []LoadError)
type Occurrence ¶ added in v0.2.51
type Occurrence = JournalOccurrence
Occurrence is retained as a concise alias for JournalOccurrence.
type OccurrenceID ¶ added in v0.2.51
type OccurrenceID uint64
OccurrenceID uniquely identifies a journal occurrence within one resolved journal. The root occurrence has ID 1.
type OverlayEntry ¶ added in v0.2.51
type ResolvedItem ¶ added in v0.2.51
type ResolvedItem struct {
OccurrenceID OccurrenceID
Kind ResolvedItemKind
Index int
}
ResolvedItem references one item in an occurrence journal. ResolvedJournal.Items stores these references in textual order with children inlined at include sites.
type ResolvedItemKind ¶ added in v0.2.51
type ResolvedItemKind uint8
ResolvedItemKind identifies a source node in an occurrence journal.
const ( ResolvedItemTransaction ResolvedItemKind = iota ResolvedItemPeriodicTransaction ResolvedItemAutoPostingRule ResolvedItemDirective ResolvedItemComment ResolvedItemInclude )
type ResolvedJournal ¶
type ResolvedJournal struct {
Occurrences []JournalOccurrence
Items []ResolvedItem
ByPath map[string][]OccurrenceID
ByCanonical map[string][]OccurrenceID
// Legacy fields are a compile-only first-occurrence projection. New code must
// use Occurrences and Items for resolved journal semantics.
Primary *ast.Journal
Files map[string]*ast.Journal
FileOrder []string
Errors []LoadError
}
func NewResolvedJournal ¶
func NewResolvedJournal(primary *ast.Journal) *ResolvedJournal
func (*ResolvedJournal) AllDirectives ¶
func (r *ResolvedJournal) AllDirectives() []ast.Directive
func (*ResolvedJournal) AllIncludes ¶
func (r *ResolvedJournal) AllIncludes() []ast.Include
func (*ResolvedJournal) AllTransactions ¶
func (r *ResolvedJournal) AllTransactions() []ast.Transaction
func (*ResolvedJournal) DefaultCommodityAt ¶ added in v0.2.51
func (r *ResolvedJournal) DefaultCommodityAt(id OccurrenceID, sourceOffset int) string
DefaultCommodityAt returns the default commodity symbol (from the D directive) in effect at sourceOffset in the occurrence identified by id.
func (*ResolvedJournal) FormatDirectives ¶ added in v0.2.19
func (r *ResolvedJournal) FormatDirectives() []ast.Directive
FormatDirectives returns directives suitable for formatter commodity format extraction. It excludes DecimalMarkDirective from included files because decimal-mark is file-scoped per hledger semantics, while primary file directives are passed through unfiltered.
func (*ResolvedJournal) FormatsAt ¶ added in v0.2.51
func (r *ResolvedJournal) FormatsAt(id OccurrenceID, sourceOffset int) map[string]formatter.CommodityFormat
FormatsAt returns the commodity formats in effect at sourceOffset in the occurrence identified by id.
For a child occurrence it starts with the formats inherited from the parent at the include site, then applies the child's own directives that appear before sourceOffset. Child decimal-mark and D stay local to the child.
For the root occurrence it walks the Items stream up to sourceOffset, collecting root directives and merge-forward CommodityDirective declarations from child occurrences (child D and decimal-mark do not merge forward).
func (*ResolvedJournal) InvalidateOccurrences ¶ added in v0.2.51
func (r *ResolvedJournal) InvalidateOccurrences()
InvalidateOccurrences clears the occurrence-based semantic source so the All* helpers fall back to the legacy Primary/Files/FileOrder projection. Consumers that still mutate the legacy projection directly (workspace incremental updates) call this to keep All* consistent until they migrate to occurrences.
func (*ResolvedJournal) Occurrence ¶ added in v0.2.51
func (r *ResolvedJournal) Occurrence(id OccurrenceID) *JournalOccurrence
Occurrence returns the occurrence with id, if present.
func (*ResolvedJournal) OccurrencesForCanonical ¶ added in v0.2.51
func (r *ResolvedJournal) OccurrencesForCanonical(path string) []JournalOccurrence
OccurrencesForCanonical returns all occurrences for a canonical filesystem path. The input is canonicalized so a real path finds occurrences included through a symlink (and vice versa).
func (*ResolvedJournal) OccurrencesForPath ¶ added in v0.2.51
func (r *ResolvedJournal) OccurrencesForPath(path string) []JournalOccurrence
OccurrencesForPath returns all occurrences for an exact source path.
func (*ResolvedJournal) SourceJournals ¶ added in v0.2.51
func (r *ResolvedJournal) SourceJournals() []*ast.Journal
SourceJournals returns each journal to aggregate, in semantic order. When occurrences are present (fresh loader output) every occurrence's journal is returned once, so repeated includes are counted per occurrence. Otherwise it falls back to the legacy Primary/Files/FileOrder projection for consumers that still mutate it directly.