parser

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package parser provides low-level GEDCOM line parsing functionality.

This package handles the tokenization and parsing of individual GEDCOM lines, converting them into Line structures with level, tag, value, and cross-reference information. It supports all standard GEDCOM formats and provides detailed error reporting with line numbers.

Example usage:

p := parser.NewParser(reader)
for {
    line, err := p.ParseLine()
    if err == io.EOF {
        break
    }
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Level %d: %s = %s\n", line.Level, line.Tag, line.Value)
}

Index

Constants

View Source
const MaxNestingDepth = 100

MaxNestingDepth is the maximum allowed nesting depth to prevent stack overflow.

Variables

This section is empty.

Functions

This section is empty.

Types

type Line

type Line struct {
	// Level indicates the hierarchical depth (0, 1, 2, etc.)
	Level int

	// Tag is the GEDCOM tag (e.g., HEAD, INDI, NAME, BIRT)
	Tag string

	// Value is the optional value associated with the tag
	Value string

	// XRef is the optional cross-reference identifier (e.g., @I1@)
	XRef string

	// LineNumber is the line number in the source file (1-based)
	// Used for error reporting
	LineNumber int
}

Line represents a single parsed line from a GEDCOM file. GEDCOM files use a line-based format with hierarchical levels. Each line format: LEVEL [XREF] TAG [VALUE]

type ParseError

type ParseError struct {
	// Line is the line number where the error occurred (1-based)
	Line int

	// Message describes what went wrong
	Message string

	// Context provides the actual line content that caused the error
	Context string

	// Err is the underlying error, if any
	Err error
}

ParseError represents an error that occurred during parsing. It includes line number and context for better error reporting.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type Parser

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

Parser parses GEDCOM files into Line structures.

func NewParser

func NewParser() *Parser

NewParser creates a new Parser instance.

func (*Parser) Parse

func (p *Parser) Parse(r io.Reader) ([]*Line, error)

Parse reads a GEDCOM file from a reader and returns all parsed lines.

func (*Parser) ParseLine

func (p *Parser) ParseLine(input string) (*Line, error)

ParseLine parses a single GEDCOM line. GEDCOM line format: LEVEL [XREF] TAG [VALUE] Examples:

0 HEAD
0 @I1@ INDI
1 NAME John /Smith/
2 GIVN John

func (*Parser) Reset

func (p *Parser) Reset()

Reset resets the parser state for reuse.

Jump to

Keyboard shortcuts

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