lexer

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEOF = errors.New("end of file")

ErrEOF is returned when the lexer reaches the end of file.

View Source
var ErrUnterminatedString = errors.New("unterminated string literal")

ErrUnterminatedString is returned when an open-quote does not have a matching close.

Functions

This section is empty.

Types

type ErrUnrecognizedToken

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

ErrUnrecognizedToken is returned when a character or sequence of characters cannot be recognized as a valid token.

func (ErrUnrecognizedToken) Error

func (err ErrUnrecognizedToken) Error() string

type Lexer

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

Lexer performs lexical analysis of LISP.

func New

func New(src string) *Lexer

New initializes the lexer with the given source. Source can contain any UTF-8 characters.

func (*Lexer) Next

func (lex *Lexer) Next() (*Token, error)

Next consumes characters from source until the next token is found and returns the token. If no token is identified till the end of source, ErrEOF will be returned.

func (*Lexer) Tokens

func (lex *Lexer) Tokens() ([]Token, error)

Tokens runs through the entire source and returns tokens.

type Token

type Token struct {
	Type  TokenType
	Start int
	Value string
}

Token represents an extracted token from the stream

func (Token) String

func (token Token) String() string

type TokenType

type TokenType string

TokenType represents the type of the extracted token

const (
	// LPAREN represents the left-parenthesis character
	LPAREN TokenType = "LPAREN"

	// RPAREN represents the right-parenthesis character
	RPAREN TokenType = "RPAREN"

	// LVECT represents the left-brace character
	LVECT TokenType = "LVECT"

	// RVECT represents the right-brace character
	RVECT TokenType = "RVECT"

	// LDICT represents the left curly brace
	LDICT TokenType = "LDICT"

	// KEYWORD represents a keyword
	KEYWORD TokenType = "KEYWORD"

	// RDICT represents the right curly brace
	RDICT TokenType = "RDICT"

	// STRING represents a double-quoted string
	STRING TokenType = "STRING"

	// NUMBER represents int, float, hex, complex etc.
	NUMBER TokenType = "NUMBER"

	// WHITESPACE represents a space, tab or newline
	WHITESPACE TokenType = "WHITESPACE"

	// NEWLINE represents a new-line or return-line-feed character.
	NEWLINE TokenType = "NEWLINE"

	// COMMENT represents a ";" based comment
	COMMENT TokenType = "COMMENT"

	// SYMBOL represents any identifier
	SYMBOL TokenType = "SYMBOL"

	// QUOTE represents the single quote
	QUOTE TokenType = "QUOTE"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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