source

package module
v0.0.0-...-ca9eab0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: MIT Imports: 3 Imported by: 4

Documentation

Overview

================================================================================================= Alex Peters - January 18, 2024

Path specifier interface for either a file system path or stdin

This is useful since the relevant information when the input is stdin is likely just that the source of input is the standard input rather than its file system path. =================================================================================================

================================================================================================= Alex Peters - January 29, 2024 =================================================================================================

Index

Constants

This section is empty.

Variables

View Source
var StdinSpec = StandardInput{}

Functions

func AssertStringInput

func AssertStringInput(p PathSpec) (si stringInput, ok bool)

func NamedStringInput

func NamedStringInput(s string, name string) stringInput

func StringInput

func StringInput(s string) stringInput

Types

type FilePath

type FilePath string

file system path

func (FilePath) Path

func (fp FilePath) Path() string

returns path to file exactly as it is written

type PathSpec

type PathSpec interface {
	Path() string
}

type SourceCode

type SourceCode struct {
	Path PathSpec
	// source file as an array of strings for each non-empty line, does not include newline chars
	Source []byte
	// records end (exclusive) position for all lines n at index n-1.
	//
	// for example, given
	//	PositionRanges = []int{10, 23, 56}
	// line one ends at position 10, line two ends at position 23, and line three ends at position 56
	PositionRanges []int
}

func (SourceCode) CalcLocation

func (source SourceCode) CalcLocation(pos int, isEndPos bool) (line, char int)

calculates line and char number given a source code position

first return value is line number, second is char

func (SourceCode) CalcLocationRange

func (source SourceCode) CalcLocationRange(start, end int) (line1, line2, char1, char2 int)

calculates a location range given a `start` and `end` position

first two return values are start line number and end line number respectively. Last two return values are start and end char number respectively

func (SourceCode) PointedWindow

func (source SourceCode) PointedWindow(start, end int) string

func (SourceCode) Window

func (source SourceCode) Window(start, end int) string

returns a window for the source code according to the start to the end position.

example:

1 | -- original the source code
2 | module example where
3 |   trait Functor f where
4 |     map : (a -> b) -> f a -> f b
5 |     _<$_ : a -> f b -> f a
6 |   end
7 | end
mySrc.Window(x, y) // where x is somewhere on line 3, and y is somewhere of line 4
3 |   trait Functor f where
4 |     map : (a -> b) -> f a -> f b

type StandardInput

type StandardInput struct{}

standard input

func (StandardInput) Path

func (si StandardInput) Path() string

returns "stdin"

Jump to

Keyboard shortcuts

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