lexer

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const EOFRUNE = -1

Variables

This section is empty.

Functions

This section is empty.

Types

type Lexeme

type Lexeme struct {
	Kind     TokenType          // The type of this lexeme.
	Position input.BytePosition // The starting position of this token in the input string.
	Value    string             // The textual value of this token.
	Error    string             // The error associated with the lexeme, if any.
}

Lexeme represents a token returned from scanning the contents of a file.

type Lexer

type Lexer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Lexer holds the state of the scanner.

func Lex

func Lex(source input.Source, input string) *Lexer

Lex creates a new scanner for the input string.

func (*Lexer) Close added in v1.1.0

func (l *Lexer) Close()

Close stops the lexer from running.

type PeekableLexer

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

PeekableLexer wraps a lexer and provides the ability to peek forward without losing state.

func NewPeekableLexer

func NewPeekableLexer(lex *Lexer) *PeekableLexer

NewPeekableLexer returns a new PeekableLexer for the given lexer.

func (*PeekableLexer) Close added in v1.1.0

func (l *PeekableLexer) Close()

Close stops the lexer from running.

func (*PeekableLexer) NextToken

func (l *PeekableLexer) NextToken() Lexeme

NextToken returns the next token found in the lexer.

func (*PeekableLexer) PeekToken

func (l *PeekableLexer) PeekToken(count int) Lexeme

PeekToken performs lookahead of the given count on the token stream.

type TokenType

type TokenType int

TokenType identifies the type of lexer lexemes.

const (
	TokenTypeError TokenType = iota // error occurred; value is text of error

	// Synthetic semicolon
	TokenTypeSyntheticSemicolon

	TokenTypeEOF
	TokenTypeWhitespace
	TokenTypeSinglelineComment
	TokenTypeMultilineComment
	TokenTypeNewline

	TokenTypeKeyword    // interface
	TokenTypeIdentifier // helloworld
	TokenTypeNumber     // 123

	TokenTypeLeftBrace  // {
	TokenTypeRightBrace // }
	TokenTypeLeftParen  // (
	TokenTypeRightParen // )

	TokenTypePipe  // |
	TokenTypePlus  // +
	TokenTypeMinus // -
	TokenTypeAnd   // &
	TokenTypeDiv   // /

	TokenTypeEquals     // =
	TokenTypeColon      // :
	TokenTypeSemicolon  // ;
	TokenTypeRightArrow // ->
	TokenTypeHash       // #
	TokenTypeEllipsis   // ...
	TokenTypeStar       // *
)

func (TokenType) String

func (i TokenType) String() string

Jump to

Keyboard shortcuts

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