src

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: BSD-3-Clause Imports: 4 Imported by: 1

Documentation

Overview

Package src provides types for working with source files.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Position

type Position struct {
	Filename string
	Line     int // 1-up
}

Position represents a position in a source file.

func FramePosition

func FramePosition(f runtime.Frame) Position

FramePosition returns the Position of the given stack frame.

func (Position) IsValid

func (p Position) IsValid() bool

IsValid reports whether the position is valid: Line must be positive, but Filename may be empty.

Example
package main

import (
	"fmt"

	"github.com/mmcloughlin/avo/src"
)

func main() {
	fmt.Println(src.Position{"a.go", 42}.IsValid())
	fmt.Println(src.Position{"", 42}.IsValid())
	fmt.Println(src.Position{"a.go", -1}.IsValid())
}
Output:

true
true
false

func (Position) Rel

func (p Position) Rel(basepath string) Position

Rel returns Position relative to basepath. If the given filename cannot be expressed relative to basepath the position will be returned unchanged.

func (Position) Relwd

func (p Position) Relwd() Position

Relwd returns Position relative to the current working directory. Returns p unchanged if the working directory cannot be determined, or the filename cannot be expressed relative to the working directory.

func (Position) String

func (p Position) String() string

String represents Position as a string.

Example
package main

import (
	"fmt"

	"github.com/mmcloughlin/avo/src"
)

func main() {
	fmt.Println(src.Position{"a.go", 42})
	fmt.Println(src.Position{"", 42})
	fmt.Println(src.Position{"a.go", -1}) // invalid
}
Output:

a.go:42
42
-

Jump to

Keyboard shortcuts

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