parser

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Mint Parser

This code is almost completely taken from https://github.com/alecthomas/participle/tree/master/_examples/protobuf with a few modifications.

It is, therefore, licenced under the same terms.

My sincere and heartfelt thanks go to github user alecthomas for their work.

Changes

The following changes have been made:

  1. Mint does not support services, and so these are removed
  2. Mint does not support embedded messages, and so these are removed
  3. Mint has different base types, and these are reflected accordingly
  4. Mint has annotations, which protobuf doesn't

Documentation

Overview

nolint: govet, golint

Index

Constants

This section is empty.

Variables

View Source
var (
	Scalars = map[string]bool{
		"string":   true,
		"datetime": true,
		"uuid":     true,

		"int16":   true,
		"int32":   true,
		"int64":   true,
		"float32": true,
		"float64": true,
		"byte":    true,
		"bool":    true,
	}
)

Functions

This section is empty.

Types

type AST

type AST struct {
	Types []AnnotatedType
	Enums []Enum
}

func Parse

func Parse(fn string, in io.Reader) (*AST, error)

func ParseDir

func ParseDir(dir string) (*AST, error)

func ParseFile

func ParseFile(fn string) (*AST, error)

type AnnotatedEntry

type AnnotatedEntry struct {
	Field

	DocString       string
	Validations     []Validation
	Transformations []Transformation
}

func (*AnnotatedEntry) AppendDocString

func (ae *AnnotatedEntry) AppendDocString(s string)

func (*AnnotatedEntry) AppendTransformation

func (ae *AnnotatedEntry) AppendTransformation(v Transformation)

func (*AnnotatedEntry) AppendValidation

func (ae *AnnotatedEntry) AppendValidation(v Validation)

func (*AnnotatedEntry) IsValidType

func (ae *AnnotatedEntry) IsValidType(names map[string][]lexer.Position) error

IsValidType returns an error unless:

  1. The specified type starts with a lower case and exists in our base scalars map; or
  2. It starts with an upper case and exists as a Type or Enum in our AST

type AnnotatedType

type AnnotatedType struct {
	Pos     lexer.Position
	Name    string
	Entries []AnnotatedEntry
}

type Annotation

type Annotation struct {
	Pos lexer.Position

	Provider string `"+" @Ident`
	Type     string `":" @Ident ":"`

	Func  string `( @Ident`
	Value string `| @String )`
}

type DataType

type DataType struct {
	Pos lexer.Position

	FixedSizeSlice *FixedSizedSliceType `@@`
	Slice          *SliceType           `| @@`
	Map            *MapType             `| @@`
	Scalar         *Scalar              `| @@`
}

type Document

type Document struct {
	Pos lexer.Position

	Entries []*Entry `( @@ ";"* )*`
}

type Entry

type Entry struct {
	Pos lexer.Position

	Type *Type ` @@`
	Enum *Enum `| @@`
}

type Enum

type Enum struct {
	Pos lexer.Position

	Name   string       `"enum" @Ident`
	Values []*EnumEntry `"{" ( @@ ( ";" )* )* "}"`
}

type EnumEntry

type EnumEntry struct {
	Pos lexer.Position

	Value *EnumValue `  @@`
}

type EnumValue

type EnumValue struct {
	Pos lexer.Position

	Key string `@Ident`
}

type Field

type Field struct {
	Pos lexer.Position

	DataType *DataType `@@`
	Name     string    `@Ident`
	Tag      int       `"=" @Int`
}

type FixedSizedSliceType

type FixedSizedSliceType struct {
	Pos lexer.Position

	Size int    `"[" @Int "]"`
	Type string `@Ident`
}

type MapType

type MapType struct {
	Pos lexer.Position

	Key   string `"map" "<" @Ident`
	Value string `"," @Ident ">"`
}

type MessageEntry

type MessageEntry struct {
	Pos lexer.Position

	Annotation *Annotation `@@`
	Field      *Field      `| @@  ";"*`
}

type Scalar

type Scalar struct {
	Pos lexer.Position

	Type string `@Ident`
}

type SliceType

type SliceType struct {
	Pos lexer.Position

	Type string `"[" "]" @Ident`
}

type Transformation

type Transformation struct {
	IsCustom bool
	Function string
}

type Type

type Type struct {
	Pos lexer.Position

	Name    string          `"type" @Ident`
	Entries []*MessageEntry `"{" @@* "}"`
}

type Validation

type Validation struct {
	IsCustom bool
	Function string
}

Jump to

Keyboard shortcuts

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