path

package module
v0.0.0-...-fbbe983 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2020 License: MIT Imports: 7 Imported by: 0

README

path

Path querying

Documentation

Index

Constants

View Source
const (
	LOWEST = iota
	PCONDOR
	PCONDAND
	EQUALS
	LESSGREATER
	CALL
	INDEX
)

Variables

View Source
var (
	ErrNotFound = errors.Errorf("not found")
)
View Source
var (
	// UnknownToken can be used as a sentinel token for a unknown state.
	UnknownToken = Token{
		Type: UNKNOWN,
	}
)

Functions

func IsRuntimeError

func IsRuntimeError(err error) bool

IsRuntimeError returns if the error is an ErrInvalidIndex error

func RuntimeErrorf

func RuntimeErrorf(msg string, args ...interface{}) error

RuntimeErrorf defines a sentinel error for invalid index.

Types

type AccessExpression

type AccessExpression struct {
	Token Token
	Index Expression
}

AccessExpression represents an expression that is associated with an operator.

func (*AccessExpression) End

func (ie *AccessExpression) End() Position

End returns the last position of the identifier.

func (*AccessExpression) Pos

func (ie *AccessExpression) Pos() Position

Pos returns the first position of the identifier.

func (*AccessExpression) String

func (ie *AccessExpression) String() string

type AccessorExpression

type AccessorExpression struct {
	Token Token
	Right Expression
	Left  Expression
}

AccessorExpression represents an expression that is associated with an operator.

func (*AccessorExpression) End

func (ie *AccessorExpression) End() Position

End returns the last position of the identifier.

func (*AccessorExpression) Pos

func (ie *AccessorExpression) Pos() Position

Pos returns the first position of the identifier.

func (*AccessorExpression) String

func (ie *AccessorExpression) String() string

type DescentExpression

type DescentExpression struct {
	Token Token
	Right Expression
}

DescentExpression represents an descent expression

func (*DescentExpression) End

func (i *DescentExpression) End() Position

End returns the last position of the descent expression.

func (*DescentExpression) Pos

func (i *DescentExpression) Pos() Position

Pos returns the first position of the descent expression.

func (*DescentExpression) String

func (i *DescentExpression) String() string

type Empty

type Empty struct {
	Token Token
}

Empty represents an empty expression

func (*Empty) End

func (i *Empty) End() Position

End returns the last position of the empty expression.

func (*Empty) Pos

func (i *Empty) Pos() Position

Pos returns the first position of the empty expression.

func (*Empty) String

func (i *Empty) String() string

type Expression

type Expression interface {
	Pos() Position
	End() Position

	String() string
}

Expression defines a type of AST node for outlining an expression.

type ExpressionStatement

type ExpressionStatement struct {
	Token      Token
	Expression Expression
}

ExpressionStatement is a group of expressions that allows us to group a subset of expressions.

func (*ExpressionStatement) End

func (es *ExpressionStatement) End() Position

End returns the last position of the expression statement.

func (*ExpressionStatement) Pos

func (es *ExpressionStatement) Pos() Position

Pos returns the first position of the expression statement.

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

type Identifier

type Identifier struct {
	Token Token
}

Identifier represents an identifier for a given AST block

func (*Identifier) End

func (i *Identifier) End() Position

End returns the last position of the identifier.

func (*Identifier) Pos

func (i *Identifier) Pos() Position

Pos returns the first position of the identifier.

func (*Identifier) String

func (i *Identifier) String() string

type IndexExpression

type IndexExpression struct {
	Token Token
	Left  Expression
	Index Expression
}

IndexExpression represents an expression that is associated with an operator.

func (*IndexExpression) End

func (ie *IndexExpression) End() Position

End returns the last position of the identifier.

func (*IndexExpression) Pos

func (ie *IndexExpression) Pos() Position

Pos returns the first position of the identifier.

func (*IndexExpression) String

func (ie *IndexExpression) String() string

type InfixExpression

type InfixExpression struct {
	Token    Token
	Operator string
	Left     Expression
	Right    Expression
}

InfixExpression represents an expression that is associated with an operator.

func (*InfixExpression) End

func (ie *InfixExpression) End() Position

End returns the last position of the identifier.

func (*InfixExpression) Pos

func (ie *InfixExpression) Pos() Position

Pos returns the first position of the identifier.

func (*InfixExpression) String

func (ie *InfixExpression) String() string

type InfixFunc

type InfixFunc func(Expression) Expression

type Lexer

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

Lexer takes a query and breaks it down into tokens that can be consumed at at later date. The lexer in question is lazy and requires the calling of next to move it forward.

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new Lexer from a given input.

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

NextToken attempts to grab the next token available.

func (*Lexer) Peek

func (l *Lexer) Peek() rune

Peek will attempt to read the next rune if it's available.

func (*Lexer) PeekN

func (l *Lexer) PeekN(n int) rune

PeekN attempts to read the next rune by a given offset, it it's available.

func (*Lexer) ReadNext

func (l *Lexer) ReadNext()

ReadNext will attempt to read the next character and correctly setup the positional values for the input.

type Operation

type Operation int

Operation describes an operation that should be run.

const (
	OpEQ Operation = iota
	OpNEQ
	OpLT
	OpLE
	OpGT
	OpGE
)

type Parser

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

func NewParser

func NewParser(lex *Lexer) *Parser

NewParser creates a parser for consuming a lexer tokens.

func (*Parser) Run

func (p *Parser) Run() (*QueryExpression, error)

Run the parser to the end, which is either an EOF or an error.

type Path

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

Path holds all the arguments for a given query.

func Parse

func Parse(src string) (Path, error)

Parse attempts to parse a given query into a argument query. Returns an error if it's not in the correct layout.

func (Path) Run

func (q Path) Run(scope Scope) (Scope, error)

Run the query over a given scope.

type Position

type Position struct {
	Offset int
	Line   int
	Column int
}

Position holds the location of the token within the query.

func (Position) String

func (p Position) String() string

type PrefixFunc

type PrefixFunc func() Expression

type QueryExpression

type QueryExpression struct {
	Expressions []Expression
}

QueryExpression represents a query full of expressions

func (*QueryExpression) End

func (e *QueryExpression) End() Position

End returns the last position of the query expression.

func (*QueryExpression) Pos

func (e *QueryExpression) Pos() Position

Pos returns the first position of the query expression.

func (*QueryExpression) String

func (e *QueryExpression) String() string

type RuntimeError

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

RuntimeError creates an invalid error.

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

type Scope

type Scope interface {
	// GetAllIdents returns all the identifiers for a given scope.
	GetAllIdents() []string
	// GetIdentValue returns the value of the identifier in a given scope.
	GetIdentValue(string) (Scope, error)
	// RunOperation attempts to run an operation on a given scope
	RunOperation(Operation, Scope) (Scope, error)
}

Scope is used to identify a given expression of a global mutated object.

type Scopes

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

Scopes holds a list of scopes to walk over.

func NewScopes

func NewScopes(scopes []Scope) *Scopes

NewScopes creates a new set of scopes.

func (Scopes) GetAllIdents

func (s Scopes) GetAllIdents() []string

GetAllIdents returns all the identifiers for a given scope.

func (Scopes) GetIdentValue

func (s Scopes) GetIdentValue(v string) (Scope, error)

GetIdentValue returns the value of the identifier in a given scope.

func (Scopes) RunOperation

func (s Scopes) RunOperation(op Operation, other Scope) (Scope, error)

RunOperation runs a given operation on a scope.

type String

type String struct {
	Token Token
}

String represents an string for a given AST block

func (*String) End

func (i *String) End() Position

End returns the last position of the string.

func (*String) Pos

func (i *String) Pos() Position

Pos returns the first position of the string.

func (*String) String

func (i *String) String() string

type StringScope

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

func MakeStringScope

func MakeStringScope(v string) StringScope

func (StringScope) GetAllIdents

func (s StringScope) GetAllIdents() []string

GetAllIdents returns all the identifiers for a given scope.

func (StringScope) GetIdentValue

func (s StringScope) GetIdentValue(v string) (Scope, error)

GetIdentValue returns the value of the identifier in a given scope.

func (StringScope) RunOperation

func (s StringScope) RunOperation(op Operation, scope Scope) (Scope, error)

RunOperation attempts to run an operation on a given scope

type Token

type Token struct {
	Pos     Position
	Type    TokenType
	Literal string
}

Token defines a token found with in a query, along with the position and what type it is.

func MakeToken

func MakeToken(tokenType TokenType, char string) Token

MakeToken creates a new token value.

type TokenType

type TokenType int

TokenType represents a way to identify an individual token.

const (
	UNKNOWN TokenType = (iota - 1)
	EOF

	IDENT
	STRING

	EQ     // ==
	NEQ    // !=
	ASSIGN // =
	BANG   // !

	LT // <
	LE // <=
	GT // >
	GE // >=

	BITAND  // &
	BITOR   // |
	CONDAND // &&
	CONDOR  // ||

	LPAREN   // (
	RPAREN   // )
	LBRACKET // [
	RBRACKET // ]

	PERIOD    // .
	SEMICOLON // ;
)

func (TokenType) String

func (t TokenType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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