package source
import "github.com/azin-lang/Azin/internal/source"
Package source handles the reading, slicing, and positional indexing of source files.
Index
-
type File
- func New(name string, text []byte) *File
- func (f *File) Base() string
- func (f *File) Byte(offset uint32) byte
- func (f *File) Dir() string
- func (f *File) EOF(offset uint32) bool
- func (f *File) Empty() bool
- func (f *File) Ext() string
- func (f *File) FormatToken(tok token.Token) string
- func (f *File) Len() uint32
- func (f *File) Line(line uint32) []byte
- func (f *File) LineColumn(offset uint32) (line, column uint32)
- func (f *File) LineCount() uint32
- func (f *File) LineStart(line uint32) (uint32, bool)
- func (f *File) LineText(offset uint32) []byte
- func (f *File) Name() string
- func (f *File) Slice(start, end uint32) []byte
- func (f *File) Text(tok token.Token) []byte
Types
type File
type File struct { // contains filtered or unexported fields }
File holds the contents and line structure of a parsed source file.
func New
func New(name string, text []byte) *File
New returns a new File, parsing line offsets from the provided text.
func (*File) Base
func (f *File) Base() string
Base returns the base file name.
func (*File) Byte
func (f *File) Byte(offset uint32) byte
Byte returns the character at the given offset.
func (*File) Dir
func (f *File) Dir() string
Dir returns the directory portion of the file path.
func (*File) EOF
func (f *File) EOF(offset uint32) bool
EOF reports whether the offset is at or beyond the end of the file.
func (*File) Empty
func (f *File) Empty() bool
Empty reports whether the file contains no text.
func (*File) Ext
func (f *File) Ext() string
Ext returns the file extension.
func (*File) FormatToken
func (f *File) FormatToken(tok token.Token) string
FormatToken returns a string representation of a token, including its location and text.
func (*File) Len
func (f *File) Len() uint32
Len returns the size of the file in bytes.
func (*File) Line
func (f *File) Line(line uint32) []byte
Line returns the byte slice for a 1-based line, excluding trailing newlines.
func (*File) LineColumn
func (f *File) LineColumn(offset uint32) (line, column uint32)
LineColumn returns the 1-based line and column numbers for the offset.
func (*File) LineCount
func (f *File) LineCount() uint32
LineCount returns the total number of lines in the file.
func (*File) LineStart
func (f *File) LineStart(line uint32) (uint32, bool)
LineStart returns the byte offset for the beginning of a 1-based line.
func (*File) LineText
func (f *File) LineText(offset uint32) []byte
LineText returns the full text of the line containing the given offset.
func (*File) Name
func (f *File) Name() string
Name returns the file path.
func (*File) Slice
func (f *File) Slice(start, end uint32) []byte
Slice returns the byte slice between start and end offsets.
func (*File) Text
func (f *File) Text(tok token.Token) []byte
Text returns the exact byte slice for a given token.