ast

package
v0.0.0-...-bc2ff70 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Copyright © 2020 aggronmagi <czy463@163.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2020 aggronmagi <czy463@163.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2023 aggronmagi <czy463@163.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2020 aggronmagi <czy463@163.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// ProtobufOptionSyntax syntax = "proto2" 选项
	ProtobufOptionSyntax = "proto.syntax"
)

protobuf 消息解析设置选项

Variables

View Source
var Flag = &astFlag{}

Flag ast包导出标记

Functions

func NewError

func NewError(tok *token.Token, format string, args ...interface{}) error

func NewError2

func NewError2(tok *token.Token, err error) error

func NewErrorPos

func NewErrorPos(pos token.Pos, format string, args ...interface{}) error

func NewErrorPos2

func NewErrorPos2(pos token.Pos, err error) error

Types

type Context

type Context struct {
	Prog *YTProgram
	//Doc         *YTDoc
	LastElement interface{}
	Docs        []*token.Token
}

func (*Context) AddDoc

func (ctx *Context) AddDoc(tok *token.Token)

func (*Context) PreDoc

func (ctx *Context) PreDoc(tokLine int) *YTDoc

func (*Context) Range

func (ctx *Context) Range(tok *token.Token, tm *token.TokenMap)

type MethodFlag

type MethodFlag int8

MethodFlag 方法标记

const (
	Call MethodFlag = iota
	Notify
)

方法标记

func (MethodFlag) String

func (flag MethodFlag) String() string

String 文字描述

type RecursionAnalyseFunc

type RecursionAnalyseFunc func(file string) (prog *YTProgram, err error)

RecursionAnalyseFunc 递归解析函数

func (RecursionAnalyseFunc) Analyse

func (f RecursionAnalyseFunc) Analyse(file string) (prog *YTProgram, err error)

Analyse 实现 RecursionAnalyser 接口

type RecursionAnalyser

type RecursionAnalyser interface {
	Analyse(file string) (prog *YTProgram, err error)
}

RecursionAnalyser 递归分析接口

var RegisterRecursionAnalyser RecursionAnalyser = nil

本地全局.递归解析函数

type YTBaseType

type YTBaseType int

YTBaseType 基本类型

var (
	// BaseTypeInt8 Int8
	BaseTypeInt8 *YTBaseType
	// BaseTypeUint8 Uint8
	BaseTypeUint8 *YTBaseType
	// BaseTypeInt16 Int16
	BaseTypeInt16 *YTBaseType
	// BaseTypeUint16 Uint16
	BaseTypeUint16 *YTBaseType
	// BaseTypeInt32 Int32
	BaseTypeInt32 *YTBaseType
	// BaseTypeUint32 Uint32
	BaseTypeUint32 *YTBaseType
	// BaseTypeInt64 Int64
	BaseTypeInt64 *YTBaseType
	// BaseTypeUint64 Uint64
	BaseTypeUint64 *YTBaseType
	// BaseTypeString String
	BaseTypeString *YTBaseType
	// BaseTypeBinary Binary
	BaseTypeBinary *YTBaseType
	// BaseTypeBool Bool
	BaseTypeBool *YTBaseType
	// BaseTypeFloat32 float32 float
	BaseTypeFloat32 *YTBaseType
	// BaseTypeFloat64 float64 double
	BaseTypeFloat64 *YTBaseType
)

func (*YTBaseType) String

func (typ *YTBaseType) String() string

type YTCustomType

type YTCustomType struct {
	Name string
	Msg  *YTMessage
}

YTCustomType 自定义类型

type YTDoc

type YTDoc struct {
	DocPos token.Pos
	Doc    []string
	// 尾注释
	TailDoc string
}

YTDoc 文档,注释

type YTEnumDef

type YTEnumDef struct {
	*YTDoc
	YTOptions
	DefPos token.Pos
	Name   string
	Values []*YTEnumValue
	// contains filtered or unexported fields
}

YTEnumDef 枚举定义

type YTEnumValue

type YTEnumValue struct {
	*YTDoc
	DefPos token.Pos
	Name   string
	Value  int64
}

YTEnumValue 枚举值

type YTField

type YTField struct {
	*YTDoc
	YTOptions
	DefPos token.Pos
	Type   *YTFieldType
	No     uint8
	Name   string
}

YTField 字段定义

type YTFieldType

type YTFieldType struct {
	*YTBaseType
	*YTListType
	*YTMapTypee
	*YTCustomType
}

YTFieldType 字段类型

type YTImport

type YTImport struct {
	*YTDoc
	DefPos    token.Pos
	Prog      *YTProgram
	File      string
	AliasName string
}

YTImport 导入依赖

type YTListType

type YTListType struct {
	*YTBaseType
	*YTCustomType
}

YTListType 列表类型

type YTMapTypee

type YTMapTypee struct {
	Key   *YTBaseType
	Value *YTListType
}

YTMapTypee 映射类型

type YTMessage

type YTMessage struct {
	*YTDoc
	DefPos token.Pos
	YTOptions
	Name         string
	Fields       []*YTField
	ProtobufFlag bool
	SubMsgs      []*YTMessage
	// contains filtered or unexported fields
}

YTMessage 消息定义

type YTMethod

type YTMethod struct {
	*YTDoc
	YTOptions
	DefPos  token.Pos
	Flag    MethodFlag
	Name    string
	Request *YTMessage
	Reply   *YTMessage
	No      *YTMethodNo
}

YTMethod 函数,方法定义

func ProtoNewMethod

func ProtoNewMethod(v1, v3, v7 interface{}) (method *YTMethod, _ error)

ProtoNewMethod 新建方法 "rpc" tok_identifier "(" tok_identifier ")" "returns" "(" tok_identifier ")" "{" "}"

type YTMethodNo

type YTMethodNo struct {
	DefPos token.Pos
	Macro  *YTCustomType
	Value  *int64
}

YTMethodNo 方法ID

type YTOption

type YTOption struct {
	*YTDoc
	DefPos token.Pos
	Key    string
	Value  *YTOptionValue
}

YTOption 定义选项节点

func ProtoNewOption

func ProtoNewOption(v1, v2 interface{}) (opt *YTOption, _ error)

ProtoNewOption 新建选项 Option: "option" tok_identifier tok_literal ";"

func ProtoNewSyntax

func ProtoNewSyntax(v2 interface{}) (syntax *YTOption, _ error)

////////////////////////////////////////////////////////// NOTE: protobuf 支持 NewSyntax protobuf 支持. 语法 Syntax: "syntax" "=" tok_identifier ";"

type YTOptionValue

type YTOptionValue struct {
	Value  *string
	IntVal *int64
}

YTOptionValue 选项值

func (*YTOptionValue) String

func (val *YTOptionValue) String() (desc string)

type YTOptions

type YTOptions struct {
	Opts []*YTOption
	// contains filtered or unexported fields
}

YTOptions 选项

func (*YTOptions) GetOption

func (opts *YTOptions) GetOption(key string) *YTOption

GetOption 获取选项

func (*YTOptions) GetOptionString

func (opts *YTOptions) GetOptionString(key string) (val string)

GetOptionString 获取选项值

func (*YTOptions) GetOptionValue

func (opts *YTOptions) GetOptionValue(key string) *YTOptionValue

GetOptionValue 获取选项值

func (*YTOptions) HasOption

func (opts *YTOptions) HasOption(key string) bool

HasOption 是否有选项

type YTPackage

type YTPackage struct {
	*YTDoc // 文件注释
	DefPos token.Pos
	Name   string
}

YTPackage 文件包定义.

type YTProgram

type YTProgram struct {
	YTOptions // 包 选项

	Pkg      *YTPackage   // 包定义
	Imports  []*YTImport  // 导入文件
	EnumDefs []*YTEnumDef // 枚举定义
	Messages []*YTMessage // 消息定义
	Services []*YTService // 服务定义
	Projects []*YTProject // 项目定义
	// File 文件名 - 只有整个文件解析成功才会赋值
	File string
	// contains filtered or unexported fields
}

YTProgram 文件语法树

func (*YTProgram) AnalyseProgram

func (prog *YTProgram) AnalyseProgram() (err error)

AnalyseProgram 分析检测Program合理性

func (*YTProgram) ApplyCmdOptions

func (prog *YTProgram) ApplyCmdOptions(opts ...string)

ApplyCmdOptions 应用命令行参数添加的全局选项 全局Options. 格式为 "xx.xxx=66" "xx.x1" "xx.xx2=xxx"

func (*YTProgram) GetFileDesc

func (prog *YTProgram) GetFileDesc() *buildpb.FileDesc

GetFileDesc 获取文件描述

func (*YTProgram) GetFileDescWithImports

func (prog *YTProgram) GetFileDescWithImports() (list []*buildpb.FileDesc)

GetFileDescWithImports 获取文件描述(包含依赖)

type YTProject

type YTProject struct {
	*YTDoc
	DefPos token.Pos
	Area   string
	Name   string
	Conf   map[string]*YTOptions
}

YTProject 项目定义

type YTService

type YTService struct {
	*YTDoc
	DefPos token.Pos
	YTOptions
	Flag    MethodFlag
	Name    string
	Methods []*YTMethod
	// contains filtered or unexported fields
}

YTService 服务定义

Jump to

Keyboard shortcuts

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