schema

package
v0.0.0-...-cc25aa6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: MIT, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TypeNames = []string{"string", "byte",
	"uint8", "int8",
	"uint16", "int16",
	"uint32", "int32",
	"uint64", "int64",
	"float32", "float64", "timestamp",
	"tuple", "int", "float", "bool",
}

Reserved Types

Functions

func LoadDirectory

func LoadDirectory(dir string, parser Parser) (err error)

LoadDirectory reads all the schema files from a directory.

Types

type Config

type Config struct {
	PackageRootDir string
}

Config simply stores the parsing configuration.

type Field

type Field struct {
	IsRequired bool
	IsArray    bool
	Type       string
	Name       string
}

Field is the lowest level of granularity in a schema. Fields belong to a single Version within a Type. They are effectively immutable and should not be changed.

type Handler

type Handler func(Token)

Handler is simpley a function which takes a single Token argument

type Import

type Import struct {
	PackageName string
	TypeNames   []string
}

Import references one or more Types from another Package

type Lexer

type Lexer struct {
	Name string // Used to error reports

	Start int // start position of this item
	Pos   int // current position in the input
	Width int // width of last rune read
	// contains filtered or unexported fields
}

Lexer holds the state of the scanner

func NewLexer

func NewLexer(name, input string, h Handler) *Lexer

NewLexer creates a new scanner from the input

func (*Lexer) LineNum

func (l *Lexer) LineNum() int

LineNum returns the current line based on the data processed so far

func (*Lexer) Offset

func (l *Lexer) Offset() int

Offset determines the character offset from the beginning of the current line

type Package

type Package struct {
	Name    string
	Imports []Import
	Types   []Type
}

Package contains an entire schema document.

func LoadFile

func LoadFile(filename string, parser Parser) (Package, error)

LoadFile reads a schema document from a file.

func LoadPackage

func LoadPackage(parser Parser, name, text string) (Package, error)

LoadPackage parses a text string.

type PackageList

type PackageList interface {
	Add(pkg Package)
	Remove(pkg string)
	Get(name string) (Package, bool)
}

PackageList is an interface for a package registry.

func NewPackageList

func NewPackageList() PackageList

NewPackageList creates a new package registry

type Parser

type Parser interface {
	Parse(name, text string) (Package, error)
}

func NewParser

func NewParser(pkgList PackageList) Parser

type SyntaxError

type SyntaxError struct {
	Message string
}

SyntaxError represents an error while parsing the schema

func (SyntaxError) Error

func (s SyntaxError) Error() string

type Token

type Token struct {
	Type  TokenType // Type, such as itemNumber
	Value string    // Value, such as "23.2"
}

Token struct

func (Token) String

func (t Token) String() string

Used to print tokens

type TokenType

type TokenType uint8

TokenType enum

const (
	TokenError             TokenType = iota // 0 Lexer Error
	TokenEOF                                // 1 End of File
	TokenComment                            // 2 Comment
	TokenTypeDef                            // 3 Type keyword
	TokenVersion                            // 4 Version keyword
	TokenValueType                          // 5 Value type ID (string, uint8)
	TokenRequired                           // 6 Required Keyword
	TokenOptional                           // 7 Optional Keyword
	TokenVersionNumber                      // 8 Version ID
	TokenOpenCurlyBracket                   // 9 Left {
	TokenCloseCurlyBracket                  // 10 Right }
	TokenOpenArrayBracket                   // 11 Open Array [
	TokenCloseArrayBracket                  // 12 Close Array ]
	TokenIdentifier                         // 13 Message or Field Name
	TokenComma                              // 14 Comma
	TokenPeriod                             // 15 Period
	TokenImport                             // 16 Import keyword
	TokenFrom                               // 17 From keyword
	TokenAs                                 // 18 As keyword
	TokenPackage                            // 19 Package keyword
	TokenPackageName                        // 20 Package name
	TokenAsterisk                           // 21 Package all
)

Lex items

type Type

type Type struct {
	Name     string
	Versions []Version
}

Type represents a data type. It encapsulates several versions, each with their own fields.

type Version

type Version struct {
	Number int
	Fields []Field
}

Version is the only construct for adding one or more Fields to a Type.

Jump to

Keyboard shortcuts

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