parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OPERATION  = "operation"
	EXPRESSION = "expression"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Expression

type Expression struct {
	Field      string
	Comparator string
	Value      string
}

Expression represents something like x=y or x>=y

func (Expression) String

func (e Expression) String() string

func (Expression) Type

func (e Expression) Type() string

type Lexer

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

Lexer represents a lexical scanner.

func NewLexer

func NewLexer(r io.Reader) *Lexer

NewLexer returns a new instance of Lexer.

func NewLexerFromString

func NewLexerFromString(s string) *Lexer

func (*Lexer) Scan

func (s *Lexer) Scan() TokenInfo

Scan returns the next token and literal Value.

type Node

type Node interface {
	Type() string
	String() string
}

Node represents a node in the AST after the expression is parsed.

type Operation

type Operation struct {
	LeftNode  Node
	Gate      string
	RightNode Node
}

Operation represents a Node (Operation or Expression) compared with another Node using either `AND` or `OR`.

func (Operation) String

func (o Operation) String() string

func (Operation) Type

func (o Operation) Type() string

type Parser

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

Parser represents a parser, including a scanner and the underlying raw input. It also contains a small buffer to allow for two unscans.

func NewParser

func NewParser(s string) *Parser

NewParser returns a new instance of Parser.

func (*Parser) Parse

func (p *Parser) Parse() (Node, error)

type Token

type Token int

Token represents a lexical token.

const (
	// Special tokens
	// Iota simply starts and integer count
	OTHER Token = iota
	EOF
	WS

	// Main literals
	STRING

	// Brackets
	OPEN_BRACKET
	CLOSED_BRACKET

	// Special characters
	GREATER_THAN
	GREATHER_THAN_EQUAL
	LESS_THAN
	LESS_THAN_EQUAL
	EQUAL
	NOT_EQUAL

	// Keywords
	AND
	OR
)

Declare the tokens here.

func (Token) String

func (t Token) String() (print string)

String prints a human readable string name for a given token.

type TokenInfo

type TokenInfo struct {
	Token   Token
	Literal string
}

TokenInfo stores relevant information about the token during scanning.

type TokenStack

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

TokenStack is used as the buffer for the Parser.

func (*TokenStack) Len

func (s *TokenStack) Len() int

func (*TokenStack) Pop

func (s *TokenStack) Pop() (TokenInfo, error)

func (*TokenStack) Push

func (s *TokenStack) Push(v TokenInfo)

Jump to

Keyboard shortcuts

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