parser

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is a ring buffer of recent lines for multi-line construct detection.

func NewBuffer

func NewBuffer(size int) *Buffer

NewBuffer creates a buffer with the given capacity.

func (*Buffer) AllocGroupID

func (b *Buffer) AllocGroupID() int

AllocGroupID returns a new unique group ID.

func (*Buffer) Count

func (b *Buffer) Count() int

Count returns how many lines are in the buffer.

func (*Buffer) DetectMultiLineJSON

func (b *Buffer) DetectMultiLineJSON(allLines []*line.LogLine) []int

DetectMultiLineJSON scans backward from the most recently pushed line to detect a complete multi-line JSON construct. Returns the indices into the global lines slice that should be reparsed, or nil.

func (*Buffer) Get

func (b *Buffer) Get(idx int) *line.LogLine

Get returns the line at the given ring index.

func (*Buffer) Last

func (b *Buffer) Last(n int) []*line.LogLine

Last returns the last N lines in order (oldest first).

func (*Buffer) Push

func (b *Buffer) Push(l *line.LogLine) int

Push adds a line to the buffer and returns its absolute index.

type DiffState

type DiffState int

DiffState tracks the state machine for unified diff detection.

const (
	DiffIdle DiffState = iota
	DiffHeader1
	DiffHeader2
	DiffBody
)

type DiffTracker

type DiffTracker struct {
	State      DiffState
	GroupID    int
	StartIndex int
	Indent     string // leading whitespace from the @@ hunk line
}

DiffTracker tracks diff state across lines.

func NewDiffTracker

func NewDiffTracker() *DiffTracker

NewDiffTracker creates a new diff state tracker.

func (*DiffTracker) Feed

func (dt *DiffTracker) Feed(raw string, lineIdx int, buf *Buffer) (*line.DiffMeta, int)

Feed processes a line through the diff state machine. Returns the DiffMeta if the line is part of a diff block, nil otherwise.

func (*DiffTracker) InDiffBlock

func (dt *DiffTracker) InDiffBlock() bool

InDiffBlock returns true if we're currently inside a confirmed diff block.

func (*DiffTracker) Reset

func (dt *DiffTracker) Reset()

Reset resets the diff tracker state.

type ParseResult

type ParseResult struct {
	Line           *line.LogLine
	ReparseIndices []int
}

ParseResult contains the parsed line and any reparse indices.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser orchestrates all detectors.

func New

func New() *Parser

New creates a new Parser.

func (*Parser) AppendExternal

func (p *Parser) AppendExternal(l *line.LogLine)

AppendExternal appends a pre-built LogLine to the parser's internal slice without running detectors. The ingestor uses this for synthesized lines (e.g. coalesced ffmpeg progress entries) so that parser.allLines and the store remain index-aligned — reparseIndices and Search both depend on that invariant. The line is pushed into the lookback buffer too, so the multi-line JSON detector doesn't underrun when the next raw line arrives.

func (*Parser) LastLine

func (p *Parser) LastLine() *line.LogLine

LastLine returns the most recently parsed line, or nil if none.

func (*Parser) LineAt

func (p *Parser) LineAt(idx int) *line.LogLine

LineAt returns the line at the given index.

func (*Parser) LineCount

func (p *Parser) LineCount() int

LineCount returns the total number of lines.

func (*Parser) Lines

func (p *Parser) Lines() []*line.LogLine

Lines returns all parsed lines.

func (*Parser) Parse

func (p *Parser) Parse(raw string, fromStderr bool) ParseResult

Parse processes a raw line and returns a ParseResult.

func (*Parser) ReleaseOldLines

func (p *Parser) ReleaseOldLines(keepN int)

ReleaseOldLines nils out all but the last keepN entries in allLines, allowing the GC to reclaim LogLine objects that the store has offloaded to disk. The slice length and indices are preserved so that reparseIndices returned by DetectMultiLineJSON remain valid.

func (*Parser) Search

func (p *Parser) Search(query string, startIdx int) int

Search finds the next line containing query (case-insensitive) starting from startIdx.

func (*Parser) SearchReverse

func (p *Parser) SearchReverse(query string, startIdx int) int

SearchReverse finds the previous line containing query starting from startIdx.

type TableTracker

type TableTracker struct {
	// contains filtered or unexported fields
}

TableTracker detects aligned column tables across consecutive lines.

func NewTableTracker

func NewTableTracker() *TableTracker

NewTableTracker creates a new table tracker.

func (*TableTracker) Feed

func (tt *TableTracker) Feed(raw string, tabGaps []line.TabGap, lineIdx int, buf *Buffer, allLines []*line.LogLine) *line.TableMeta

Feed checks if the current line forms a table with previous lines. Returns table metadata if it matches, nil otherwise. When tabGaps is non-empty, those positions are used as authoritative column boundaries (tabs are unambiguous column delimiters); otherwise we fall back to detecting ≥2-space gaps.

func (*TableTracker) GroupID

func (tt *TableTracker) GroupID() int

GroupID returns the current group ID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL