span

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// used to unify `\r`, `\r\n` to `\n`, despite other line-terminators in unicode
	EOL = rune('\n')
	EOF = rune(-1)
)

Variables

This section is empty.

Functions

func IsLineTerminator

func IsLineTerminator(c rune) bool

Types

type Pos

type Pos struct {
	Line uint32
	Col  uint32
}

type Range

type Range struct {
	Lo uint32
	Hi uint32
}

func (Range) Before added in v0.0.10

func (r Range) Before(rng Range) bool

func (Range) Empty added in v0.0.10

func (r Range) Empty() bool

func (Range) Valid added in v0.0.10

func (r Range) Valid() bool

type Runes

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

type Source

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

process the utf8 encoded source file

the return value of below methods which return rune will be `utf8.RuneError` if the given position is not well encoded in utf8

`\r`, `\r\n` will be unified to `\n` which has an alias `span.EOL`

func NewSource

func NewSource(path string, code string) *Source

func (*Source) AdvanceIf

func (s *Source) AdvanceIf(c rune) bool

func (*Source) Ahead2nd

func (s *Source) Ahead2nd() rune

func (*Source) AheadIsCh

func (s *Source) AheadIsCh(c rune) bool

func (*Source) AheadIsChOr

func (s *Source) AheadIsChOr(c1 rune, c2 rune) bool

func (*Source) AheadIsChs2

func (s *Source) AheadIsChs2(c1 rune, c2 rune) bool

func (*Source) AheadIsEOF

func (s *Source) AheadIsEOF() bool

func (*Source) DiscardState

func (s *Source) DiscardState()

pop the state-stack and discard the popped state

func (*Source) Len added in v0.0.11

func (s *Source) Len() int

func (*Source) LineCol added in v0.0.10

func (s *Source) LineCol(rng Range) (from, to Pos)

line-column is useful for developer can figure out where the errors occur, however it will pressure memory footprint if we directly store them in Node, this method is inspired by `acorn` to defer restore the line-column by the given source range

refer: https://github.com/acornjs/acorn/blob/ee1ce3766fe484926b84f29182f140d21e25fc6f/acorn/src/locutil.js#L31

func (*Source) MetLineTerm

func (s *Source) MetLineTerm() bool

func (*Source) NewOpenRange

func (s *Source) NewOpenRange() Range

func (*Source) Ofst

func (s *Source) Ofst() uint32

ofst base on byte

func (*Source) OfstLineCol added in v0.0.10

func (s *Source) OfstLineCol(ofst uint32) (pos Pos)

func (*Source) OpenRange

func (s *Source) OpenRange(rng *Range)

func (*Source) Peek

func (s *Source) Peek() rune

func (*Source) PopState

func (s *Source) PopState()

pop the state-stack and apply the popped state

func (*Source) Pos

func (s *Source) Pos() uint32

pos base on rune

func (*Source) PushState

func (s *Source) PushState()

push current state into the state-stack

func (*Source) Read

func (s *Source) Read() rune

read rune as well as join the CR/LF to record the line/column info

func (*Source) RngText added in v0.0.10

func (s *Source) RngText(rng Range) string

func (*Source) SkipSpace

func (s *Source) SkipSpace() *Source

func (*Source) Text

func (s *Source) Text(start, end uint32) string

return the string in the span `[start,end)`

type SourceState

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

Jump to

Keyboard shortcuts

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