model

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FQNSplit2 added in v0.38.0

func FQNSplit2(fqn string) (string, string)

func FQNSplit3 added in v0.38.0

func FQNSplit3(fqn string) (string, string, string)

a.b.C.d a.c is the module name C is the element name d is the member name

Types

type DataParser

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

func NewDataParser

func NewDataParser(s *System) *DataParser

func (*DataParser) LintModule

func (p *DataParser) LintModule(module *Module) error

func (*DataParser) ParseFile

func (p *DataParser) ParseFile(file string) error

func (*DataParser) ParseJson

func (p *DataParser) ParseJson(data []byte) error

func (*DataParser) ParseYaml

func (p *DataParser) ParseYaml(data []byte) error

type Enum

type Enum struct {
	NamedNode `json:",inline" yaml:",inline"`
	Module    *Module       `json:"-" yaml:"-"`
	Members   []*EnumMember `json:"members" yaml:"members"`
}

Enum is an enumeration.

func NewEnum

func NewEnum(name string) *Enum

InitEnum creates a new Enum.

func (*Enum) CheckReservedWords added in v0.38.0

func (e *Enum) CheckReservedWords(langs []rkw.Lang)

CheckReservedWords checks the names of the enum.

func (*Enum) Default added in v0.9.0

func (e *Enum) Default() *EnumMember

Default returns the default member of the enum, which is the first member

func (*Enum) LookupMember added in v0.8.0

func (e *Enum) LookupMember(name string) *EnumMember

LookupMember returns the member with the given name, or nil if no such member exists.

func (*Enum) NoMembers added in v0.28.0

func (e *Enum) NoMembers() bool

NoMembers returns true if the enum has no members.

func (*Enum) Validate added in v0.33.0

func (e *Enum) Validate(mod *Module) error

Validate resolves all references in the enum.

type EnumMember

type EnumMember struct {
	NamedNode `json:",inline" yaml:",inline"`
	Value     int `json:"value" yaml:"value"`
}

EnumMember is a member of an enumeration.

func NewEnumMember

func NewEnumMember(name string, value int) *EnumMember

NewEnumMember creates a new EnumMember.

func (*EnumMember) CheckReservedWords added in v0.38.0

func (e *EnumMember) CheckReservedWords(langs []rkw.Lang)

CheckReservedWords checks the names of the enum member.

func (*EnumMember) Validate added in v0.33.0

func (e *EnumMember) Validate(m *Module) error

Validate resolves all references in the enum member.

type EnumScope added in v0.8.0

type EnumScope struct {
	// System is the root of all modules
	System *System
	// Module is the module that contains the interfaces, structs, and enums
	Module *Module
	// Enum is the enum that contains the values
	Enum *Enum
	// Features is the list of features that are enabled
	Features map[string]bool
	// Meta is the map of metadata
	Meta map[string]any
}

EnumScope is used by the generator to generate code for an enum

type Extends added in v0.38.0

type Extends struct {
	Name   string `json:"name" yaml:"name"`
	Import string `json:"import" yaml:"import"`
}

type Extern added in v0.38.0

type Extern struct {
	NamedNode `json:",inline" yaml:",inline"`
}

func NewExtern added in v0.38.0

func NewExtern(name string) *Extern

func (*Extern) IsEmpty added in v0.38.0

func (e *Extern) IsEmpty() bool

func (*Extern) Validate added in v0.38.0

func (e *Extern) Validate(m *Module) error

type Import

type Import struct {
	NamedNode `json:",inline" yaml:",inline"`
}

func NewImport

func NewImport(name string, version string) *Import

type Interface

type Interface struct {
	NamedNode  `json:",inline" yaml:",inline"`
	Module     *Module      `json:"-" yaml:"-"`
	Extends    Extends      `json:"extends" yaml:"extends"`
	Properties []*TypedNode `json:"properties" yaml:"properties"`
	Operations []*Operation `json:"operations" yaml:"operations"`
	Signals    []*Signal    `json:"signals" yaml:"signals"`
}

func NewInterface

func NewInterface(name string) *Interface

func (*Interface) CheckReservedWords added in v0.38.0

func (i *Interface) CheckReservedWords(langs []rkw.Lang)

func (*Interface) HasExtends added in v0.38.0

func (i *Interface) HasExtends() bool

func (Interface) LookupMember added in v0.38.0

func (i Interface) LookupMember(name string) *NamedNode

func (Interface) LookupOperation added in v0.6.0

func (i Interface) LookupOperation(name string) *Operation

func (Interface) LookupProperty

func (i Interface) LookupProperty(name string) *TypedNode

func (Interface) LookupSignal

func (i Interface) LookupSignal(name string) *Signal

func (Interface) NoMembers

func (i Interface) NoMembers() bool

func (Interface) NoOperations added in v0.6.0

func (i Interface) NoOperations() bool

func (Interface) NoProperties

func (i Interface) NoProperties() bool

func (Interface) NoSignals

func (i Interface) NoSignals() bool

func (*Interface) Validate added in v0.33.0

func (i *Interface) Validate(mod *Module) error

type InterfaceScope added in v0.8.0

type InterfaceScope struct {
	// System is the root of all modules
	System *System
	// Module is the module that contains the interfaces, structs, and enums
	Module *Module
	// Interface is the interface that contains the properties, operations and signals
	Interface *Interface
	// Features is the list of features that are enabled
	Features map[string]bool
	// Meta is the map of metadata
	Meta map[string]any
}

InterfaceScope is used by the generator to generate code for an interface

type Kind

type Kind string

Kind is an enumeration of the kinds of nodes.

const (
	KindSystem    Kind = "system"
	KindModule    Kind = "module"
	KindImport    Kind = "import"
	KindExtern    Kind = "extern"
	KindInterface Kind = "interface"
	KindProperty  Kind = "property"
	KindOperation Kind = "operation"
	KindParam     Kind = "param"
	KindReturn    Kind = "return"
	KindSignal    Kind = "signal"
	KindStruct    Kind = "struct"
	KindField     Kind = "field"
	KindEnum      Kind = "enum"
	KindMember    Kind = "member"
)

type KindType

type KindType string
const (
	TypeVoid      KindType = "void"
	TypeBool      KindType = "bool"
	TypeInt       KindType = "int"
	TypeInt32     KindType = "int32"
	TypeInt64     KindType = "int64"
	TypeFloat     KindType = "float"
	TypeFloat32   KindType = "float32"
	TypeFloat64   KindType = "float64"
	TypeString    KindType = "string"
	TypeExtern    KindType = "extern"
	TypeEnum      KindType = "enum"
	TypeStruct    KindType = "struct"
	TypeInterface KindType = "interface"
)

type Meta added in v0.38.0

type Meta map[string]interface{}

Meta is a map of string to interface It is used to store additional information in a node

func (Meta) AssertKey added in v0.38.0

func (m Meta) AssertKey(key string) (string, error)

AssertKey asserts that a key exists in the meta

func (Meta) Get added in v0.38.0

func (m Meta) Get(key string) interface{}

Get returns a value from the meta

func (Meta) GetBool added in v0.38.0

func (m Meta) GetBool(key string) bool

GetBool returns a bool value from the meta

func (Meta) GetFloat added in v0.38.0

func (m Meta) GetFloat(key string) float64

GetFloat returns a float value from the meta

func (Meta) GetInt added in v0.38.0

func (m Meta) GetInt(key string) int

GetInt returns an int value from the meta

func (Meta) GetString added in v0.38.0

func (m Meta) GetString(key string) string

GetString returns a string value from the meta

func (Meta) Has added in v0.38.0

func (m Meta) Has(key string) bool

Has returns true if the key exists in the meta

func (Meta) Set added in v0.38.0

func (m Meta) Set(key string, value interface{})

Set sets a key value in the meta

type Module

type Module struct {
	NamedNode  `json:",inline" yaml:",inline"`
	Version    Version      `json:"version" yaml:"version"`
	Imports    []*Import    `json:"imports" yaml:"imports"`
	Externs    []*Extern    `json:"externs" yaml:"externs"`
	Interfaces []*Interface `json:"interfaces" yaml:"interfaces"`
	Structs    []*Struct    `json:"structs" yaml:"structs"`
	Enums      []*Enum      `json:"enums" yaml:"enums"`
	Checksum   string       `json:"checksum" yaml:"checksum"`
	System     *System      `json:"-"` // reference to the parent system
}

func NewModule

func NewModule(n string, v string) *Module

func (*Module) CheckImport added in v0.38.0

func (m *Module) CheckImport(mName string) bool

func (*Module) CheckReservedWords added in v0.38.0

func (m *Module) CheckReservedWords(langs []rkw.Lang)

func (Module) LookupDefaultEnumMember added in v0.9.0

func (m Module) LookupDefaultEnumMember(mName, eName string) *EnumMember

LookupDefaultEnumMember looks up the enum by name and returns the default member

func (Module) LookupEnum

func (m Module) LookupEnum(mName, eName string) *Enum

LookupEnum looks up an enum by name

func (Module) LookupExtern added in v0.38.0

func (m Module) LookupExtern(mName, eName string) *Extern

func (Module) LookupInterface

func (m Module) LookupInterface(mName, iName string) *Interface

LookupInterface looks up an interface by name

func (Module) LookupLocalDefaultEnumMember added in v0.38.0

func (m Module) LookupLocalDefaultEnumMember(eName string) *EnumMember

LookupLocalDefaultEnumMember looks up the enum by name and returns the default member

func (Module) LookupLocalEnum added in v0.38.0

func (m Module) LookupLocalEnum(eName string) *Enum

func (Module) LookupLocalExtern added in v0.38.0

func (m Module) LookupLocalExtern(eName string) *Extern

func (Module) LookupLocalInterface added in v0.38.0

func (m Module) LookupLocalInterface(iName string) *Interface

LookupLocalInterface looks up an interface by name

func (Module) LookupLocalStruct added in v0.38.0

func (m Module) LookupLocalStruct(sName string) *Struct

LookupLocalStruct looks up a struct by name

func (Module) LookupNode

func (m Module) LookupNode(mName, nName string) *NamedNode

LookupNode looks up a named node by name

func (Module) LookupStruct

func (m Module) LookupStruct(mName, sName string) *Struct

LookupStruct looks up a struct by name

func (*Module) ShortName added in v0.38.0

func (m *Module) ShortName() string

ShortName returns the last part of the name, i.e. the module name

func (*Module) Validate added in v0.33.0

func (m *Module) Validate() error

type ModuleScope added in v0.8.0

type ModuleScope struct {
	// System is the root of all modules
	System *System
	// Module is the module that contains the interfaces, structs, and enums
	Module *Module
	// Features is the list of features that are enabled
	Features map[string]bool
	// Meta is the map of metadata
	Meta map[string]any
}

ModuleScope is used by the generator to generate code for a module

type NamedNode

type NamedNode struct {
	Id          uint   `json:"-" yaml:"-"` // internal id
	Name        string `json:"name" yaml:"name"`
	Kind        Kind   `json:"kind" yaml:"kind"`
	Description string `json:"description" yaml:"description"`
	Meta        Meta   `json:"meta" yaml:"meta"`
}

NamedNode is a base node with a name and a kind. { "name": "foo", "kind": "interface" }

func (*NamedNode) AsPath

func (n *NamedNode) AsPath() string

func (NamedNode) IsEmpty

func (n NamedNode) IsEmpty() bool

func (*NamedNode) ShortName

func (n *NamedNode) ShortName() string

func (*NamedNode) String

func (n *NamedNode) String() string

type Operation added in v0.6.0

type Operation struct {
	NamedNode `json:",inline" yaml:",inline"`
	Params    []*TypedNode `json:"params" yaml:"params"`
	Return    *TypedNode   `json:"return" yaml:"return"`
}

func NewOperation added in v0.6.0

func NewOperation(name string) *Operation

func (*Operation) CheckReservedWords added in v0.38.0

func (m *Operation) CheckReservedWords(langs []rkw.Lang)

func (*Operation) ParamNames added in v0.8.0

func (m *Operation) ParamNames() []string

func (*Operation) Validate added in v0.33.0

func (m *Operation) Validate(mod *Module) error

type Schema

type Schema struct {
	Type        string   `json:"type" yaml:"type"`
	Import      string   `json:"import" yaml:"import"`
	IsArray     bool     `json:"array" yaml:"array"`
	Module      *Module  `json:"-" yaml:"-"`
	KindType    KindType `json:"kindType" yaml:"kindType"`
	IsPrimitive bool     `json:"isPrimitive" yaml:"isPrimitive"`
	IsSymbol    bool     `json:"isSymbol" yaml:"isSymbol"`
	// contains filtered or unexported fields
}

TypeNode is a node with type information. { type: array, items: { type: string } }

func (Schema) Dump added in v0.38.0

func (s Schema) Dump() string

func (*Schema) GetEnum

func (s *Schema) GetEnum() *Enum

func (*Schema) GetExtern added in v0.38.0

func (s *Schema) GetExtern() *Extern

func (*Schema) GetInterface

func (s *Schema) GetInterface() *Interface

func (*Schema) GetStruct

func (s *Schema) GetStruct() *Struct

func (Schema) InnerSchema added in v0.38.0

func (s Schema) InnerSchema() Schema

func (Schema) IsEmpty

func (s Schema) IsEmpty() bool

IsEmpty returns true if the schema is empty

func (*Schema) IsEnum

func (s *Schema) IsEnum() bool

func (*Schema) IsExtern added in v0.38.0

func (s *Schema) IsExtern() bool

func (*Schema) IsImported added in v0.38.0

func (s *Schema) IsImported() bool

func (*Schema) IsInterface

func (s *Schema) IsInterface() bool

func (Schema) IsNotVoid added in v0.19.0

func (s Schema) IsNotVoid() bool

IsNotVoid returns true if the schema is not void

func (*Schema) IsStruct

func (s *Schema) IsStruct() bool

func (Schema) LookupEnum added in v0.38.0

func (s Schema) LookupEnum(mName, eName string) *Enum

func (Schema) LookupExtern added in v0.38.0

func (s Schema) LookupExtern(mName, eName string) *Extern

func (Schema) LookupInterface added in v0.38.0

func (s Schema) LookupInterface(mName, iName string) *Interface

func (Schema) LookupNode

func (s Schema) LookupNode(mName, nName string) *NamedNode

Lookup returns the node with the given name inside the module

func (Schema) LookupStruct added in v0.38.0

func (s Schema) LookupStruct(mName, sName string) *Struct

func (*Schema) ShortImportName added in v0.38.0

func (s *Schema) ShortImportName() string

func (Schema) System added in v0.38.0

func (s Schema) System() *System

func (*Schema) Validate added in v0.33.0

func (s *Schema) Validate(m *Module) error

Validate resolves all the types in the schema

type Signal

type Signal struct {
	NamedNode `json:",inline" yaml:",inline"`
	Params    []*TypedNode `json:"params" yaml:"params"`
}

func NewSignal

func NewSignal(name string) *Signal

func (*Signal) CheckReservedWords added in v0.38.0

func (s *Signal) CheckReservedWords(langs []rkw.Lang)

func (*Signal) Validate added in v0.33.0

func (s *Signal) Validate(m *Module) error

type Struct

type Struct struct {
	NamedNode `json:",inline" yaml:",inline"`
	Module    *Module      `json:"-" yaml:"-"`
	Fields    []*TypedNode `json:"fields" yaml:"fields"`
}

func NewStruct

func NewStruct(name string) *Struct

func (*Struct) CheckReservedWords added in v0.38.0

func (s *Struct) CheckReservedWords(langs []rkw.Lang)

func (*Struct) LookupField added in v0.8.0

func (s *Struct) LookupField(name string) *TypedNode

func (*Struct) NoFields added in v0.28.0

func (s *Struct) NoFields() bool

func (*Struct) Validate added in v0.33.0

func (s *Struct) Validate(m *Module) error

type StructScope added in v0.8.0

type StructScope struct {
	// System is the root of all modules
	System *System
	// Module is the module that contains the interfaces, structs, and enums
	Module *Module
	// Struct is the struct that contains the fields
	Struct *Struct
	// Features is the list of features that are enabled
	Features map[string]bool
	// Meta is the map of metadata
	Meta map[string]any
}

StructScope is used by the generator to generate code for a struct

type System

type System struct {
	NamedNode `json:",inline" yaml:",inline"`
	Modules   []*Module `json:"modules" yaml:"modules"`
	Checksum  string    `json:"checksum" yaml:"checksum"`
}

func NewSystem

func NewSystem(name string) *System

NewSystem creates a new system

func (*System) AddModule added in v0.38.0

func (s *System) AddModule(m *Module)

func (*System) CheckReservedWords added in v0.38.0

func (s *System) CheckReservedWords(langs []string)

func (System) LookupEnum

func (s System) LookupEnum(mName, eName string) *Enum

LookupEnum looks up an enum by module and enum name

func (System) LookupExtern added in v0.38.0

func (s System) LookupExtern(mName, eName string) *Extern

LookupExtern looks up an extern by name

func (System) LookupField added in v0.38.0

func (s System) LookupField(mName, sName, fName string) *TypedNode

func (System) LookupInterface

func (s System) LookupInterface(mName string, iName string) *Interface

LookupInterface looks up an interface by module and interface name

func (System) LookupModule

func (s System) LookupModule(name string) *Module

LookupModule looks up a module by name

func (System) LookupNode added in v0.38.0

func (s System) LookupNode(fqn string) *NamedNode

LookupNode looks up a node by module and node name

func (System) LookupOperation added in v0.6.0

func (s System) LookupOperation(mName, iName, oName string) *Operation

func (System) LookupProperty

func (s System) LookupProperty(mName, iName, pName string) *TypedNode

func (System) LookupSignal

func (s System) LookupSignal(mName, iName, sName string) *Signal

func (System) LookupStruct

func (s System) LookupStruct(mName, sName string) *Struct

LookupStruct looks up a struct by module and struct name

func (*System) Validate added in v0.33.0

func (s *System) Validate() error

type SystemScope added in v0.8.0

type SystemScope struct {
	// System is the root of all modules
	System *System
	// Features is the list of features that are enabled
	Features map[string]bool
	// Meta is the map of metadata
	Meta map[string]any
}

SystemScope is used by the generator to generate code for a system

type TypedNode

type TypedNode struct {
	NamedNode  `json:",inline" yaml:",inline"`
	Schema     `json:",inline" yaml:",inline"`
	IsReadOnly bool `json:"readonly" yaml:"readonly"`
}

TypedNode is a base node with a schema type. { name: "foo", kind: "property", type: "string" }

func NewTypedNode

func NewTypedNode(n string, k Kind) *TypedNode

NewTypedNode creates a new typed node

func (*TypedNode) CheckReservedWords added in v0.38.0

func (t *TypedNode) CheckReservedWords(langs []rkw.Lang)

func (*TypedNode) IsFloat added in v0.20.0

func (t *TypedNode) IsFloat() bool

IsFloat returns true if the schema is a float (e.g. float, float32, float64)

func (*TypedNode) IsInt added in v0.20.0

func (t *TypedNode) IsInt() bool

func (*TypedNode) IsVoid added in v0.9.0

func (t *TypedNode) IsVoid() bool

IsVoid returns true if the schema is void

func (TypedNode) TypeName added in v0.8.0

func (t TypedNode) TypeName() string

TypeName returns the name of the type, e.g. String, Int32, Int32Array, InterfaceFoo, StructBar, EnumBaz Can be used to call conversion functions based on type name

func (*TypedNode) Validate added in v0.33.0

func (t *TypedNode) Validate(m *Module) error

Validate resolves all the types in the schema

type Version added in v0.13.13

type Version string

func (Version) Major added in v0.13.13

func (v Version) Major() int

func (Version) Minor added in v0.13.13

func (v Version) Minor() int

func (Version) Patch added in v0.13.13

func (v Version) Patch() int

func (Version) String added in v0.13.13

func (v Version) String() string

Jump to

Keyboard shortcuts

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