ast

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IDENTIFIER ExpressionType = "identifier"
	INFLIX     ExpressionType = "inflix"

	AND Operator = "and"
	OR  Operator = "or"
	NOT Operator = "not"

	PERMISSION RelationalReferenceType = "permission"
	RELATION   RelationalReferenceType = "relation"
)

Variables

This section is empty.

Functions

func IsDirectEntityReference added in v0.3.1

func IsDirectEntityReference(s RelationTypeStatement) bool

IsDirectEntityReference returns true if the RelationTypeStatement is a direct entity reference.

Types

type EntityStatement

type EntityStatement struct {
	Entity               token.Token // token.ENTITY
	Name                 token.Token // token.IDENT
	RelationStatements   []Statement // Statements that define relationships between entities
	PermissionStatements []Statement // Statements that define permissions performed on the entity
}

EntityStatement represents a statement that refers to an entity.

func (*EntityStatement) String

func (ls *EntityStatement) String() string

String returns a string representation of the EntityStatement.

type Expression

type Expression interface {
	Node

	IsInfix() bool
	GetType() ExpressionType
	// contains filtered or unexported methods
}

Expression defines an interface for an expression node.

type ExpressionStatement

type ExpressionStatement struct {
	Expression Expression
}

ExpressionStatement struct represents an expression statement

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

String function returns a string representation of the ExpressionStatement

type ExpressionType

type ExpressionType string

ExpressionType defines the type of expression.

type Identifier

type Identifier struct {
	Idents []token.Token // Idents is a slice of tokens that make up the identifier
}

Identifier represents an expression that identifies an entity, permission or relation

func (*Identifier) GetType

func (ls *Identifier) GetType() ExpressionType

GetType returns the type of the expression which is Identifier

func (*Identifier) IsInfix

func (ls *Identifier) IsInfix() bool

IsInfix returns false since an identifier is not an infix expression

func (*Identifier) String

func (ls *Identifier) String() string

String returns a string representation of the identifier expression

type InfixExpression

type InfixExpression struct {
	Op       token.Token // The operator token, e.g. and, or, not.
	Left     Expression  // The left-hand side sub-expression.
	Operator Operator    // The operator as a string.
	Right    Expression  // The right-hand side sub-expression.
}

InfixExpression represents an expression with an operator between two sub-expressions.

func (*InfixExpression) GetType

func (ie *InfixExpression) GetType() ExpressionType

GetType returns the type of the expression, which is infix.

func (*InfixExpression) IsInfix

func (ie *InfixExpression) IsInfix() bool

IsInfix returns true because it's an infix expression.

func (*InfixExpression) String

func (ie *InfixExpression) String() string

String returns the string representation of the infix expression.

type Node

type Node interface {
	String() string
}

Node defines an interface for a tree node.

type Operator

type Operator string

Operator defines a logical operator.

func (Operator) String

func (o Operator) String() string

String returns a string representation of the operator.

type PermissionStatement added in v0.3.9

type PermissionStatement struct {
	Permission          token.Token // token.PERMISSION
	Name                token.Token // token.IDENT
	ExpressionStatement Statement
}

PermissionStatement represents an permission statement, which consists of an permission name and an optional expression statement. It implements the Statement interface.

func (*PermissionStatement) String added in v0.3.9

func (ls *PermissionStatement) String() string

String returns a string representation of the permission statement.

type RelationStatement

type RelationStatement struct {
	Relation      token.Token             // token.RELATION
	Name          token.Token             // token.IDENT
	RelationTypes []RelationTypeStatement // Statements that define the types of the relationship
}

RelationStatement represents a statement that defines a relationship between two entities.

func (*RelationStatement) String

func (ls *RelationStatement) String() string

String returns a string representation of the RelationStatement.

type RelationTypeStatement

type RelationTypeStatement struct {
	Sign     token.Token // token.SIGN
	Type     token.Token // token.IDENT
	Relation token.Token // token.IDENT
}

RelationTypeStatement represents a statement that defines the type of a relationship.

func (*RelationTypeStatement) String

func (ls *RelationTypeStatement) String() string

String returns a string representation of the RelationTypeStatement.

type RelationalReferenceType

type RelationalReferenceType string

RelationalReferenceType defines the type of relational reference.

type Schema

type Schema struct {
	// The list of statements in the schema
	Statements []Statement
	// contains filtered or unexported fields
}

Schema represents the parsed schema, which contains all the statements and extracted entity and relational references used by the schema. It is used as an intermediate representation before generating the corresponding metadata.

func (*Schema) GetRelationReferenceIfExist

func (sch *Schema) GetRelationReferenceIfExist(name string) ([]RelationTypeStatement, bool)

GetRelationReferenceIfExist returns the relation reference if it exists in the schema

func (*Schema) GetRelationalReferenceTypeIfExist

func (sch *Schema) GetRelationalReferenceTypeIfExist(r string) (RelationalReferenceType, bool)

GetRelationalReferenceTypeIfExist returns the relational reference type if it exists

func (*Schema) IsEntityReferenceExist

func (sch *Schema) IsEntityReferenceExist(name string) bool

IsEntityReferenceExist checks if the entity reference exists in the schema

func (*Schema) IsRelationReferenceExist

func (sch *Schema) IsRelationReferenceExist(name string) bool

IsRelationReferenceExist checks if the relation reference exists in the schema

func (*Schema) IsRelationalReferenceExist added in v0.3.1

func (sch *Schema) IsRelationalReferenceExist(name string) bool

IsRelationalReferenceExist checks if the relational reference exists in the schema

func (*Schema) SetEntityReferences

func (sch *Schema) SetEntityReferences(r map[string]struct{})

SetEntityReferences sets the entity references in the schema

func (*Schema) SetPermissionReferences added in v0.3.9

func (sch *Schema) SetPermissionReferences(r map[string]struct{})

SetPermissionReferences sets the permission references in the schema

func (*Schema) SetRelationReferences

func (sch *Schema) SetRelationReferences(r map[string][]RelationTypeStatement)

SetRelationReferences sets the relation references in the schema

func (*Schema) SetRelationalReferences

func (sch *Schema) SetRelationalReferences(r map[string]RelationalReferenceType)

SetRelationalReferences sets the relational references in the schema

func (*Schema) Validate added in v0.3.1

func (sch *Schema) Validate() error

Validate - validates the schema to ensure that it meets certain requirements.

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Statement defines an interface for a statement node.

Jump to

Keyboard shortcuts

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