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.
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.
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) 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.