source

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package source provides source file management and text indexing for the SysML v2 parser.

This package defines SourceFile, which represents a single input file (either .sysml or .kerml), along with Span and Position types for tracking locations in source text. LineIndex provides efficient line/column lookups for error reporting and IDE features.

All source locations are represented as byte offsets; LineIndex converts between offsets and user-facing line:column positions on demand.

Package source owns file content and byte-offset span types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind added in v0.1.2

type Kind int

Kind is the language a file is written in. The two languages share a lexer but not a grammar: KerML notation in a SysML file is diagnosed.

const (
	// KindUnknown is a name with neither model extension.
	KindUnknown Kind = iota
	// KindSysML is a `.sysml` file, whose grammar is SysML.xtext.
	KindSysML
	// KindKerML is a `.kerml` file, whose grammar is KerML.xtext.
	KindKerML
)

func KindOf added in v0.1.2

func KindOf(name string) Kind

KindOf reports the language of a file name by its extension.

func (Kind) String added in v0.1.2

func (k Kind) String() string

String returns the language's name.

type LineIndex

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

LineIndex maps byte offsets to 1-based line/column positions. lineStarts[i] is the byte offset where line (i+1) begins.

func (*LineIndex) OffsetAt

func (li *LineIndex) OffsetAt(p Pos) int

OffsetAt returns the byte offset for a 1-based line/col.

func (*LineIndex) PosAt

func (li *LineIndex) PosAt(offset int) Pos

PosAt returns the 1-based line/col for a byte offset. Col counts bytes from the line start + 1.

type Pos

type Pos struct {
	Line int
	Col  int
}

Pos is a 1-based line/column location.

type SourceFile

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

SourceFile owns the raw bytes of one source file.

func New

func New(name string, content []byte) *SourceFile

New creates a SourceFile from a name and its raw bytes.

func NewWithKind added in v0.2.0

func NewWithKind(name string, content []byte, kind Kind) *SourceFile

NewWithKind creates a source file whose language is explicit rather than inferred from its name. This is used for inline KerML content.

func (*SourceFile) Bytes

func (sf *SourceFile) Bytes() []byte

Bytes returns the raw content (do not mutate).

func (*SourceFile) Kind added in v0.1.2

func (sf *SourceFile) Kind() Kind

Kind reports the language of this file.

func (*SourceFile) Len

func (sf *SourceFile) Len() int

Len returns the byte length of the content.

func (*SourceFile) Lines

func (sf *SourceFile) Lines() *LineIndex

Lines returns the cached line index for this file, building it on first use. Col is a byte column (1-based). LSP requires UTF-16 code-unit columns; that conversion is an LSP-layer concern (Plan 06), not the source package.

func (*SourceFile) Name

func (sf *SourceFile) Name() string

Name returns the file name.

func (*SourceFile) Text

func (sf *SourceFile) Text(sp Span) string

Text returns the substring covered by the span. Spans are taken from one cached copy of the content, so a span costs no allocation of its own.

type Span

type Span struct {
	Offset int
	Len    int
}

Span is a byte range within a SourceFile: [Offset, Offset+Len).

func (Span) End

func (s Span) End() int

End returns the exclusive end offset.

Jump to

Keyboard shortcuts

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