lexing

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	// Type is the type of the lexical item
	Type ItemType
	// Value is the string value of the token
	Value string
	// Message is an optional string for the token
	Message string
	Range   Range
}

func (Item) DebugString

func (item Item) DebugString() string

func (Item) IsKeyword

func (item Item) IsKeyword() bool

func (Item) String

func (item Item) String() string

type ItemType

type ItemType int
const (
	// Meta
	ItemStartOfInput ItemType = iota
	ItemEndOfInput
	ItemError

	// Operators
	ItemAddition
	ItemAdditionAssign
	ItemSubtraction
	ItemSubtractionAssign
	ItemMultiplication
	ItemMultiplicationAssign
	ItemDivision
	ItemDivisionAssign
	ItemAssignment
	ItemLooseAssignment
	ItemEquals
	ItemNot
	ItemNotEqual
	ItemLessThan
	ItemLessThanOrEqual
	ItemGreaterThan
	ItemGreaterThanOrEqual
	ItemAnd
	ItemOr
	ItemSpread
	ItemIncrement
	ItemDecrement
	ItemModulo
	ItemModuloAssign

	// Punctuation
	ItemLeftParentheses
	ItemRightParentheses
	ItemLeftBracket
	ItemRightBracket
	ItemLeftCurly
	ItemRightCurly
	ItemColon
	ItemColonColon
	ItemComma
	ItemDot
	ItemSubstitutionStart
	ItemSubstitutionEnd
	ItemDoubleQuote
	ItemBacktick

	// Keywords
	ItemKeywordPackage
	ItemKeywordImport
	ItemKeywordFunc
	ItemKeywordRule
	ItemKeywordExport
	ItemKeywordIf
	ItemKeywordFor
	ItemKeywordIn
	ItemKeywordElse
	ItemKeywordReturn
	ItemKeywordLet
	ItemKeywordShell
	ItemKeywordAlias
	ItemKeywordBreak

	// Identifiers
	ItemIdentifier

	// Whitespace
	ItemNewline
	ItemWhitespace

	// Strings etc.
	ItemStringPart

	// Numbers
	ItemInteger

	// Boleans
	ItemBoolean

	// Comments
	ItemComment
)

func (ItemType) String

func (i ItemType) String() string

type LexMode

type LexMode int
const (
	ModeRoot LexMode = iota
	ModeEvaluatedString
	ModeShellString
	ModeMultilineShellString
)

type Lexer

type Lexer struct {
	Mode LexMode
	// contains filtered or unexported fields
}

func Lex

func Lex(input string) *Lexer

func (*Lexer) AllItems

func (lexer *Lexer) AllItems() []Item

func (*Lexer) Backtrack

func (lexer *Lexer) Backtrack()

func (*Lexer) BacktrackCount

func (lexer *Lexer) BacktrackCount(count int)

func (*Lexer) Emit

func (lexer *Lexer) Emit(itemType ItemType)

func (*Lexer) EmitWithMessage

func (lexer *Lexer) EmitWithMessage(itemType ItemType, message string)

func (*Lexer) Ignore

func (lexer *Lexer) Ignore()

func (*Lexer) Next

func (lexer *Lexer) Next() rune

func (*Lexer) NextItem

func (lexer *Lexer) NextItem() Item

func (*Lexer) NextNonWhitespaceItem

func (lexer *Lexer) NextNonWhitespaceItem(includeNewline bool) Item

func (*Lexer) NextString

func (lexer *Lexer) NextString(text string) bool

func (*Lexer) Peek

func (lexer *Lexer) Peek() rune

type Position

type Position struct {
	// Line is the zero-based line number
	Line int
	// Character is the zero-based unicode character index
	Character int
	// Offset is the offset from the start of the text, in bytes
	Offset int
}

Position describes a position in a text

type Range

type Range struct {
	// Start is the inclusive start of the range
	Start Position
	// End is the inclusive end of the range
	End Position
}

Range describes a range of a text

func (Range) String

func (r Range) String() string

Jump to

Keyboard shortcuts

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