token

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

nolint:varnamelen

nolint varnamelen

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidQuoteStyle = errors.New("Invalid quote style")

Functions

func DebugString added in v0.9.4

func DebugString(ctx context.Context, value string)

func DebugStringSlice added in v0.9.4

func DebugStringSlice(ctx context.Context, value string) []string

func Escape added in v0.9.4

func Escape(ctx context.Context, input string, quote Quote) string

func EscapeFull added in v0.9.4

func EscapeFull(ctx context.Context, input string, quote Quote, ASCIIonly, graphicOnly bool) string

func EscapeRune added in v0.9.4

func EscapeRune(ctx context.Context, buf []byte, runeValue rune, quote Quote, ASCIIonly, graphicOnly bool) []byte

func Unescape added in v0.9.4

func Unescape(ctx context.Context, input string, quote Quote) (out string, err error)

Types

type Annotation

type Annotation struct {
	Key   string
	Value string
}

func (Annotation) IsDottie

func (a Annotation) IsDottie() bool

func (Annotation) String

func (a Annotation) String() string

type Option

type Option func(*Token)

func WithAnnotation

func WithAnnotation(key, value string) Option

func WithLineNumber

func WithLineNumber(in uint) Option

func WithLiteral

func WithLiteral(in string) Option

func WithLiteralRune

func WithLiteralRune(in rune) Option

func WithOffset

func WithOffset(in int) Option

func WithQuoteType

func WithQuoteType(in Quote) Option

type Quote

type Quote uint
const (
	InvalidQuote Quote = iota
	DoubleQuote
	SingleQuote
	NoQuote
)

func QuoteFromString added in v0.5.0

func QuoteFromString(in string) Quote

func (Quote) Byte added in v0.9.4

func (qt Quote) Byte() byte

func (Quote) Is

func (qt Quote) Is(in rune) bool

func (Quote) MarshalJSON added in v0.8.0

func (qt Quote) MarshalJSON() ([]byte, error)

func (Quote) Name added in v0.9.4

func (qt Quote) Name() string

func (Quote) Rune

func (qt Quote) Rune() rune

func (Quote) String

func (qt Quote) String() string

String returns the string corresponding to the token.

func (Quote) Valid added in v0.5.0

func (qt Quote) Valid() bool

type Token

type Token struct {
	Type       Type
	Literal    string
	Offset     int
	Length     int
	LineNumber uint
	Commented  bool
	Quote      Quote
	Annotation *Annotation
}

func New

func New(t Type, options ...Option) Token

type Type

type Type uint

Type is the set of lexical tokens.

const (
	Illegal Type = iota
	EOF

	GroupBanner       // # -- ### (3 or more hashtags)
	Comment           // # -- # <anything>
	CommentAnnotation // # -- # @<name> <value>
	Assign            // = -- KEY=VALUE

	Identifier // Name of the variable
	Value      // Value is an interpreted value of the variable, if it contains special characters, they will be escaped
	RawValue   // RawValue is used as-is. Special characters are not escaped.
	Space      // All whitespace symbols except \n (new line)
	NewLine    // A new line symbol (\n)
)

The list of tokens.

func (Type) String

func (t Type) String() string

String returns the string corresponding to the token.

Jump to

Keyboard shortcuts

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