parser

package
v0.387.1-next.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeywordModel   = "model"
	KeywordModels  = "models"
	KeywordApi     = "api"
	KeywordMessage = "message"
	KeywordField   = "field"
	KeywordFields  = "fields"
	KeywordActions = "actions"
	KeywordDomains = "domains"
	KeywordEmails  = "emails"
	KeywordRole    = "role"
	KeywordEnum    = "enum"
	KeywordWith    = "with"
	KeywordReturns = "returns"
	KeywordJob     = "job"
	KeywordInput   = "inputs"
)

Keywords

View Source
const (
	TypeNumber  = "Number"
	TypeText    = "Text"
	TypeBoolean = "Boolean"
	TypeDecimal = "Decimal"

	// These are unique to expressions
	TypeNull  = "Null"
	TypeArray = "Array"
	TypeIdent = "Ident"
	TypeEnum  = "Enum"
	TypeModel = "Model"
)

Types are roughly analogous to field types but they are used to type expressions

View Source
const (
	FieldTypeID       = "ID"        // a uuid or similar
	FieldTypeText     = "Text"      // a string
	FieldTypeNumber   = "Number"    // an integer
	FieldTypeDecimal  = "Decimal"   // a decimal
	FieldTypeDate     = "Date"      // a date with no time element
	FieldTypeDatetime = "Timestamp" // a UTC unix timestamp
	FieldTypeBoolean  = "Boolean"   // a boolean
	FieldTypeSecret   = "Secret"    // an encrypted secret
	FieldTypePassword = "Password"  // a hashed password
	FieldTypeMarkdown = "Markdown"  // a markdown rich text
	FieldTypeVector   = "Vector"    // a vector
)

Built in Keel types. Worth noting a field type can also reference another user-defined model

View Source
const (
	ActionTypeGet    = "get"
	ActionTypeCreate = "create"
	ActionTypeUpdate = "update"
	ActionTypeList   = "list"
	ActionTypeDelete = "delete"

	// Arbitrary function action types
	ActionTypeRead  = "read"
	ActionTypeWrite = "write"
)

All possible action types

View Source
const (
	FieldNameId        = "id"
	FieldNameCreatedAt = "createdAt"
	FieldNameUpdatedAt = "updatedAt"
)

All models get a field named "id" implicitly. This set of constants provides the set of this, and other similar implicit fields.

View Source
const (
	IdentityModelName              = "Identity"
	IdentityFieldNameEmail         = "email"
	IdentityFieldNameEmailVerified = "emailVerified"
	IdentityFieldNamePassword      = "password"
	IdentityFieldNameExternalId    = "externalId"
	IdentityFieldNameIssuer        = "issuer"
	IdentityFieldNameName          = "name"
	IdentityFieldNameGivenName     = "givenName"
	IdentityFieldNameFamilyName    = "familyName"
	IdentityFieldNameMiddleName    = "middleName"
	IdentityFieldNameNickName      = "nickName"
	IdentityFieldNameProfile       = "profile"
	IdentityFieldNamePicture       = "picture"
	IdentityFieldNameWebsite       = "website"
	IdentityFieldNameGender        = "gender"
	IdentityFieldNameZoneInfo      = "zoneInfo"
	IdentityFieldNameLocale        = "locale"
)
View Source
const (
	RequestPasswordResetActionName = "requestPasswordReset"
	PasswordResetActionName        = "resetPassword"
)
View Source
const (
	AttributeUnique     = "unique"
	AttributePermission = "permission"
	AttributeWhere      = "where"
	AttributeSet        = "set"
	AttributePrimaryKey = "primaryKey"
	AttributeDefault    = "default"
	AttributeValidate   = "validate"
	AttributeRelation   = "relation"
	AttributeOrderBy    = "orderBy"
	AttributeSortable   = "sortable"
	AttributeSchedule   = "schedule"
	AttributeFunction   = "function"
	AttributeOn         = "on"
)
View Source
const (
	OrderByAscending  = "asc"
	OrderByDescending = "desc"
)
View Source
const (
	DefaultApi = "Api"
)
View Source
const (
	MessageFieldTypeAny = "Any"
)

Types for Message fields

Variables

View Source
var (
	AssignmentCondition = "assignment"
	LogicalCondition    = "logical"
	ValueCondition      = "value"
	UnknownCondition    = "unknown"
)
View Source
var (
	OperatorEquals               = "=="
	OperatorAssignment           = "="
	OperatorNotEquals            = "!="
	OperatorGreaterThanOrEqualTo = ">="
	OperatorLessThanOrEqualTo    = "<="
	OperatorLessThan             = "<"
	OperatorGreaterThan          = ">"
	OperatorIn                   = "in"
	OperatorNotIn                = "notin"
	OperatorIncrement            = "+="
	OperatorDecrement            = "-="
)
View Source
var AssignmentOperators = []string{
	OperatorAssignment,
}
View Source
var ErrNotAssignment = errors.New("expression is not using an assignment, e.g. a = b")
View Source
var ErrNotValue = errors.New("expression is not a single value")

Functions

func IsBuiltInFieldType

func IsBuiltInFieldType(s string) bool

Types

type APIModelActionNode added in v0.377.0

type APIModelActionNode struct {
	node.Node

	Name NameNode `@@`
}

type APIModelNode added in v0.377.0

type APIModelNode struct {
	node.Node

	Name     NameNode               `@@`
	Sections []*APIModelSectionNode `("{" @@* "}")*`
}

type APIModelSectionNode added in v0.377.0

type APIModelSectionNode struct {
	node.Node

	Actions []*APIModelActionNode `"actions" "{" @@* "}"`
}

type APINode

type APINode struct {
	node.Node

	Name     NameNode          `@@`
	Sections []*APISectionNode `"{" @@* "}"`
}

type APISectionNode

type APISectionNode struct {
	node.Node

	Models    []*APIModelNode `("models" "{" @@* "}"`
	Attribute *AttributeNode  `| @@)`
}

type AST

type AST struct {
	node.Node

	Declarations         []*DeclarationNode `@@*`
	EnvironmentVariables []string
	Secrets              []string
}

func Parse

func Parse(s *reader.SchemaFile) (*AST, error)

type ActionInputNode

type ActionInputNode struct {
	node.Node

	Label    *NameNode `(@@ ":")?`
	Type     Ident     `@@`
	Optional bool      `@( "?" )?`
}

func (*ActionInputNode) Name

func (a *ActionInputNode) Name() string

type ActionNode

type ActionNode struct {
	node.Node

	Type       NameNode           `@@`
	Name       NameNode           `@@`
	Inputs     []*ActionInputNode `"(" ( @@ ( "," @@ )* ","? )? ")"`
	With       []*ActionInputNode `( ( "with" "(" ( @@ ( "," @@ )* ","? )? ")" )`
	Returns    []*ActionInputNode `| ( "returns" "(" ( @@ ( "," @@ )* ) ")" ) )?`
	Attributes []*AttributeNode   `( "{" @@+ "}" | @@+ )?`

	BuiltIn bool
}

func (*ActionNode) IsArbitraryFunction

func (a *ActionNode) IsArbitraryFunction() bool

func (*ActionNode) IsFunction

func (a *ActionNode) IsFunction() bool

type Array

type Array struct {
	node.Node

	Values []*Operand `"[" @@* ( "," @@ )* "]"`
}

type AttributeArgumentNode

type AttributeArgumentNode struct {
	node.Node

	Label      *NameNode   `(@@ ":")?`
	Expression *Expression `@@`
}

type AttributeNameToken

type AttributeNameToken struct {
	node.Node

	Value string `"@" @Ident`
}

type AttributeNode

type AttributeNode struct {
	node.Node

	Name AttributeNameToken `@@`

	// This supports:
	// - no parenthesis at all
	// - empty parenthesis
	// - parenthesis with args
	Arguments []*AttributeArgumentNode `(( "(" @@ ( "," @@ )* ")" ) | ( "(" ")" ) )?`
}

Attributes: - @permission - @set - @validate - @where - @unique - @default - @orderBy - @sortable - @on

type Condition

type Condition struct {
	node.Node

	LHS      *Operand  `@@`
	Operator *Operator `(@@`
	RHS      *Operand  `@@ )?`
}

func (*Condition) ToString

func (condition *Condition) ToString() string

func (*Condition) Type

func (c *Condition) Type() string

type ConditionWrap

type ConditionWrap struct {
	node.Node

	Expression *Expression `( "(" @@ ")"`
	Condition  *Condition  `| @@ )`
}

type DeclarationNode

type DeclarationNode struct {
	node.Node

	Model   *ModelNode   `("model" @@`
	Role    *RoleNode    `| "role" @@`
	API     *APINode     `| "api" @@`
	Enum    *EnumNode    `| "enum" @@`
	Message *MessageNode `| "message" @@`
	Job     *JobNode     `| "job" @@)`
}

type DomainNode

type DomainNode struct {
	node.Node

	Domain string `@String`
}

type EmailsNode

type EmailsNode struct {
	node.Node

	Email string `@String`
}

type EnumNode

type EnumNode struct {
	node.Node

	Name   NameNode         `@@`
	Values []*EnumValueNode `"{" @@* "}"`
}

func (*EnumNode) NameNode

func (e *EnumNode) NameNode() NameNode

type EnumValueNode

type EnumValueNode struct {
	node.Node

	Name NameNode `@@`
}

type Error

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

func (Error) Error

func (e Error) Error() string

func (Error) GetPositionRange

func (e Error) GetPositionRange() (start lexer.Position, end lexer.Position)

func (Error) GetTokens

func (e Error) GetTokens() []lexer.Token

func (Error) HasEndPosition

func (e Error) HasEndPosition() bool

func (Error) InRange

func (e Error) InRange(position node.Position) bool

type Expression

type Expression struct {
	node.Node

	Or []*OrExpression `@@ ("or" @@)*`
}

func ParseExpression

func ParseExpression(source string) (*Expression, error)

func (*Expression) Conditions

func (e *Expression) Conditions() []*Condition

func (*Expression) IsAssignment

func (expr *Expression) IsAssignment() bool

func (*Expression) IsValue

func (expr *Expression) IsValue() bool

func (*Expression) ToAssignmentCondition

func (expr *Expression) ToAssignmentCondition() (*Condition, error)

func (*Expression) ToString

func (expr *Expression) ToString() (string, error)

func (*Expression) ToValue

func (expr *Expression) ToValue() (*Operand, error)

type FieldNode

type FieldNode struct {
	node.Node

	Name       NameNode         `@@`
	Type       NameNode         `@@`
	Repeated   bool             `@( "[" "]" )?`
	Optional   bool             `@( "?" )?`
	Attributes []*AttributeNode `( "{" @@+ "}" | @@+ )?`

	// Some fields are added implicitly after parsing the schema
	// For these fields this value is set to true so we can distinguish
	// them from fields defined by the user in the schema
	BuiltIn bool
}

func (*FieldNode) IsScalar

func (f *FieldNode) IsScalar() bool

type Ident

type Ident struct {
	node.Node

	Fragments []*IdentFragment `( @@ ( "." @@ )* )`
}

func (*Ident) IsContext

func (ident *Ident) IsContext() bool

func (*Ident) IsContextEnvField

func (ident *Ident) IsContextEnvField() bool

func (*Ident) IsContextHeadersField

func (ident *Ident) IsContextHeadersField() bool

func (*Ident) IsContextIdentity added in v0.370.1

func (ident *Ident) IsContextIdentity() bool

func (*Ident) IsContextIdentityId added in v0.370.1

func (ident *Ident) IsContextIdentityId() bool

func (*Ident) IsContextIsAuthenticatedField

func (ident *Ident) IsContextIsAuthenticatedField() bool

func (*Ident) IsContextNowField

func (ident *Ident) IsContextNowField() bool

func (*Ident) IsContextSecretField

func (ident *Ident) IsContextSecretField() bool

func (*Ident) LastFragment

func (ident *Ident) LastFragment() string

func (*Ident) ToString

func (ident *Ident) ToString() string

type IdentFragment

type IdentFragment struct {
	node.Node

	Fragment string `@Ident`
}

type JobInputNode

type JobInputNode struct {
	node.Node

	Name     NameNode `@@`
	Type     NameNode `@@`
	Repeated bool     `( @( "[" "]" )`
	Optional bool     `| @( "?" ))?`
}

type JobNode

type JobNode struct {
	node.Node

	Name     NameNode          `@@`
	Sections []*JobSectionNode `"{" @@* "}"`
}

type JobSectionNode

type JobSectionNode struct {
	node.Node

	Inputs    []*JobInputNode `( "inputs" "{" @@* "}"`
	Attribute *AttributeNode  `| @@)`
}

type MessageNode

type MessageNode struct {
	node.Node

	Name    NameNode     `@@`
	Fields  []*FieldNode `"{" @@* "}"`
	BuiltIn bool
}

func (*MessageNode) NameNode

func (e *MessageNode) NameNode() NameNode

type ModelNode

type ModelNode struct {
	node.Node

	Name     NameNode            `@@`
	Sections []*ModelSectionNode `"{" @@* "}"`
	BuiltIn  bool
}

func (*ModelNode) NameNode

func (e *ModelNode) NameNode() NameNode

type ModelSectionNode

type ModelSectionNode struct {
	node.Node

	Fields    []*FieldNode   `( "fields" "{" @@* "}"`
	Actions   []*ActionNode  `| "actions" "{" @@* "}"`
	Attribute *AttributeNode `| @@)`
}

type NameNode

type NameNode struct {
	node.Node

	Value string `@Ident`
}

type Operand

type Operand struct {
	node.Node

	Number  *int64   `  @('-'? Int)`
	Decimal *float64 `| @('-'? Float)`
	String  *string  `| @String`
	Null    bool     `| @"null"`
	True    bool     `| @"true"`
	False   bool     `| @"false"`
	Array   *Array   `| @@`
	Ident   *Ident   `| @@`
}

func (*Operand) IsLiteralType

func (o *Operand) IsLiteralType() (bool, string)

func (*Operand) ToString

func (o *Operand) ToString() string

func (*Operand) Type

func (o *Operand) Type() string

type Operator

type Operator struct {
	node.Node

	// Todo need to figure out how we can share with the consts below
	Symbol string `@( "=" "=" | "!" "=" | ">" "=" | "<" "=" | ">" | "<" | "not" "in" | "in" | "+" "=" | "-" "=" | "=")`
}

func (*Operator) ToString

func (o *Operator) ToString() string

type OrExpression

type OrExpression struct {
	node.Node

	And []*ConditionWrap `@@ ("and" @@)*`
}

type RoleNode

type RoleNode struct {
	node.Node

	Name     NameNode           `@@`
	Sections []*RoleSectionNode `"{" @@* "}"`
}

type RoleSectionNode

type RoleSectionNode struct {
	node.Node

	Domains []*DomainNode `("domains" "{" @@* "}"`
	Emails  []*EmailsNode `| "emails" "{" @@* "}")`
}

Jump to

Keyboard shortcuts

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