sourcemap

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sourcemap provides a simplified sourcemap for data-files. Its primary use is to map keypaths to the correct linenumber / offsets within the data-file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiffOfObjects

func DiffOfObjects(a, b interface{}) (diff.Changelog, error)

DiffOfObjects returns a changelog with options set for use with for instance i18n-json.

func IsValueLike

func IsValueLike(t chroma.Token) bool

func JsonKeys

func JsonKeys(tokens []Token) map[string]SpanToken

JsonKeys creates a map of all the key-paths within a json-file pointing to the line-number/offset of the json-file This is mostly used to be able to use git blame on the file on the client-side to get a timestamp for the change, to make it easier to autoresolve change-conflicts. Asumptions for the input-file: - Valid Json - Each json-value is on a single line. I don't think JSON supports values spanning multiple lines

func MapToSource

func MapToSource(contentType string, content string) (map[string]SpanToken, error)

func MapToSourceFromTokens

func MapToSourceFromTokens(contentType string, tokens []Token) (map[string]SpanToken, error)

func SourceMapperSupports

func SourceMapperSupports(contentType string) bool

Types

type JsonPath

type JsonPath struct {
	Queue string
	// contains filtered or unexported fields
}

func NewJsonPath

func NewJsonPath() JsonPath

func (*JsonPath) Add

func (jp *JsonPath) Add(s string)

func (*JsonPath) AddArrayElement

func (jp *JsonPath) AddArrayElement()

func (*JsonPath) IsWithinArray

func (jp *JsonPath) IsWithinArray() (int, bool)

func (*JsonPath) SetQueue

func (jp *JsonPath) SetQueue(s string)

func (*JsonPath) String

func (jp *JsonPath) String() string

type Offset

type Offset struct {
	Offset int
	Line   int
}

type SpanToken

type SpanToken struct {
	Path *[]string `json:"path,omitempty"`
	// not ready for use yet
	End   *Offset `json:"-"`
	Token `json:"token"`
}

type Token

type Token struct {
	chroma.Token
	Start Offset
	End   Offset
}

func (Token) String

func (t Token) String() string

type Tokenizer

type Tokenizer struct {
	FilePath string
	Lexer    chroma.Config
	// contains filtered or unexported fields
}

func NewTokenizer

func NewTokenizer(filepath string, content string) (Tokenizer, error)

func (Tokenizer) Concat

func (t Tokenizer) Concat() string

func (Tokenizer) IsChanged

func (t Tokenizer) IsChanged() bool

func (*Tokenizer) SetTokens

func (t *Tokenizer) SetTokens(tokens []chroma.Token)

func (Tokenizer) Tokens

func (t Tokenizer) Tokens() []chroma.Token

func (*Tokenizer) TokensWithOffsets

func (t *Tokenizer) TokensWithOffsets(consumer func(token Token) bool)

Returns offsets for each token

Jump to

Keyboard shortcuts

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