schema

package
v0.0.0-...-ab86bc2 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SchemaFor

func SchemaFor(val interface{}) (string, error)

Given a pointer to a value, returns the BARE schema language representation for that value type.

var example string schema.SchemaFor(&example); // "string"

Given a struct type, if the "bare" tag is found on its fields, it will be used as the field name in the generated schema.

func SchemaForType

func SchemaForType(t reflect.Type) (string, error)

Given a reflect.Type, returns the BARE schema language representation for that type. See SchemaFor for details.

Types

type ArrayType

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

func (*ArrayType) Kind

func (at *ArrayType) Kind() TypeKind

func (*ArrayType) Length

func (at *ArrayType) Length() uint

func (*ArrayType) Member

func (at *ArrayType) Member() Type

type DataType

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

func (*DataType) Kind

func (dt *DataType) Kind() TypeKind

func (*DataType) Length

func (dt *DataType) Length() uint

type EnumValue

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

func (*EnumValue) Name

func (ev *EnumValue) Name() string

func (*EnumValue) Value

func (ev *EnumValue) Value() uint

type ErrUnexpectedToken

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

Returned when the lexer encounters an unexpected token

func (*ErrUnexpectedToken) Error

func (e *ErrUnexpectedToken) Error() string

type ErrUnknownToken

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

Returned when the lexer encounters an unexpected character

func (*ErrUnknownToken) Error

func (e *ErrUnknownToken) Error() string

type MapType

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

func (*MapType) Key

func (mt *MapType) Key() Type

func (*MapType) Kind

func (mt *MapType) Kind() TypeKind

func (*MapType) Value

func (mt *MapType) Value() Type

type NamedUserType

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

This has not been compared with the list of user-defined types and is not guaranteed to actually exist; the consumer of this type must perform this lookup itself.

func (*NamedUserType) Kind

func (nut *NamedUserType) Kind() TypeKind

func (*NamedUserType) Name

func (nut *NamedUserType) Name() string

type OptionalType

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

func (*OptionalType) Kind

func (ot *OptionalType) Kind() TypeKind

func (*OptionalType) Subtype

func (ot *OptionalType) Subtype() Type

type PrimitiveType

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

func (*PrimitiveType) Kind

func (pt *PrimitiveType) Kind() TypeKind

type Scanner

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

A scanner for reading lexographic tokens from a BARE schema language document.

func NewScanner

func NewScanner(reader io.Reader) *Scanner

Creates a new BARE schema language scanner for the given reader.

func (*Scanner) Next

func (sc *Scanner) Next() (Token, error)

Returns the next token from the reader. If the token has a string associated with it (e.g. UserTypeName, Name, and Integer), the second return value is set to that string.

func (*Scanner) PushBack

func (sc *Scanner) PushBack(tok Token)

Pushes a token back to the scanner, causing it to be returned on the next call to Next.

type SchemaType

type SchemaType interface {
	Name() string
}

func Parse

func Parse(reader io.Reader) ([]SchemaType, error)

Parses a BARE schema definition language document from the given reader and returns a list of the user-defined types it specifies.

type SchemaTypeKind

type SchemaTypeKind int

type StructField

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

func (*StructField) Name

func (sf *StructField) Name() string

func (*StructField) Type

func (sf *StructField) Type() Type

type StructType

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

func (*StructType) Fields

func (st *StructType) Fields() []StructField

func (*StructType) Kind

func (st *StructType) Kind() TypeKind

type Token

type Token struct {
	Token TokenKind
	Value string
}

A single lexographic token from a schema language token stream

func (Token) String

func (t Token) String() string

type TokenKind

type TokenKind int
const (
	TTYPE TokenKind = iota
	TENUM

	// NAME is used for name, user-type-name, and enum-value-name.
	// Distinguishing between these requires context.
	TNAME
	TINTEGER

	TUINT
	TU8
	TU16
	TU32
	TU64
	TINT
	TI8
	TI16
	TI32
	TI64
	TF32
	TF64
	TBOOL
	TSTRING
	TDATA
	TVOID
	TMAP
	TOPTIONAL

	// <
	TLANGLE
	// >
	TRANGLE
	// {
	TLBRACE
	// }
	TRBRACE
	// [
	TLBRACKET
	// ]
	TRBRACKET
	// (
	TLPAREN
	// )
	TRPAREN
	// |
	TPIPE
	// =
	TEQUAL
	// :
	TCOLON
)

type Type

type Type interface {
	Kind() TypeKind
}

type TypeKind

type TypeKind int
const (
	UINT TypeKind = iota
	U8
	U16
	U32
	U64
	INT
	I8
	I16
	I32
	I64
	F32
	F64
	Bool
	String
	Void
	// data
	Data
	// data<length>
	DataFixed
	// [len]type
	Array
	// []type
	Slice
	// optional<type>
	Optional
	// data<len>
	DataArray
	// data
	DataSlice
	// map[type]type
	Map
	// (type | type | ...)
	Union
	// { fields... }
	Struct
	// Named user type
	UserType
)

func (TypeKind) String

func (tk TypeKind) String() string

type UnionSubtype

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

func (*UnionSubtype) Tag

func (ust *UnionSubtype) Tag() uint64

func (*UnionSubtype) Type

func (ust *UnionSubtype) Type() Type

type UnionType

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

func (*UnionType) Kind

func (ut *UnionType) Kind() TypeKind

func (*UnionType) Types

func (ut *UnionType) Types() []UnionSubtype

type UserDefinedEnum

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

func (*UserDefinedEnum) Kind

func (ude *UserDefinedEnum) Kind() TypeKind

func (*UserDefinedEnum) Name

func (ude *UserDefinedEnum) Name() string

func (*UserDefinedEnum) Values

func (ude *UserDefinedEnum) Values() []EnumValue

type UserDefinedType

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

func (*UserDefinedType) Name

func (udt *UserDefinedType) Name() string

func (*UserDefinedType) Type

func (udt *UserDefinedType) Type() Type

Jump to

Keyboard shortcuts

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