ast

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

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

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

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 AttributeStatement added in v0.5.0

type AttributeStatement struct {
	Attribute     token.Token // token.ATTRIBUTE
	Name          token.Token // token.IDENT
	AttributeType AttributeTypeStatement
}

AttributeStatement represents a statement that defines an attribute of an entity.

func (*AttributeStatement) GetName added in v0.5.0

func (as *AttributeStatement) GetName() string

func (*AttributeStatement) StatementType added in v0.7.9

func (as *AttributeStatement) StatementType() StatementType

func (*AttributeStatement) String added in v0.5.0

func (as *AttributeStatement) String() string

String returns a string representation of the AttributeStatement.

type AttributeTypeStatement added in v0.5.0

type AttributeTypeStatement struct {
	Type    token.Token // token.IDENT
	IsArray bool
}

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

func (*AttributeTypeStatement) GetName added in v0.5.0

func (as *AttributeTypeStatement) GetName() string

func (*AttributeTypeStatement) StatementType added in v0.7.9

func (as *AttributeTypeStatement) StatementType() StatementType

func (*AttributeTypeStatement) String added in v0.5.0

func (as *AttributeTypeStatement) String() string

String returns a string representation of the RelationTypeStatement.

type Call added in v0.5.0

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

func (*Call) GetType added in v0.5.0

func (ls *Call) GetType() ExpressionType

GetType returns the type of the expression which is Identifier

func (*Call) IsInfix added in v0.5.0

func (ls *Call) IsInfix() bool

IsInfix returns false since an identifier is not an infix expression

func (*Call) String added in v0.5.0

func (ls *Call) String() string

String returns a string representation of the identifier expression

type EntityStatement

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

EntityStatement represents a statement that refers to an entity.

func (*EntityStatement) GetName added in v0.5.0

func (ls *EntityStatement) GetName() string

func (*EntityStatement) StatementType added in v0.7.9

func (ls *EntityStatement) StatementType() StatementType

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) GetName added in v0.5.0

func (es *ExpressionStatement) GetName() string

func (*ExpressionStatement) StatementType added in v0.7.9

func (es *ExpressionStatement) StatementType() StatementType

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) GetName added in v0.5.0

func (ls *PermissionStatement) GetName() string

func (*PermissionStatement) StatementType added in v0.7.9

func (ls *PermissionStatement) StatementType() StatementType

func (*PermissionStatement) String added in v0.3.9

func (ls *PermissionStatement) String() string

String returns a string representation of the permission statement.

type ReferenceType added in v0.5.0

type ReferenceType string

ReferenceType defines the type of reference.

const (
	UNSPECIFIED ReferenceType = "unspecified"
	PERMISSION  ReferenceType = "permission"
	RELATION    ReferenceType = "relation"
	ATTRIBUTE   ReferenceType = "attribute"
	ENTITY      ReferenceType = "entity"
	RULE        ReferenceType = "rule"
)

type References added in v0.5.0

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

References - Map of all relational references extracted from the schema

func NewReferences added in v0.5.0

func NewReferences() *References

NewReferences creates a new instance of References

func (*References) AddAttributeReferences added in v0.7.9

func (refs *References) AddAttributeReferences(key string, typ AttributeTypeStatement) error

AddAttributeReferences sets references for an attribute with its type.

func (*References) AddEntityReference added in v0.7.9

func (refs *References) AddEntityReference(name string) error

AddEntityReference sets a reference for an entity.

func (*References) AddPermissionReference added in v0.7.9

func (refs *References) AddPermissionReference(key string) error

AddPermissionReference sets a reference for a permission.

func (*References) AddRelationReferences added in v0.7.9

func (refs *References) AddRelationReferences(key string, types []RelationTypeStatement) error

AddRelationReferences sets references for a relation with its types.

func (*References) AddRuleReference added in v0.7.9

func (refs *References) AddRuleReference(name string, types map[string]string) error

AddRuleReference sets a reference for a rule.

func (*References) GetAttributeReferenceTypeIfExist added in v0.5.0

func (refs *References) GetAttributeReferenceTypeIfExist(name string) (AttributeTypeStatement, bool)

GetAttributeReferenceTypeIfExist retrieves the attribute type for a given attribute reference key.

func (*References) GetReferenceType added in v0.5.0

func (refs *References) GetReferenceType(key string) (ReferenceType, bool)

GetReferenceType retrieves the type of the reference for a given key.

func (*References) GetRelationReferenceTypesIfExist added in v0.5.0

func (refs *References) GetRelationReferenceTypesIfExist(name string) ([]RelationTypeStatement, bool)

GetRelationReferenceTypesIfExist retrieves the relation types for a given relation reference key.

func (*References) GetRuleArgumentTypesIfRuleExist added in v0.5.0

func (refs *References) GetRuleArgumentTypesIfRuleExist(name string) (map[string]string, bool)

GetRuleArgumentTypesIfRuleExist retrieves the rule argument types for a given rule reference key.

func (*References) IsAttributeReferenceExist added in v0.5.0

func (refs *References) IsAttributeReferenceExist(name string) bool

IsAttributeReferenceExist checks if an attribute reference exists for the given key.

func (*References) IsEntityReferenceExist added in v0.5.0

func (refs *References) IsEntityReferenceExist(name string) bool

IsEntityReferenceExist checks if an entity reference exists for the given name.

func (*References) IsReferenceExist added in v0.5.0

func (refs *References) IsReferenceExist(name string) bool

IsReferenceExist checks if a reference exists for the given key.

func (*References) IsRelationReferenceExist added in v0.5.0

func (refs *References) IsRelationReferenceExist(name string) bool

IsRelationReferenceExist checks if a relation reference exists for the given key.

func (*References) IsRuleReferenceExist added in v0.5.0

func (refs *References) IsRuleReferenceExist(name string) bool

IsRuleReferenceExist checks if a rule reference exists for the given name.

func (*References) RemoveAttributeReferences added in v0.7.9

func (refs *References) RemoveAttributeReferences(key string) error

RemoveAttributeReferences removes the attribute references associated with a given key. If the key is empty, it returns an error.

func (*References) RemovePermissionReference added in v0.7.9

func (refs *References) RemovePermissionReference(key string) error

RemovePermissionReference removes the permission references associated with a given key. If the key is empty, it returns an error.

func (*References) RemoveRelationReferences added in v0.7.9

func (refs *References) RemoveRelationReferences(key string) error

RemoveRelationReferences removes the relationship references associated with a given key. If the key is empty, it returns an error.

func (*References) UpdateAttributeReferences added in v0.7.9

func (refs *References) UpdateAttributeReferences(key string, typ AttributeTypeStatement) error

UpdateAttributeReferences updates the attribute references for a given key. It associates a specific attribute type with the key. If the key is empty, it returns an error.

func (*References) UpdatePermissionReference added in v0.7.9

func (refs *References) UpdatePermissionReference(key string) error

UpdatePermissionReference updates the permission references for a given key. This typically means marking a particular entity or action as permitted. If the key is empty, it returns an error.

func (*References) UpdateRelationReferences added in v0.7.9

func (refs *References) UpdateRelationReferences(key string, types []RelationTypeStatement) error

UpdateRelationReferences updates the relationship references for a given key. It replaces the existing relation types with the new ones provided. If the key is empty, it returns an error.

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) GetName added in v0.5.0

func (ls *RelationStatement) GetName() string

func (*RelationStatement) StatementType added in v0.7.9

func (ls *RelationStatement) StatementType() StatementType

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 relationship.

func (*RelationTypeStatement) GetName added in v0.5.0

func (ls *RelationTypeStatement) GetName() string

func (*RelationTypeStatement) StatementType added in v0.7.9

func (ls *RelationTypeStatement) StatementType() StatementType

func (*RelationTypeStatement) String

func (ls *RelationTypeStatement) String() string

String returns a string representation of the RelationTypeStatement.

type RuleStatement added in v0.5.0

type RuleStatement struct {
	Rule       token.Token // token.RULE
	Name       token.Token // token.IDENT
	Arguments  map[token.Token]AttributeTypeStatement
	Expression string
}

RuleStatement represents a rule statement, which consists of a rule name, a list of parameters and a body.

func (*RuleStatement) GetName added in v0.5.0

func (rs *RuleStatement) GetName() string

func (*RuleStatement) StatementType added in v0.7.9

func (rs *RuleStatement) StatementType() StatementType

func (*RuleStatement) String added in v0.5.0

func (rs *RuleStatement) String() string

String returns a string representation of the permission statement.

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 NewSchema added in v0.5.0

func NewSchema() *Schema

func (*Schema) AddStatement added in v0.7.9

func (sch *Schema) AddStatement(entityName string, stmt Statement) error

AddStatement adds a new statement to an entity within the schema. It also updates the schema's references.

func (*Schema) DeleteStatement added in v0.7.9

func (sch *Schema) DeleteStatement(entityName, name string) error

DeleteStatement removes a specific statement from an entity within the schema. It identifies the statement by its name and the name of the entity it belongs to. If successful, it also removes the corresponding reference from the schema.

func (*Schema) GetReferences added in v0.5.0

func (sch *Schema) GetReferences() *References

GetReferences -

func (*Schema) SetReferences added in v0.5.0

func (sch *Schema) SetReferences(refs *References)

SetReferences -

func (*Schema) String added in v0.7.9

func (sch *Schema) String() string

String -

func (*Schema) UpdateStatement added in v0.7.9

func (sch *Schema) UpdateStatement(entityName string, newStmt Statement) error

UpdateStatement updates a statement of a specific type (permission, relation, or attribute) for a given entity within the schema. It either updates an existing statement or appends a new one if not found.

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

	GetName() string
	StatementType() StatementType
	// contains filtered or unexported methods
}

Statement defines an interface for a statement node.

type StatementType added in v0.7.9

type StatementType string
const (
	PERMISSION_STATEMENT     StatementType = "permission"
	RELATION_STATEMENT       StatementType = "relation"
	ATTRIBUTE_STATEMENT      StatementType = "attribute"
	ENTITY_STATEMENT         StatementType = "entity"
	RULE_STATEMENT           StatementType = "rule"
	EXPRESSION_STATEMENT     StatementType = "expression"
	RELATION_TYPE_STATEMENT  StatementType = "relation_type"
	ATTRIBUTE_TYPE_STATEMENT StatementType = "attribute_type"
)

Jump to

Keyboard shortcuts

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