file

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 3 Imported by: 285

Documentation

Overview

Package file encapsulates the file abstractions used by the ast & parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File represents a file to parse.

func NewFile

func NewFile(filename, src string, base int) *File

NewFile returns a new file with the given filename, src and base.

func (*File) Base

func (fl *File) Base() int

Base returns the base of fl.

func (*File) Name

func (fl *File) Name() string

Name returns the name of fl.

func (*File) Position

func (fl *File) Position(idx Idx) *Position

Position returns the position at idx or nil if not valid.

func (*File) Source

func (fl *File) Source() string

Source returns the source of fl.

func (*File) WithSourceMap

func (fl *File) WithSourceMap(sm *sourcemap.Consumer) *File

WithSourceMap sets the source map of fl.

type FileSet

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

A FileSet represents a set of source files.

func (*FileSet) AddFile

func (fs *FileSet) AddFile(filename, src string) int

AddFile adds a new file with the given filename and src.

This an internal method, but exported for cross-package use.

func (*FileSet) File

func (fs *FileSet) File(idx Idx) *File

File returns the File at idx or nil if not found.

func (*FileSet) Position

func (fs *FileSet) Position(idx Idx) *Position

Position converts an Idx in the FileSet into a Position.

type Idx

type Idx int

Idx is a compact encoding of a source position within a file set. It can be converted into a Position for a more convenient, but much larger, representation.

type Position

type Position struct {
	Filename string // The filename where the error occurred, if any
	Offset   int    // The src offset
	Line     int    // The line number, starting at 1
	Column   int    // The column number, starting at 1 (The character count)
}

Position describes an arbitrary source position including the filename, line, and column location.

func (*Position) String

func (p *Position) String() string

String returns a string in one of several forms:

file:line:column    A valid position with filename
line:column         A valid position without filename
file                An invalid position with filename
-                   An invalid position without filename

Jump to

Keyboard shortcuts

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