lexer

package
v0.0.0-...-402e600 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2017 License: GPL-3.0 Imports: 4 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// LowestPrecedence is the lowest precedence
	LowestPrecedence = 0
	// UnaryPrecedence is the precedence of unary operators
	UnaryPrecedence = 6
	// HighestPrecedence is the highest precedence
	HighestPrecedence = 7
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Line    int
	Column  int
	Message string
}

Error describes an error during the lexing

func (*Error) Error

func (e *Error) Error() string

type Lexer

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

func NewLexer

func NewLexer(source []byte) *Lexer

NewLexer creates a new lexer

func (*Lexer) Lex

func (l *Lexer) Lex() ([]Token, error)

Lex runs the lexer across the source and returns a slice of tokens or an error

type Token

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

Token is a token

func NewToken

func NewToken(typ TokenType, value string, line, column int) Token

NewToken is a convenice method for making new tokens for testing etc.

func (Token) Column

func (t Token) Column() int

Column returns the column number of the token

func (Token) IsKeyword

func (t Token) IsKeyword() bool

IsKeyword returns true if token is a keyword

func (Token) IsLiteral

func (t Token) IsLiteral() bool

IsLiteral returns true if token is a literal

func (Token) IsOperator

func (t Token) IsOperator() bool

IsOperator returns true if token is a operator

func (Token) Line

func (t Token) Line() int

Line returns the line number of the token

func (Token) Precedence

func (t Token) Precedence() int

Precedence returns the operators precedence

func (Token) String

func (t Token) String() string

func (Token) Type

func (t Token) Type() TokenType

Type returns the type of the token

func (Token) Value

func (t Token) Value() string

Value returns the value of the token

type TokenType

type TokenType int

TokenType is the type of a token

const (
	// Special
	ILLEGAL TokenType = iota
	EOF
	COMMENT

	IDENT
	INT
	FLOAT
	CHAR
	STRING

	ADD
	SUB
	MUL
	QUO
	REM
	AND
	OR
	XOR
	SHL
	SHR
	AND_NOT
	ADD_ASSIGN
	SUB_ASSIGN
	MUL_ASSIGN
	QUO_ASSIGN
	REM_ASSIGN
	AND_ASSIGN
	OR_ASSIGN
	XOR_ASSIGN
	SHL_ASSIGN
	SHR_ASSIGN
	AND_NOT_ASSIGN
	LAND
	LOR
	ARROW
	INC
	DEC
	EQL
	LSS
	GTR
	ASSIGN
	NOT
	NEQ
	LEQ
	GEQ
	DEFINE
	ELLIPSIS
	LPAREN
	LBRACK
	LBRACE
	COMMA
	PERIOD
	RPAREN
	RBRACK
	RBRACE
	SEMICOLON
	COLON
	DOUBLE_COLON

	BREAK
	CASE
	CONST
	CONTINUE
	DEFAULT
	DEFER
	ELSE
	FALLTHROUGH
	FOR
	FUNC
	PROC
	IF
	IMPORT
	RETURN
	SELECT
	STRUCT
	SWITCH
	TYPE
	VAR
)

TokenType constants

func Lookup

func Lookup(ident string) TokenType

Lookup returns the keyword token if the string is a keyword

func (TokenType) String

func (t TokenType) String() string

Jump to

Keyboard shortcuts

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