Documentation
¶
Index ¶
- Constants
- func GenTokenHash(t *Token) (res string)
- func GetToken(literal string) token
- func IsDigit(lit rune) bool
- func IsKeyword(tok token) bool
- func IsNumber(str string) (isFloat bool, isInt bool)
- func IsWhitespace(tok token) bool
- type Const
- type ConstList
- type ConstMap
- type ConstValue
- type Enum
- type EnumElement
- type Field
- type FieldType
- type Function
- type Include
- type ListType
- type MapType
- type Namespace
- type Node
- type NodeCommonField
- type Option
- type Parser
- type Service
- type SetType
- type Struct
- type Thrift
- type Token
- type TypeDef
Constants ¶
View Source
const ( CONST_VALUE_INT = iota + 1 CONST_VALUE_FLOAT CONST_VALUE_IDENT CONST_VALUE_LITERAL CONST_VALUE_MAP CONST_VALUE_LIST )
View Source
const ( FIELD_TYPE_IDENT = iota + 1 FIELD_TYPE_BASE FIELD_TYPE_MAP FIELD_TYPE_LIST FIELD_TYPE_SET )
the definition of what kind of field type
View Source
const ( FIELD_PARENT_TYPE_ARGS = iota + 1 FIELD_PARENT_TYPE_THROWS )
View Source
const ( STRUCT = iota + 1 UNION EXCEPTION )
View Source
const ( // special tokens T_ILLEGAL token = iota T_EOF T_IDENT T_STRING // string literal T_NUMBER // integer or float // white space T_SPACE T_LINEBREAK // \n T_RETURN // \r T_TAB // \t // punctuator T_SEMICOLON // ; T_COLON // : T_EQUALS // = T_QUOTE // " T_SINGLEQUOTE // ' T_LEFTPAREN // ( T_RIGHTPAREN // ) T_LEFTCURLY // { T_RIGHTCURLY // } T_LEFTSQUARE // [ T_RIGHTSQUARE // ] T_COMMENT // / T_LESS // < T_GREATER // > T_COMMA // , T_DOT // . T_PLUS // + T_MINUS // - T_NAMESPACE T_ENUM T_SENUM // currently not supported T_CONST T_SERVICE T_STRUCT T_INCLUDE T_CPP_INCLUDE T_TYPEDEF T_UNION T_EXCEPTION // field keywords T_OPTIONAL T_REQUIRED // type keywords T_MAP T_SET T_LIST // function keywords T_ONEWAY T_VOID T_THROWS )
View Source
const ( SINGLE_LINE_COMMENT = iota + 1 // like this MULTI_LINE_COMMENT /* like this */ BASH_LIKE_COMMENT // # like this )
comment type
Variables ¶
This section is empty.
Functions ¶
func GenTokenHash ¶ added in v0.0.4
Generate hash from token.Type + token.Raw + token.Pos, for nodes like enum/struct/service to find their element node when iterate over token.
func GetToken ¶ added in v0.0.2
func GetToken(literal string) token
Get corresponding token from string literal, mostly used for generate token.
func IsKeyword ¶ added in v0.0.3
func IsKeyword(tok token) bool
isKeyword returns if tok is in the keywords range
func IsWhitespace ¶ added in v0.0.3
func IsWhitespace(tok token) bool
Types ¶
type Const ¶
type Const struct {
NodeCommonField
Ident string
Type *FieldType
Value *ConstValue
}
type ConstMap ¶
type ConstMap struct {
NodeCommonField
MapKeyList []ConstValue
MapValueList []ConstValue
}
func NewConstMap ¶
type ConstValue ¶
type ConstValue struct {
NodeCommonField
Type int
Value string
Map *ConstMap
List *ConstList
}
func NewConstValue ¶
func NewConstValue(parent Node) *ConstValue
func (*ConstValue) NodeType ¶
func (r *ConstValue) NodeType() string
func (*ConstValue) NodeValue ¶
func (r *ConstValue) NodeValue() interface{}
func (*ConstValue) String ¶
func (r *ConstValue) String() string
type Enum ¶
type Enum struct {
NodeCommonField
Ident string
Elems []*EnumElement
Options []*Option
ElemsMap map[string]*EnumElement // startToken hash => EnumElement node
}
type EnumElement ¶
type EnumElement struct {
NodeCommonField
ID int
Ident string
Options []*Option
}
func NewEnumElement ¶
func NewEnumElement(parent Node) *EnumElement
func (*EnumElement) NodeType ¶
func (r *EnumElement) NodeType() string
func (*EnumElement) NodeValue ¶
func (r *EnumElement) NodeValue() interface{}
func (*EnumElement) String ¶
func (r *EnumElement) String() string
type Field ¶
type Field struct {
NodeCommonField
ID int
Requiredness string
FieldType *FieldType
Ident string
DefaultValue *ConstValue
Options []*Option
}
Field represent a field within struct/union/exception
type FieldType ¶
type FieldType struct {
NodeCommonField
Type int
Ident string
BaseType string
Map *MapType
List *ListType
Set *SetType
Options []*Option
}
func NewFieldType ¶
type Function ¶
type Function struct {
NodeCommonField
Ident string
Throws []*Field
Oneway bool
FunctionType *FieldType
Void bool
Args []*Field
Options []*Option
ArgsMap map[string]*Field // startToken hash => Argument Field
ThrowsMap map[string]*Field // startToken hash => Throws Field
}
func NewFunction ¶
type ListType ¶
type ListType struct {
NodeCommonField
Elem *FieldType
CppType string
}
func NewListType ¶
type MapType ¶
type MapType struct {
NodeCommonField
// since directly use map structure its hard to index and will lead to loss of order, we use slice to represent map type, use slice index to mapping
Key *FieldType
Value *FieldType
CppType string
}
func NewMapType ¶
type Namespace ¶
type Namespace struct {
NodeCommonField
Name string
Value string
Options []*Option
}
func NewNamespace ¶
type NodeCommonField ¶
type Option ¶
type Option struct {
NodeCommonField
Name string
Value string
}
Represent a single option, e.g. a = "123"
type Service ¶
type Service struct {
NodeCommonField
Ident string
Elems []*Function
Extends string
Options []*Option
ElemsMap map[string]*Function // startToken hash => Function node
}
func NewService ¶
type SetType ¶
type SetType struct {
NodeCommonField
Elem *FieldType
CppType string
}
func NewSetType ¶
type Struct ¶
type Thrift ¶
type Thrift struct {
NodeCommonField
// thrift file name, if it exists
FileName string
// since Thrift is the root node, we need a property to access its children
Nodes []Node
}
type TypeDef ¶
type TypeDef struct {
NodeCommonField
Type *FieldType // except for identifier
Ident string
Options []*Option
}
func NewTypeDef ¶
Click to show internal directories.
Click to hide internal directories.