Documentation ¶
Index ¶
- Constants
- func LowercaseFirstLetter(s string) string
- func Parse(filename string, b []byte, opts ...Option) (interface{}, error)
- func ParseFile(filename string, opts ...Option) (interface{}, error)
- func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error)
- type Annotation
- type Annotations
- type Auditor
- type Constant
- type Enum
- type EnumValue
- type Field
- type FieldModifier
- type Frugal
- func (f *Frugal) ConstantFromField(field *Field, value interface{}) *Constant
- func (f *Frugal) ContainsFrugalDefinitions() bool
- func (f *Frugal) ContextFromIdentifier(identifier Identifier) *IdentifierContext
- func (f *Frugal) DataStructures() []*Struct
- func (f *Frugal) FindStruct(typ *Type) *Struct
- func (f *Frugal) Include(name string) *Include
- func (f *Frugal) IsEnum(t *Type) bool
- func (f *Frugal) IsStruct(t *Type) bool
- func (f *Frugal) IsUnion(t *Type) bool
- func (f *Frugal) Namespace(scope string) *Namespace
- func (f *Frugal) NamespaceForInclude(include, lang string) *Namespace
- func (f *Frugal) OrderedIncludes() []Include
- func (f *Frugal) ReferencedIncludes() ([]*Include, error)
- func (f *Frugal) ReferencedInternals() []string
- func (f *Frugal) ReferencedScopeIncludes() ([]*Include, error)
- func (f *Frugal) ReferencedServiceIncludes() ([]*Include, error)
- func (f *Frugal) UnderlyingType(t *Type) *Type
- type Identifier
- type IdentifierContext
- type IdentifierType
- type Include
- type KeyValue
- type Method
- type Namespace
- type Operation
- type Option
- type Scope
- type ScopePrefix
- type Service
- type Struct
- type StructType
- type Type
- type TypeDef
- type ValidationLogger
Constants ¶
const ( // VendorAnnotation is used on namespace definitions to indicate to any // consumers of the IDL where the generated code is vendored so that // consumers can generate code that points to it. This cannot be used with // "*" namespaces since it is language-dependent. Consumers then use the // "vendor" annotation on includes they wish to vendor. The value provided // on the include-side "vendor" annotation, if any, is ignored. // // When an include is annotated with "vendor", Frugal will skip generating // the include if -use-vendor is set since this flag indicates intention to // use the vendored code as advertised by the "vendor" annotation. // // If no location is specified by the "vendor" annotation, the behavior is // defined by the language generator. VendorAnnotation = "vendor" // DeprecatedAnnotation is the annotation to mark a service method as deprecated. DeprecatedAnnotation = "deprecated" )
Supported generator annotations.
const ( StructTypeStruct = iota StructTypeException StructTypeUnion )
Valid StructTypes.
Variables ¶
This section is empty.
Functions ¶
func LowercaseFirstLetter ¶
LowercaseFirstLetter of the string.
Types ¶
type Annotation ¶
Annotation is key-value metadata attached to an IDL definition.
type Annotations ¶
type Annotations []*Annotation
Annotations is the collection of Annotations present on an IDL definition.
func (Annotations) Deprecated ¶
func (a Annotations) Deprecated() (string, bool)
Deprecated returns true if the "deprecated" annotation is present and its associated value, if any.
func (Annotations) DeprecationValue ¶
func (a Annotations) DeprecationValue() string
DeprecationValue returns the value of the "deprecated" annotation.
func (Annotations) Get ¶
func (a Annotations) Get(name string) (string, bool)
Get returns true if the given annotation name is present and its associated value, if any.
func (Annotations) IsDeprecated ¶
func (a Annotations) IsDeprecated() bool
IsDeprecated returns true if the "deprecated" annotation is present.
func (Annotations) Vendor ¶
func (a Annotations) Vendor() (string, bool)
Vendor returns true if the "vendor" annotation is present and its associated value, if any.
type Auditor ¶
type Auditor struct {
// contains filtered or unexported fields
}
Auditor provides an interface for auditing one frugal file against another for breaking API changes.
func NewAuditor ¶
func NewAuditor() *Auditor
NewAuditor constructs an auditor that logs warnings and errors to standard output
func NewAuditorWithLogger ¶
func NewAuditorWithLogger(logger ValidationLogger) *Auditor
NewAuditorWithLogger constructs an auditor which uses the given logger to log warnings and errors
type Constant ¶
type Constant struct { Comment []string Name string Type *Type Value interface{} Annotations Annotations }
Constant represents an IDL constant.
type Enum ¶
type Enum struct { Comment []string Name string Values []*EnumValue Annotations Annotations }
Enum represents an IDL enum.
type EnumValue ¶
type EnumValue struct { Comment []string Name string Value int Annotations Annotations }
EnumValue represents an IDL enum value.
type Field ¶
type Field struct { Comment []string ID int Name string Modifier FieldModifier Type *Type Default interface{} Annotations Annotations }
Field represents an IDL field on a struct or method.
func FieldFromType ¶
FieldFromType returns a new Field from the given Type and name.
type FieldModifier ¶
type FieldModifier int
FieldModifier represents a Frugal IDL field modifier (required, optional default).
const ( // Required indicates always written for the writer and must read or error // for the reader. Required FieldModifier = iota // Optional indicates written if set for the writer and read if present for // the reader. Optional // Default indicates always written for the writer and read if present for // the reader. Default )
func (*FieldModifier) String ¶
func (f *FieldModifier) String() string
type Frugal ¶
type Frugal struct { Name string File string Dir string Path string ParsedIncludes map[string]*Frugal Includes []*Include Typedefs []*TypeDef Namespaces []*Namespace Constants []*Constant Enums []*Enum Structs []*Struct Exceptions []*Struct Unions []*Struct Services []*Service Scopes []*Scope // contains filtered or unexported fields }
Frugal contains the complete IDL parse tree.
func ParseFrugal ¶
ParseFrugal parses the given Frugal file into its semantic representation.
func (*Frugal) ConstantFromField ¶
ConstantFromField returns a new Constant from the given Field and value.
func (*Frugal) ContainsFrugalDefinitions ¶
ContainsFrugalDefinitions indicates if the parse tree contains any scope or service definitions.
func (*Frugal) ContextFromIdentifier ¶
func (f *Frugal) ContextFromIdentifier(identifier Identifier) *IdentifierContext
ContextFromIdentifier returns a IdentifierContext for the given Identifier.
func (*Frugal) DataStructures ¶
DataStructures returns a slice containing all structs, exceptions, and unions.
func (*Frugal) FindStruct ¶
func (*Frugal) NamespaceForInclude ¶
NamespaceForInclude returns the Namespace for the given include name and language.
func (*Frugal) OrderedIncludes ¶
OrderedIncludes returns the Includes in order, sorted by the include name.
func (*Frugal) ReferencedIncludes ¶
ReferencedIncludes returns a slice containing the referenced includes which will need to be imported in generated code.
func (*Frugal) ReferencedInternals ¶
ReferencedInternals returns a slice containing the referenced internals which will need to be imported in generated code.
func (*Frugal) ReferencedScopeIncludes ¶
ReferencedScopeIncludes returns a slice containing the referenced includes which will need to be imported in generated code for scopes.
func (*Frugal) ReferencedServiceIncludes ¶
ReferencedServiceIncludes returns a slice containing the referenced includes which will need to be imported in generated code for services.
func (*Frugal) UnderlyingType ¶
UnderlyingType follows any typedefs to get the base IDL type.
type IdentifierContext ¶
type IdentifierContext struct { Type IdentifierType Constant *Constant Enum *Enum EnumValue *EnumValue Include *Frugal }
IdentifierContext gives information about the identifier for a given contextual reference
type IdentifierType ¶
type IdentifierType uint8
IdentifierType indicates if a Identifier is a local/include constant/enum
const ( NonIdentifier IdentifierType = iota LocalConstant LocalEnum IncludeConstant IncludeEnum )
type Include ¶
type Include struct { Name string Value string Annotations Annotations }
Include represents an IDL file include.
type KeyValue ¶
type KeyValue struct {
Key, Value interface{}
}
KeyValue is a key-value pair.
func (*KeyValue) KeyToString ¶
type Method ¶
type Method struct { Comment []string Name string Oneway bool ReturnType *Type Arguments []*Field Exceptions []*Field Annotations Annotations }
Method represents an IDL service method.
type Namespace ¶
type Namespace struct { Scope string Value string Annotations Annotations }
Namespace represents an IDL namespace.
type Operation ¶
type Operation struct { Comment []string Name string Type *Type Annotations Annotations Scope *Scope // Pointer back to containing Scope }
Operation is a pub/sub scope operation. Corresponding publish and subscribe methods are generated from this for publishers and subscribers, respectively.
type Option ¶
type Option func(*parser) Option
Option is a function that can set an option on the parser. It returns the previous setting as an Option.
func Debug ¶
Debug creates an Option to set the debug flag to b. When set to true, debugging information is printed to stdout while parsing.
The default is false.
func Memoize ¶
Memoize creates an Option to set the memoize flag to b. When set to true, the parser will cache all results so each expression is evaluated only once. This guarantees linear parsing time even for pathological cases, at the expense of more memory and slower times for typical cases.
The default is false.
type Scope ¶
type Scope struct { Comment []string Name string Prefix *ScopePrefix Operations []*Operation Annotations Annotations Frugal *Frugal // Pointer back to containing Frugal }
Scope is a pub/sub namespace.
func (*Scope) ReferencedIncludes ¶
ReferencedIncludes returns a slice containing the referenced includes which will need to be imported in generated code for this Scope.
type ScopePrefix ¶
ScopePrefix is the string prefix prepended to a pub/sub topic. The string can contain variables of the form {foo}, e.g. "foo.{bar}.baz" where "bar" is supplied at publish/subscribe time.
func (*ScopePrefix) Template ¶
func (n *ScopePrefix) Template(s string) string
Template returns the prefix where variables are replaced with the given string.
type Service ¶
type Service struct { Comment []string Name string Extends string Methods []*Method Annotations Annotations Frugal *Frugal // Pointer back to containing Frugal }
Service represents an IDL service.
func (*Service) ExtendsInclude ¶
ExtendsInclude returns the name of the include this service extends from, if applicable, or an empty string if not.
func (*Service) ExtendsService ¶
ExtendsService returns the name of the service this service extends, if applicable, or an empty string if not.
func (*Service) ReferencedIncludes ¶
ReferencedIncludes returns a slice containing the referenced includes which will need to be imported in generated code for this Service.
func (*Service) ReferencedInternals ¶
ReferencedInternals returns a slice containing the referenced internals which will need to be imported in generated code for this Service. TODO: Clean this mess up
func (*Service) TwowayMethods ¶
TwowayMethods returns a slice of the non-oneway methods defined in this Service.
type Struct ¶
type Struct struct { Comment []string Name string Fields []*Field Type StructType Annotations Annotations }
Struct represents an IDL struct (or exception or union).
type StructType ¶
type StructType int
StructType represents what "type" a struct is (struct, exception, or union).
func (StructType) String ¶
func (s StructType) String() string
String returns a human-readable version of the StructType.
type Type ¶
type Type struct { Name string KeyType *Type // If map ValueType *Type // If map, list, or set Annotations Annotations }
Type represents an IDL data type.
func TypeFromStruct ¶
TypeFromStruct returns a new Type from the given Struct.
func (*Type) IncludeName ¶
IncludeName returns the base include name of the type, if any.
func (*Type) IsContainer ¶
IsContainer indicates if the type is a Frugal container type (list, set, or map).
func (*Type) IsPrimitive ¶
IsPrimitive indicates if the type is a Frugal primitive type.
type TypeDef ¶
type TypeDef struct { Comment []string Name string Type *Type Annotations Annotations }
TypeDef represents an IDL typedef.
type ValidationLogger ¶
type ValidationLogger interface { // LogWarning should log a warning message LogWarning(...string) // LogError should log an error message LogError(...string) // ErrorsLogged should return true if any errors have been logged, // and false otherwise ErrorsLogged() bool }
ValidationLogger provides an interface to output validation results.