util

package
v0.0.0-...-6725145 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesSource

func BytesSource(content []byte) api.Source

func CalcLocation

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

func CalcLocationRange

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

func Describe

func Describe(n api.Node) (name string, children []api.Node)

func EmptySource

func EmptySource() api.Source

func Expose

func Expose[T any](expose func(T) string, items ...T) string

func ExposeConfig

func ExposeConfig(cfg api.Config) string

func ExposeList

func ExposeList[T any](expose func(T) string, items []T, sep string) string

ExposeList returns a string representation of a list of items

this function is guaranteed to return a string with a left-most '[' and a right-most ']' and a possibly empty string between them

func ExposeNode

func ExposeNode(node api.Node) string

ExposeNode returns a string representation of the node's exposed data

Example:

"Node{line: 1, column: 1, name: foo, children: [Node{line: 1, column: 5, name: bar, children: []}]}"

func ExposeNodeSurface

func ExposeNodeSurface(node api.Node) string

ExposeNodeSurface returns a string representation of the node's exposed top level data (no children)

If the node has children, the children will be represented as "[...]"; otherwise, they will be represented as "[]"

Example:

"Node{line: 1, column: 1, name: foo, children: [...]}"

func ExposeParser

func ExposeParser(p api.Parser) string

func ExposeScanner

func ExposeScanner(scanner api.Scanner) string

func ExposeSource

func ExposeSource(source api.Source) string

func ExposeToken

func ExposeToken(token api.Token) string

ExposeToken returns a string representation of the token's exposed data

func ExposeTranslator

func ExposeTranslator[From, To any](translator api.Translator[From, To]) string

func FileSource

func FileSource(path string) (api.Source, error)

func FreeSource

func FreeSource(path, content string) api.Source

func Get

func Get[Option any](cfg api.Config, key string) (option Option, found bool)

func InitParser

func InitParser[T api.Parser](s api.Scanner) (out T)

func PointedWindow

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

func PrintTree

func PrintTree(w io.Writer, n api.Node)

func Reclassify

func Reclassify[T api.Node](nodes []T) []api.Node

func StringSource

func StringSource(content string) api.Source

func Tokenize

func Tokenize(scanner api.Scanner, buf []api.Token) (_ []api.Token, errorToken *api.Token)

Tokenize scans all tokens from the scanner (from its current input position) and returns them in a slice.

If an error occurs during scanning, the function will return whatever tokens were scanned up to that point with a non-nil value for 'errorToken'.

func TranslateRemaining

func TranslateRemaining[From, To any](dest []To, translator api.Translator[From, To]) []To

dest may be nil, in which case a new slice will be allocated

NOTE: if translator returns true on `translator.Done()`, this function will loop infinitely

  • this can be prevented by implementing the following method: `UpperBound() int`
  • an example of how this could be implemented in a reasonable way is shown in `api/examples/translator.go`
  • if `UpperBound()` returns a negative value, the number of translations will be treated as unbounded

func Window

func Window(source api.SourceCode, 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
3 | spec Functor f where
4 |   map : (a -> b) -> f a -> f b
5 |   (<$) : a -> f b -> f a

mySrc.Window(x, y), where x is somewhere on line 3, and y is somewhere of line 4
3 | spec Functor f where
4 |   map : (a -> b) -> f a -> f b

Types

This section is empty.

Directories

Path Synopsis
fun

Jump to

Keyboard shortcuts

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