lexing

package
v0.0.0-...-e57836d Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LEXER_ERROR_UNEXPECTED_EOF                    string = "Unexpected end of file"
	LEXER_ERROR_UNEXPECTED_RUNE                   string = "Unexpected character"
	LEXER_ERROR_UNEXPECTED_NEWLINE                string = "Unexpected newline"
	LEXER_ERROR_MISSING_RIGHT_BRACE               string = "Missing closing section brace"
	LEXER_ERROR_MISSING_NEWLINE_BEFORE_LEFT_BRACE string = "Missing newline before start of section"
	LEXER_ERROR_MISSING_NEWLINE_BEFORE_EOF        string = "Missing newline before end of file"
	LEXER_ERROR_MISSING_RIGHT_PARENTHESIS         string = "Missing closing parenthesis"
	LEXER_ERROR_START_OF_TOKEN_AFTER_EOF          string = "Start of current token is after EOF"
	LEXER_ERROR_POSITION_AFTER_EOF                string = "Lexer position is after EOF"
	LEXER_ERROR_NIL_LEXING_FUNCTION               string = "Cannot call nil lexing function"
)
View Source
const (
	RUNE_EOF               rune = 0
	RUNE_ERROR             rune = utf8.RuneError
	RUNE_LEFT_PARENTHESIS  rune = '('
	RUNE_RIGHT_PARENTHESIS rune = ')'
	RUNE_LEFT_BRACKET      rune = '['
	RUNE_RIGHT_BRACKET     rune = ']'
	RUNE_LEFT_BRACE        rune = '{'
	RUNE_RIGHT_BRACE       rune = '}'
	RUNE_COLUMN            rune = ':'
	RUNE_NEWLINE           rune = '\n'
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Lexer

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

func NewLexer

func NewLexer(input string, lexingFunc LexingFunction) *Lexer

NewLexer creates a new lexer

func (*Lexer) Errorf

func (lexer *Lexer) Errorf(format string, args ...interface{}) LexingFunction

Errorf pushes an error token in the token channel. Errorf is a lexing function.

func (*Lexer) MoveAfterRune

func (lexer *Lexer) MoveAfterRune(nextRune rune)

MoveAfterRune moves position just after next rune

func (*Lexer) NextToken

func (lexer *Lexer) NextToken() Token

NextToken procedes lexing until a token is produced and returns it

func (*Lexer) PeekRune

func (lexer *Lexer) PeekRune() rune

PeekRune returns the next rune in input. Returns EOF if OEF is reached. Returns ERROR if error occured while reading next rune.

func (*Lexer) PushToken

func (lexer *Lexer) PushToken(tokenType TokenType)

PushToken pushes a token into the token channel

func (*Lexer) SkipWhitespace

func (lexer *Lexer) SkipWhitespace()

SkipWhitespace moves position to the next non-whitespaces rune. Non-whitespace runes are all runes for which utf8.IsSpace returns false. If EOF is reached, pushes an EOF

type LexingFunction

type LexingFunction func(*Lexer) LexingFunction

LexingFunction

type Token

type Token struct {
	Type  TokenType
	Value string
	Start TokenPosition
	End   TokenPosition
}

Token

func NewToken

func NewToken() Token

func (Token) String

func (token Token) String() string

String

type TokenPosition

type TokenPosition struct {
	Line   int
	Column int
}

func (*TokenPosition) String

func (tokenPosition *TokenPosition) String() string

type TokenType

type TokenType int
const (
	TOKEN_UNKNOWN TokenType = iota
	TOKEN_ERROR
	TOKEN_EOF
	TOKEN_LEFT_PARENTHESIS
	TOKEN_RIGHT_PARENTHESIS
	TOKEN_LEFT_BRACKET
	TOKEN_RIGHT_BRACKET
	TOKEN_LEFT_BRACE
	TOKEN_RIGHT_BRACE
	TOKEN_COLUMN
	TOKEN_NEWLINE
	TOKEN_PROPERTY_KEY
	TOKEN_PROPERTY_VALUE
	TOKEN_SECTION_NAME
	TOKEN_LYRICS
	TOKEN_CHORD
)

func (*TokenType) String

func (tokenType *TokenType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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