util

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ShowTimeTrack = false

ShowTimeTrack controls if TimeTrack should be logged

Functions

func CanonicaliseURI

func CanonicaliseURI(parent string, child string) string

CanonicaliseURI canonicalises a child URI by shorten it assuming that it is prefixed with parent, otherwise the original URI is returned

func DecodeURIFromQuery

func DecodeURIFromQuery(uri string) (string, error)

func FirstToken

func FirstToken(node phrase.AstNode) *lexer.Token

FirstToken returns the first terminal node (leave)

func GetURIID

func GetURIID(uri string) string

GetURIID shortens the URI but still readable

func HandleError

func HandleError(err error)

func IsOfPhraseType

func IsOfPhraseType(node phrase.AstNode, phraseType phrase.PhraseType) (*phrase.Phrase, bool)

IsOfPhraseType checks if a node is the given type

func IsOfPhraseTypes

func IsOfPhraseTypes(node phrase.AstNode, phraseTypes []phrase.PhraseType) (*phrase.Phrase, bool)

IsOfPhraseTypes checks if a node is one of the given types

func IsURINavigatable

func IsURINavigatable(uri string) bool

IsURINavigatable checks if the given URI is navigatable

func LastToken

func LastToken(node phrase.AstNode) *lexer.Token

LastToken returns the last terminal node (leave)

func PathToURI

func PathToURI(path string) string

PathToURI converts file path to URI

func PrintMemUsage

func PrintMemUsage()

PrintMemUsage outputs the current, total and OS memory being used. As well as the number of garage collection cycles completed.

func RunesToUTF8

func RunesToUTF8(rs []rune) []byte

RunesToUTF8 converts []rune to []byte without converting to string first

func SetFromArray added in v0.0.2

func SetFromArray[V comparable](arr []V) mapset.Set[V]

func TimeTrack

func TimeTrack(start time.Time, name string)

TimeTrack tracks the time Example: `defer util.TimeTrack(time.Now(), "An example")`

func URIFromCanonicalURI

func URIFromCanonicalURI(parent string, canonicalURI string) string

URIFromCanonicalURI converts canonical URI back to full URI, if the canonical URI is a full URI which is prefixed with parent then it is returned

func URIToPath

func URIToPath(uri string) (string, error)

URIToPath convert URI to file path

Types

type NodeStack

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

NodeStack contains the token and its parents

func (*NodeStack) Parent

func (s *NodeStack) Parent() phrase.Phrase

Parent returns the parent and mutate the stack

func (*NodeStack) Phrase

func (s *NodeStack) Phrase() phrase.Phrase

Phrase returns the phrase of the stack

func (*NodeStack) Pop

func (s *NodeStack) Pop() *phrase.Phrase

Pop pops the node from the stack or nil if stack is empty

func (*NodeStack) Push

func (s *NodeStack) Push(node *phrase.Phrase)

Push adds the node to the stack

func (*NodeStack) SetParents

func (s *NodeStack) SetParents(parents []*phrase.Phrase) *NodeStack

SetParents sets the parents of the stack

func (*NodeStack) SetToken

func (s *NodeStack) SetToken(token *lexer.Token) *NodeStack

SetToken sets the token to the stack

func (NodeStack) String

func (s NodeStack) String() string

String returns the string representation of a NodeStack

func (NodeStack) Token

func (s NodeStack) Token() lexer.Token

Token returns the token of the stack

type Traverser

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

func NewTraverser

func NewTraverser(node *phrase.Phrase) *Traverser

func (*Traverser) Advance

func (s *Traverser) Advance() phrase.AstNode

func (*Traverser) Ascend

func (s *Traverser) Ascend() (*Traverser, error)

func (*Traverser) Clone

func (s *Traverser) Clone() *Traverser

func (*Traverser) Descend

func (s *Traverser) Descend() (*Traverser, error)

func (*Traverser) Peek

func (s *Traverser) Peek() phrase.AstNode

func (*Traverser) SkipToken

func (s *Traverser) SkipToken(tokenType lexer.TokenType)

func (*Traverser) Traverse

func (s *Traverser) Traverse(visit Visitor)

type Visitor

type Visitor func(phrase.AstNode, []*phrase.Phrase) VisitorContext

type VisitorContext

type VisitorContext struct {
	ShouldAscend bool
	AscendNode   phrase.AstNode
}

Jump to

Keyboard shortcuts

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