parser

package
v0.11.1-meitner1.4-fix Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when an Object is not found.

Functions

func Split

func Split(src string) (entries []string)

Split splits the camelcase word and returns a list of words. It also supports digits. Both lower camel case and upper camel case are supported. For more info please check: http://en.wikipedia.org/wiki/CamelCase

Examples

"" =>                     [""]
"lowercase" =>            ["lowercase"]
"Class" =>                ["Class"]
"MyClass" =>              ["My", "Class"]
"MyC" =>                  ["My", "C"]
"HTML" =>                 ["HTML"]
"PDFLoader" =>            ["PDF", "Loader"]
"AString" =>              ["A", "String"]
"SimpleXMLParser" =>      ["Simple", "XML", "Parser"]
"vimRPCPlugin" =>         ["vim", "RPC", "Plugin"]
"GL11Version" =>          ["GL", "11", "Version"]
"99Bottles" =>            ["99", "Bottles"]
"May5" =>                 ["May", "5"]
"BFG9000" =>              ["BFG", "9000"]
"BöseÜberraschung" =>     ["Böse", "Überraschung"]
"Two  spaces" =>          ["Two", "  ", "spaces"]
"BadUTF8\xe2\xe2\xa1" =>  ["BadUTF8\xe2\xe2\xa1"]

Splitting rules

  1. If string is not valid UTF-8, return it without splitting as single item array.
  2. Assign all unicode characters into one of 4 sets: lower case letters, upper case letters, numbers, and all other characters.
  3. Iterate through characters of string, introducing splits between adjacent characters that belong to different sets.
  4. Iterate through array of split strings, and if a given string is upper case: if subsequent string is lower case: move last character of upper case string to beginning of lower case string
Example
for _, c := range []string{
	"",
	"lowercase",
	"Class",
	"MyClass",
	"MyC",
	"HTML",
	"PDFLoader",
	"AString",
	"SimpleXMLParser",
	"vimRPCPlugin",
	"GL11Version",
	"99Bottles",
	"May5",
	"BFG9000",
	"BöseÜberraschung",
	"Two  spaces",
	"BadUTF8\xe2\xe2\xa1",
} {
	fmt.Printf("%#v => %#v\n", c, Split(c))
}
Output:

"" => []string{}
"lowercase" => []string{"lowercase"}
"Class" => []string{"Class"}
"MyClass" => []string{"My", "Class"}
"MyC" => []string{"My", "C"}
"HTML" => []string{"HTML"}
"PDFLoader" => []string{"PDF", "Loader"}
"AString" => []string{"A", "String"}
"SimpleXMLParser" => []string{"Simple", "XML", "Parser"}
"vimRPCPlugin" => []string{"vim", "RPC", "Plugin"}
"GL11Version" => []string{"GL", "11", "Version"}
"99Bottles" => []string{"99", "Bottles"}
"May5" => []string{"May", "5"}
"BFG9000" => []string{"BFG", "9000"}
"BöseÜberraschung" => []string{"Böse", "Überraschung"}
"Two  spaces" => []string{"Two", "  ", "spaces"}
"BadUTF8\xe2\xe2\xa1" => []string{"BadUTF8\xe2\xe2\xa1"}

Types

type Definition

type Definition struct {
	// PackageName is the name of the package.
	PackageName string `json:"packageName"`
	// Services are the services described in this definition.
	Services []Service `json:"services"`
	// Objects are the structures that are used throughout this definition.
	Objects []Object `json:"objects"`
	// Imports is a map of Go imports that should be imported into
	// Go code.
	Imports map[string]string `json:"imports"`
}

Definition describes an Oto definition.

func (*Definition) Example

func (d *Definition) Example(o Object) (map[string]interface{}, error)

Example generates an object that is a realistic example of this object. Examples are read from the docs. This is experimental.

func (*Definition) ExampleJSON

func (d *Definition) ExampleJSON(o Object) ([]byte, error)

func (*Definition) MethodHasPagination

func (d *Definition) MethodHasPagination(method Method) bool

MethodHasPagination checks if the object given by name, has pagination. The object has pagination if it is an output object and has a field named TotalCount of the type int64 and the input object has query.

func (*Definition) Object

func (d *Definition) Object(name string) (*Object, error)

Object looks up an object by name. Returns ErrNotFound error if it cannot find it.

func (*Definition) ObjectIsInput

func (d *Definition) ObjectIsInput(name string) bool

ObjectIsInput gets whether this object is a method input (request) type or not.\ Returns true if any method.InputObject.ObjectName matches name.

func (*Definition) ObjectIsOutput

func (d *Definition) ObjectIsOutput(name string) bool

ObjectIsOutput gets whether this object is a method output (response) type or not. Returns true if any method.OutputObject.ObjectName matches name.

type Field

type Field struct {
	Name           string              `json:"name"`
	NameLowerCamel string              `json:"nameLowerCamel"`
	NameLowerSnake string              `json:"nameLowerSnake"`
	Type           FieldType           `json:"type"`
	OmitEmpty      bool                `json:"omitEmpty"`
	Comment        string              `json:"comment"`
	Tag            string              `json:"tag"`
	ParsedTags     map[string]FieldTag `json:"parsedTags"`
	Example        interface{}         `json:"example"`
	// Metadata are typed key/value pairs extracted from the
	// comments.
	Metadata map[string]interface{} `json:"metadata"`
}

Field describes the field inside an Object.

type FieldTag

type FieldTag struct {
	// Value is the value of the tag.
	Value string `json:"value"`
	// Options are the options for the tag.
	Options []string `json:"options"`
}

FieldTag is a parsed tag. For more information, see Struct Tags in Go.

type FieldType

type FieldType struct {
	TypeID     string `json:"typeID"`
	TypeName   string `json:"typeName"`
	ObjectName string `json:"objectName"`
	// CleanObjectName is the ObjectName with * removed
	// for pointer types.
	CleanObjectName      string `json:"cleanObjectName"`
	ObjectNameLowerCamel string `json:"objectNameLowerCamel"`
	ObjectNameLowerSnake string `json:"objectNameLowerSnake"`
	Multiple             bool   `json:"multiple"`
	MultipleTimes        []struct{}
	Package              string       `json:"package"`
	IsObject             bool         `json:"isObject"`
	JSType               string       `json:"jsType"`
	TSType               string       `json:"tsType"`
	SwiftType            string       `json:"swiftType"`
	IsMap                bool         `json:"is_map"`
	Map                  FieldTypeMap `json:"map"`
}

FieldType holds information about the type of data that this Field stores.

func (FieldType) IsOptional

func (f FieldType) IsOptional() bool

IsOptional returns true for pointer types (optional).

type FieldTypeMap

type FieldTypeMap struct {
	KeyType           string
	KeyTypeJS         string `json:"keyTypeJS"`
	KeyTypeTS         string `json:"keyTypeTS"`
	KeyTypeSwift      string `json:"keyTypeSwift"`
	ElementType       string `json:"ElementType"`
	ElementTypeJS     string `json:"elementTypeJS"`
	ElementTypeTS     string `json:"elementTypeTS"`
	ElementTypeSwift  string `json:"elementTypeSwift"`
	ElementIsMultiple bool   `json:"elementIsMultiple"`
}

type Method

type Method struct {
	Name           string    `json:"name"`
	NameLowerCamel string    `json:"nameLowerCamel"`
	NameLowerSnake string    `json:"nameLowerSnake"`
	InputObject    FieldType `json:"inputObject"`
	OutputObject   FieldType `json:"outputObject"`
	Comment        string    `json:"comment"`
	// Metadata are typed key/value pairs extracted from the
	// comments.
	Metadata map[string]interface{} `json:"metadata"`
}

Method describes a method that a Service can perform.

type Object

type Object struct {
	TypeID   string  `json:"typeID"`
	Name     string  `json:"name"`
	Imported bool    `json:"imported"`
	Fields   []Field `json:"fields"`
	Comment  string  `json:"comment"`
	// Metadata are typed key/value pairs extracted from the
	// comments.
	Metadata map[string]interface{} `json:"metadata"`
}

Object describes a data structure that is part of this definition.

type Parser

type Parser struct {
	Verbose bool

	ExcludeInterfaces []string
	// contains filtered or unexported fields
}

Parser parses Oto Go definition packages.

func New

func New(patterns ...string) *Parser

New makes a fresh parser using the specified patterns. The patterns should be the args passed into the tool (after any flags) and will be passed to the underlying build system.

func (*Parser) Parse

func (p *Parser) Parse() (Definition, error)

Parse parses the files specified, returning the definition.

type Service

type Service struct {
	Name    string   `json:"name"`
	Methods []Method `json:"methods"`
	Comment string   `json:"comment"`
	// Metadata are typed key/value pairs extracted from the
	// comments.
	Metadata map[string]interface{} `json:"metadata"`
}

Service describes a service, akin to an interface in Go.

Jump to

Keyboard shortcuts

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