semantic

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package semantic contains the semantic analysis required to have a senantically valid parser. It includes the data conversion required to turn tokens into valid BadWolf structures. It also provides the hooks implementations required for buliding an actionable execution plan.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToLiteral

func ToLiteral(ce ConsumedElement) (*literal.Literal, error)

ToLiteral converts the node found by the lexer and converts it into a BadWolf literal.

func ToNode

func ToNode(ce ConsumedElement) (*node.Node, error)

ToNode converts the node found by the lexer and converts it into a BadWolf node.

func ToPredicate

func ToPredicate(ce ConsumedElement) (*predicate.Predicate, error)

ToPredicate converts the node found by the lexer and converts it into a BadWolf predicate.

Types

type AlwaysReturn

type AlwaysReturn struct {
	V bool
}

AlwaysReturn evaluator always return the provided boolean value.

func (*AlwaysReturn) Evaluate

func (a *AlwaysReturn) Evaluate(r table.Row) (bool, error)

Evaluate return the provided value.

type ClauseHook

type ClauseHook func(*Statement, Symbol) (ClauseHook, error)

ClauseHook is a function hook for the parser that gets called on clause wide events.

func GroupByBindingsChecker

func GroupByBindingsChecker() ClauseHook

GroupByBindingsChecker returns the singleton to check that the group by bindings are valid.

func HavingExpressionBuilder

func HavingExpressionBuilder() ClauseHook

HavingExpressionBuilder returns the singleton to collect the tokens that form the having clause.

func OrderByBindingsChecker

func OrderByBindingsChecker() ClauseHook

OrderByBindingsChecker returns the singleton to check that the group by bindings are valid.

func TypeBindingClauseHook

func TypeBindingClauseHook(t StatementType) ClauseHook

TypeBindingClauseHook returns a ClauseHook that sets the binding type.

func VarBindingsGraphChecker

func VarBindingsGraphChecker() ClauseHook

VarBindingsGraphChecker returns the singleton for checking a query statement for valid bidings in the select variables.

func WhereInitWorkingClauseHook

func WhereInitWorkingClauseHook() ClauseHook

WhereInitWorkingClauseHook returns the singleton for graph accumulation.

func WhereNextWorkingClauseHook

func WhereNextWorkingClauseHook() ClauseHook

WhereNextWorkingClauseHook returns the singleton for graph accumulation.

type ConsumedElement

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

ConsumedElement groups the curernt element being processed by the parser.

func NewConsumedSymbol

func NewConsumedSymbol(s Symbol) ConsumedElement

NewConsumedSymbol create a new consumed element that boxes a symbol.

func NewConsumedToken

func NewConsumedToken(tkn *lexer.Token) ConsumedElement

NewConsumedToken create a new consumed element that boxes a roken.

func (ConsumedElement) IsSymbol

func (c ConsumedElement) IsSymbol() bool

IsSymbol returns true if the boxed element is a symbol; false otherwise.

func (ConsumedElement) Symbol

func (c ConsumedElement) Symbol() Symbol

Symbol returns the boxed symbol.

func (ConsumedElement) Token

func (c ConsumedElement) Token() *lexer.Token

Token returns the boxed token.

type ElementHook

type ElementHook func(*Statement, ConsumedElement) (ElementHook, error)

ElementHook is a function hook for the parser that gets called after an Element is confused.

func CollectGlobalBounds

func CollectGlobalBounds() ElementHook

CollectGlobalBounds returns the global temporary bounds hook.

func DataAccumulatorHook

func DataAccumulatorHook() ElementHook

DataAccumulatorHook returns the singleton for data accumulation.

func GraphAccumulatorHook

func GraphAccumulatorHook() ElementHook

GraphAccumulatorHook returns the singleton for graph accumulation.

func GroupByBindings

func GroupByBindings() ElementHook

GroupByBindings returns the singleton for collecting all the group by bidings.

func HavingExpression

func HavingExpression() ElementHook

HavingExpression returns the singleton to collect the tokens that form the having clause.

func LimitCollection

func LimitCollection() ElementHook

LimitCollection returns the limit collection hook.

func OrderByBindings

func OrderByBindings() ElementHook

OrderByBindings returns the singleton for collecting all the group by bidings.

func VarAccumulatorHook

func VarAccumulatorHook() ElementHook

VarAccumulatorHook returns the singleton for accumulating variable projections.

func WhereObjectClauseHook

func WhereObjectClauseHook() ElementHook

WhereObjectClauseHook returns the singleton for working clause hooks that populates the object.

func WherePredicateClauseHook

func WherePredicateClauseHook() ElementHook

WherePredicateClauseHook returns the singleton for working clause hooks that populates the predicate.

func WhereSubjectClauseHook

func WhereSubjectClauseHook() ElementHook

WhereSubjectClauseHook returns the singleton for working clause hooks that populates the subject.

type Evaluator

type Evaluator interface {
	// Evaluate computes the boolean value of the expression given a certain
	// restults table row. It will return an
	// error if it could not be evaluated for the provided table row.
	Evaluate(r table.Row) (bool, error)
}

Evaluator interface computes the evaluation of a boolean expression.

func NewBinaryBooleanExpression

func NewBinaryBooleanExpression(op OP, lE, rE Evaluator) (Evaluator, error)

NewBinaryBooleanExpression creates a new binary boolean evalautor.

func NewEvaluationExpression

func NewEvaluationExpression(op OP, lB, rB string) (Evaluator, error)

NewEvaluationExpression creates a new evaluator for two bindings in a row.

func NewEvaluator

func NewEvaluator(ce []ConsumedElement) (Evaluator, error)

NewEvaluator construct an evaluator given a sequence of tokens. It will return a descriptive error if it could build it properly.

func NewUnaryBooleanExpression

func NewUnaryBooleanExpression(op OP, lE Evaluator) (Evaluator, error)

NewUnaryBooleanExpression creates a new unary boolean evalautor.

type GraphClause

type GraphClause struct {
	S          *node.Node
	SBinding   string
	SAlias     string
	STypeAlias string
	SIDAlias   string

	P                *predicate.Predicate
	PID              string
	PBinding         string
	PAlias           string
	PIDAlias         string
	PAnchorBinding   string
	PAnchorAlias     string
	PLowerBound      *time.Time
	PUpperBound      *time.Time
	PLowerBoundAlias string
	PUpperBoundAlias string
	PTemporal        bool

	O                *triple.Object
	OBinding         string
	OAlias           string
	OID              string
	OTypeAlias       string
	OIDAlias         string
	OAnchorBinding   string
	OAnchorAlias     string
	OLowerBound      *time.Time
	OUpperBound      *time.Time
	OLowerBoundAlias string
	OUpperBoundAlias string
	OTemporal        bool
}

GraphClause represents a clause of a graph pattern in a where clause.

func (*GraphClause) Bindings

func (c *GraphClause) Bindings() []string

Bindings returns the list of unique bindings listed int he graph clause.

func (*GraphClause) BindingsMap

func (c *GraphClause) BindingsMap() map[string]int

BindingsMap returns the binding map fo he graph clause.

func (*GraphClause) IsEmpty

func (c *GraphClause) IsEmpty() bool

IsEmpty will return true if the are no set values in the clause.

func (*GraphClause) Specificity

func (c *GraphClause) Specificity() int

Specificity return

type OP

type OP int8

OP the operation to be use in the expression evaluation.

const (
	// LT represents '<'
	LT OP = iota
	// GT represents '>”
	GT
	// EQ represents '=”
	EQ
	// NOT represents 'not'
	NOT
	// AND represents 'and'
	AND
	// OR represents 'or'
	OR
)

func (OP) String

func (o OP) String() string

String returns a readable string of the operation.

type Projection

type Projection struct {
	Binding  string
	Alias    string
	OP       lexer.TokenType // The information about what function to use.
	Modifier lexer.TokenType // The modifier for the selected op.
}

Projection contails the information required to project the outcome of querying with GraphClauses. It also contains the information of what aggregation function should be used.

func (*Projection) IsEmpty

func (p *Projection) IsEmpty() bool

IsEmpty check if the given projection is empty.

func (*Projection) String

func (p *Projection) String() string

String returns a readable form of the projection.

type Statement

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

Statement contains all the semantic information extract from the parsing

func (*Statement) AddData

func (s *Statement) AddData(d *triple.Triple)

AddData adds a triple to a given statement's data.

func (*Statement) AddGraph

func (s *Statement) AddGraph(g string)

AddGraph adds a graph to a given https://critique.corp.google.com/#review/101398527statement.

func (*Statement) AddWorkingGrpahClause

func (s *Statement) AddWorkingGrpahClause()

AddWorkingGrpahClause add the current working graph clause to the set of clauses that form the graph pattern.

func (*Statement) AddWorkingProjection

func (s *Statement) AddWorkingProjection()

AddWorkingProjection add the current projection variableto the set of projects that this statement.

func (*Statement) BindType

func (s *Statement) BindType(st StatementType)

BindType set he type of a statement.

func (*Statement) Bindings

func (s *Statement) Bindings() []string

Bindings retuns the list of bindings available on the graph clauses for he statement.

func (*Statement) BindingsMap

func (s *Statement) BindingsMap() map[string]int

BindingsMap retuns the set of bindings available on the graph clauses for he statement.

func (*Statement) Data

func (s *Statement) Data() []*triple.Triple

Data returns the data available for the given statement.

func (*Statement) GlobalLookupOptions

func (s *Statement) GlobalLookupOptions() *storage.LookupOptions

GlobalLookupOptions returns the global lookup options available in the statement.

func (*Statement) GraphPatternClauses

func (s *Statement) GraphPatternClauses() []*GraphClause

GraphPatternClauses return the list of graph pattern clauses

func (*Statement) Graphs

func (s *Statement) Graphs() []string

Graphs returns the list of graphs listed on the statement.

func (*Statement) GroupByBindings

func (s *Statement) GroupByBindings() []string

GroupByBindings returns the bindings used on the group by statement.

func (*Statement) HasHavingClause

func (s *Statement) HasHavingClause() bool

HasHavingClause returns true if there is a having clause.

func (*Statement) HavingEvaluator

func (s *Statement) HavingEvaluator() Evaluator

HavingEvaluator returns the evaluator constructed for the provided having clause.

func (*Statement) InputBindings

func (s *Statement) InputBindings() []string

InputBindings returns the list of incomming binding feed from a where clause.

func (*Statement) IsLimitSet

func (s *Statement) IsLimitSet() bool

IsLimitSet returns true if the limit is set.

func (*Statement) Limit

func (s *Statement) Limit() int64

Limit returns the limit value set in the limit clause.

func (*Statement) OrderByConfig

func (s *Statement) OrderByConfig() table.SortConfig

OrderByConfig returns the sort configuration specified by the order by statement.

func (*Statement) OutputBindings

func (s *Statement) OutputBindings() []string

OutputBindings returns the list of binding that a query will return.

func (*Statement) Projections

func (s *Statement) Projections() []*Projection

Projections returns all the available projections.

func (*Statement) ResetProjection

func (s *Statement) ResetProjection()

ResetProjection resets the current working variable projection.

func (*Statement) ResetWorkingGraphClause

func (s *Statement) ResetWorkingGraphClause()

ResetWorkingGraphClause resets the current working graph clause.

func (*Statement) SortedGraphPatternClauses

func (s *Statement) SortedGraphPatternClauses() []*GraphClause

SortedGraphPatternClauses return the list of graph pattern clauses

func (*Statement) Type

func (s *Statement) Type() StatementType

Type returns the type of the statement.

func (*Statement) WorkingClause

func (s *Statement) WorkingClause() *GraphClause

WorkingClause returns the current working clause.

func (*Statement) WorkingProjection

func (s *Statement) WorkingProjection() *Projection

WorkingProjection returns the current working variable projection.

type StatementType

type StatementType int8

StatementType describes the type of statement being represented.

const (
	// Query statement.
	Query StatementType = iota
	// Insert statemrnt.
	Insert
	// Delete statement.
	Delete
	// Create statement.
	Create
	// Drop statement.
	Drop
)

func (StatementType) String

func (t StatementType) String() string

String provides a readable version of the StatementType.

type Symbol

type Symbol string

Symbol of the LLk left factored grammar.

func (Symbol) String

func (s Symbol) String() string

String returns a string representation of the symbol

Jump to

Keyboard shortcuts

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