parser

package
v0.0.0-...-77c610b Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	EffectPermit = Effect("permit")
	EffectForbid = Effect("forbid")
)
View Source
const (
	MatchAny = MatchType(iota)
	MatchEquals
	MatchIn
	MatchInList
	MatchIs
	MatchIsIn
)
View Source
const (
	TokenEOF = TokenType(iota)
	TokenIdent
	TokenInt
	TokenString
	TokenOperator
	TokenUnknown
)

Variables

This section is empty.

Functions

func FakeRustQuote

func FakeRustQuote(s string) string

TODO: make FakeRustQuote actually accurate in all cases

func Unquote

func Unquote(s string) (string, error)

Types

type Access

type Access struct {
	Type        AccessType
	Name        string
	Expressions []Expression
}

func (Access) String

func (a Access) String() string

type AccessType

type AccessType int
const (
	AccessField AccessType = iota
	AccessCall
	AccessIndex
)

type Action

type Action struct {
	Type     MatchType
	Entities []Entity
}

func (Action) String

func (a Action) String() string

type Add

type Add struct {
	Mults  []Mult
	AddOps []AddOp
}

func (Add) String

func (a Add) String() string

type AddOp

type AddOp string
const (
	AddOpAdd AddOp = "+"
	AddOpSub AddOp = "-"
)

type And

type And struct {
	Relations []Relation
}

func (And) String

func (a And) String() string

type Annotation

type Annotation struct {
	Key   string
	Value string
}

func (Annotation) String

func (a Annotation) String() string

type Condition

type Condition struct {
	Type       ConditionType
	Expression Expression
}

func (Condition) String

func (c Condition) String() string

type ConditionType

type ConditionType string
const (
	ConditionWhen   ConditionType = "when"
	ConditionUnless ConditionType = "unless"
)

type Effect

type Effect string

type Entity

type Entity struct {
	Path []string
}

func ParseEntity

func ParseEntity(tokens []Token) (Entity, error)

func (Entity) String

func (e Entity) String() string

type Expression

type Expression struct {
	Type ExpressionType
	Or   Or
	If   *If
}

func (Expression) String

func (e Expression) String() string

type ExpressionType

type ExpressionType int
const (
	ExpressionOr ExpressionType = iota
	ExpressionIf
)

type ExtFun

type ExtFun struct {
	Path        []string
	Expressions []Expression
}

func (ExtFun) String

func (f ExtFun) String() string

type If

type If struct {
	If   Expression
	Then Expression
	Else Expression
}

func (If) String

func (i If) String() string

type Literal

type Literal struct {
	Type LiteralType
	Bool bool
	Long int64
	Str  string
}

func (Literal) String

func (l Literal) String() string

type LiteralType

type LiteralType int
const (
	LiteralBool LiteralType = iota
	LiteralInt
	LiteralString
)

type MatchType

type MatchType int

type Member

type Member struct {
	Primary  Primary
	Accesses []Access
}

func (Member) String

func (m Member) String() string

type Mult

type Mult struct {
	Unaries []Unary
}

func (Mult) String

func (m Mult) String() string

type Or

type Or struct {
	Ands []And
}

func (Or) String

func (o Or) String() string

type Path

type Path struct {
	Path []string
}

func (Path) String

func (e Path) String() string

type Pattern

type Pattern struct {
	Comps []PatternComponent
	Raw   string
}

func NewPattern

func NewPattern(literal string) (Pattern, error)

func (Pattern) String

func (p Pattern) String() string

type PatternComponent

type PatternComponent struct {
	Star  bool
	Chunk string
}

type Policies

type Policies []Policy

func Parse

func Parse(tokens []Token) (Policies, error)

func (Policies) String

func (c Policies) String() string

type Policy

type Policy struct {
	Position    Position
	Annotations []Annotation
	Effect      Effect
	Principal   Principal
	Action      Action
	Resource    Resource
	Conditions  []Condition
}

func (Policy) String

func (p Policy) String() string

type Position

type Position struct {
	Offset int // byte offset, starting at 0
	Line   int // line number, starting at 1
	Column int // column number, starting at 1 (character count per line)
}

Position is a value that represents a source position. A position is valid if Line > 0.

func (Position) String

func (pos Position) String() string

type Primary

type Primary struct {
	Type        PrimaryType
	Literal     Literal
	Var         Var
	Entity      Entity
	ExtFun      ExtFun
	Expression  Expression
	Expressions []Expression
	RecInits    []RecInit
}

func (Primary) String

func (p Primary) String() string

type PrimaryType

type PrimaryType int
const (
	PrimaryLiteral PrimaryType = iota
	PrimaryVar
	PrimaryEntity
	PrimaryExtFun
	PrimaryExpr
	PrimaryExprList
	PrimaryRecInits
)

type Principal

type Principal struct {
	Type   MatchType
	Path   Path
	Entity Entity
}

func (Principal) String

func (p Principal) String() string

type RecInit

type RecInit struct {
	KeyType RecKeyType
	Key     string
	Value   Expression
}

func (RecInit) String

func (r RecInit) String() string

type RecKeyType

type RecKeyType int
const (
	RecKeyIdent RecKeyType = iota
	RecKeyString
)

type RelOp

type RelOp string
const (
	RelOpLt RelOp = "<"
	RelOpLe RelOp = "<="
	RelOpGe RelOp = ">="
	RelOpGt RelOp = ">"
	RelOpNe RelOp = "!="
	RelOpEq RelOp = "=="
	RelOpIn RelOp = "in"
)

type Relation

type Relation struct {
	Add      Add
	Type     RelationType
	RelOp    RelOp
	RelOpRhs Add
	Str      string
	Pat      Pattern
	Path     Path
	Entity   Add
}

func (Relation) String

func (r Relation) String() string

type RelationType

type RelationType string
const (
	RelationNone       RelationType = "none"
	RelationRelOp      RelationType = "relop"
	RelationHasIdent   RelationType = "hasident"
	RelationHasLiteral RelationType = "hasliteral"
	RelationLike       RelationType = "like"
	RelationIs         RelationType = "is"
	RelationIsIn       RelationType = "isIn"
)

type Resource

type Resource struct {
	Type   MatchType
	Path   Path
	Entity Entity
}

func (Resource) String

func (r Resource) String() string

type Token

type Token struct {
	Type TokenType
	Pos  Position
	Text string
}

func Tokenize

func Tokenize(src []byte) ([]Token, error)

type TokenType

type TokenType int

type Unary

type Unary struct {
	Ops    []UnaryOp
	Member Member
}

func (Unary) String

func (u Unary) String() string

type UnaryOp

type UnaryOp string
const (
	UnaryOpNot   UnaryOp = "!"
	UnaryOpMinus UnaryOp = "-"
)

type Var

type Var struct {
	Type VarType
}

func (Var) String

func (v Var) String() string

type VarType

type VarType string
const (
	VarPrincipal VarType = "principal"
	VarAction    VarType = "action"
	VarResource  VarType = "resource"
	VarContext   VarType = "context"
)

Jump to

Keyboard shortcuts

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