scanner

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checkpoint

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

type Error

type Error struct {
	Message string
	Start   ast.Idx
	End     ast.Idx
}

func (Error) Error

func (d Error) Error() string

type Scanner

type Scanner struct {
	Token Token

	EscapedStr string // escape-processed string for current token
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(src string, errors *error) Scanner

func (*Scanner) AdvanceIfByteEquals

func (s *Scanner) AdvanceIfByteEquals(b byte) bool

func (*Scanner) Checkpoint

func (s *Scanner) Checkpoint() Checkpoint

func (*Scanner) ConsumeByte

func (s *Scanner) ConsumeByte() byte

func (*Scanner) ConsumeRune

func (s *Scanner) ConsumeRune() rune

func (*Scanner) Next

func (s *Scanner) Next()

func (*Scanner) NextByte

func (s *Scanner) NextByte() (byte, bool)

func (*Scanner) NextRune

func (s *Scanner) NextRune() (rune, bool)

func (*Scanner) NextTemplatePart

func (s *Scanner) NextTemplatePart()

func (*Scanner) Offset

func (s *Scanner) Offset() ast.Idx

func (*Scanner) ParseRegExp

func (s *Scanner) ParseRegExp() (string, string, string)

ParseRegExp re-tokenizes the current `/` or `/=` as a regular expression.

func (*Scanner) PeekByte

func (s *Scanner) PeekByte() (byte, bool)

func (*Scanner) PeekRune

func (s *Scanner) PeekRune() (rune, bool)

func (*Scanner) ReadTemplateLiteral

func (s *Scanner) ReadTemplateLiteral(sub, tail token.Token) token.Token

ReadTemplateLiteral scans the body of a template literal. The opening delimiter (` or }) must already have been consumed by the caller. sub is the Token to return when encountering ${, tail is for closing `.

func (*Scanner) Rewind

func (s *Scanner) Rewind(c Checkpoint)

type Source

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

func NewSource

func NewSource(src string) Source

func (*Source) AdvanceIfByteEquals

func (s *Source) AdvanceIfByteEquals(b byte) (matched bool)

func (*Source) EOF

func (s *Source) EOF() bool

func (*Source) EndOffset

func (s *Source) EndOffset() ast.Idx

func (*Source) FromPositionToCurrent

func (s *Source) FromPositionToCurrent(pos ast.Idx) string

func (*Source) NextByte

func (s *Source) NextByte() (byte, bool)

func (*Source) NextByteUnchecked

func (s *Source) NextByteUnchecked() byte

func (*Source) NextRune

func (s *Source) NextRune() (rune, bool)

func (*Source) Offset

func (s *Source) Offset() ast.Idx

func (*Source) PeekByte

func (s *Source) PeekByte() (byte, bool)

func (*Source) PeekByteUnchecked

func (s *Source) PeekByteUnchecked() byte

func (*Source) PeekRune

func (s *Source) PeekRune() (rune, bool)

func (*Source) PeekTwoBytes

func (s *Source) PeekTwoBytes() ([2]byte, bool)

func (*Source) ReadPosition

func (s *Source) ReadPosition(pos ast.Idx) byte

func (*Source) SetPosition

func (s *Source) SetPosition(pos ast.Idx)

func (*Source) Slice

func (s *Source) Slice(from, to ast.Idx) string

type Token

type Token struct {
	Kind token.Token

	OnNewLine bool
	HasEscape bool

	Idx0, Idx1 ast.Idx // 8 bytes
}

func (Token) Raw

func (t Token) Raw(s Scanner) string

func (Token) String

func (t Token) String(s Scanner) string

func (Token) TemplateLiteral

func (t Token) TemplateLiteral(s Scanner) string

TemplateLiteral returns the raw source text of a template literal element (without the surrounding delimiters).

func (Token) TemplateParsed

func (t Token) TemplateParsed(s Scanner) string

TemplateParsed returns the escape-processed content of a template literal element. If no escapes were present, returns the same as TemplateLiteral.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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