parser

package
v0.0.41 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	FilterTokenOpenParen int = iota
	FilterTokenCloseParen
	FilterTokenWhitespace
	FilterTokenComma
	FilterTokenLogical
	FilterTokenFunc
	FilterTokenFloat
	FilterTokenInteger
	FilterTokenString
	FilterTokenDate
	FilterTokenTime
	FilterTokenDateTime
	FilterTokenBoolean
	FilterTokenLiteral
)

Token constants

View Source
const (
	OpAssociationLeft int = iota
	OpAssociationRight
)

Operator constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Function

type Function struct {
	Token string
	// The number of parameters this function accepts
	Params int
}

Function function structure

type Operator

type Operator struct {
	Token string
	// Whether the operator is left/right/or not associative
	Association int
	// The number of operands this operator operates on
	Operands int
	// Rank of precedence
	Precedence int
}

Operator operator structure

type ParseNode

type ParseNode struct {
	Token    *Token
	Parent   *ParseNode
	Children []*ParseNode
}

ParseNode parseNode structure

type Parser

type Parser struct {
	// Map from string inputs to operator types
	Operators map[string]*Operator
	// Map from string inputs to function types
	Functions map[string]*Function
}

Parser parser structure

func EmptyParser

func EmptyParser() *Parser

EmptyParser create empty parser

func (*Parser) DefineFunction

func (p *Parser) DefineFunction(token string, params int)

DefineFunction Adds a function to the language

func (*Parser) DefineOperator

func (p *Parser) DefineOperator(token string, operands, assoc, precedence int)

DefineOperator Adds an operator to the language. Provide the token, a precedence, and whether the operator is left, right, or not associative.

func (*Parser) Parse

func (p *Parser) Parse(tokens []*Token) (*ParseNode, error)

type Token

type Token struct {
	Value interface{}
	Type  int
	// contains filtered or unexported fields
}

Token token structure

type TokenMatcher

type TokenMatcher struct {
	Pattern string
	Regexp  *regexp.Regexp
	Token   int
}

TokenMatcher token matcher structure

type Tokenizer

type Tokenizer struct {
	TokenMatchers  []*TokenMatcher
	IgnoreMatchers []*TokenMatcher
}

Tokenizer structure

func (*Tokenizer) Add

func (t *Tokenizer) Add(pattern string, token int)

Add adds token to the tokenizer

func (*Tokenizer) Ignore

func (t *Tokenizer) Ignore(pattern string, token int)

Ignore adds ignore case to the tokenizer

func (*Tokenizer) Tokenize

func (t *Tokenizer) Tokenize(target string) ([]*Token, error)

Tokenize tokenize string by converting it to bytes and passing the array to the tokeizeBytes function

Jump to

Keyboard shortcuts

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