本文整理汇总了Golang中github.com/myitcv/protobuf/ast.Extension.Up方法的典型用法代码示例。如果您正苦于以下问题:Golang Extension.Up方法的具体用法?Golang Extension.Up怎么用?Golang Extension.Up使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/myitcv/protobuf/ast.Extension
的用法示例。
在下文中一共展示了Extension.Up方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: readMessageContents
func (p *parser) readMessageContents(msg *ast.Message) *parseError {
// Parse message fields and other things inside a message.
var oneof *ast.Oneof // set while inside a oneof
for !p.done {
tok := p.next()
if tok.err != nil {
return tok.err
}
switch tok.value {
case "extend":
// extension
p.back()
ext := new(ast.Extension)
msg.Extensions = append(msg.Extensions, ext)
if err := p.readExtension(ext); err != nil {
return err
}
ext.Up = msg
case "oneof":
// oneof
if oneof != nil {
return p.errorf("nested oneof not permitted")
}
oneof = new(ast.Oneof)
msg.Oneofs = append(msg.Oneofs, oneof)
oneof.Position = p.cur.astPosition()
tok := p.next()
if tok.err != nil {
return tok.err
}
oneof.Name = tok.value // TODO: validate
oneof.Up = msg
if err := p.readToken("{"); err != nil {
return err
}
case "message":
// nested message
p.back()
nmsg := new(ast.Message)
msg.Messages = append(msg.Messages, nmsg)
if err := p.readMessage(nmsg); err != nil {
return err
}
nmsg.Up = msg
case "enum":
// nested enum
p.back()
ne := new(ast.Enum)
msg.Enums = append(msg.Enums, ne)
if err := p.readEnum(ne); err != nil {
return err
}
ne.Up = msg
case "extensions":
// extension range
p.back()
r, err := p.readExtensionRange()
if err != nil {
return err
}
msg.ExtensionRanges = append(msg.ExtensionRanges, r...)
default:
// field; this token is required/optional/repeated,
// a primitive type, or a named type.
p.back()
field := new(ast.Field)
msg.Fields = append(msg.Fields, field)
field.Oneof = oneof
field.Up = msg // p.readField uses this
if err := p.readField(field); err != nil {
return err
}
case "}":
if oneof != nil {
// end of oneof
oneof = nil
continue
}
// end of message
p.back()
return nil
}
}
return p.errorf("unexpected EOF while parsing message")
}
示例2: readFile
//.........这里部分代码省略.........
if err != nil {
return err
}
switch s := tok.unquoted; s {
case "proto2", "proto3":
f.Syntax = s
default:
return p.errorf("invalid syntax value %q", s)
}
if err := p.readToken(";"); err != nil {
return err
}
case "import":
if err := p.readToken("public"); err == nil {
f.PublicImports = append(f.PublicImports, len(f.Imports))
} else {
p.back()
}
tok, err := p.readString()
if err != nil {
return err
}
f.Imports = append(f.Imports, tok.unquoted)
if err := p.readToken(";"); err != nil {
return err
}
case "message":
p.back()
msg := new(ast.Message)
f.Messages = append(f.Messages, msg)
if err := p.readMessage(msg); err != nil {
return err
}
msg.Up = f
case "enum":
p.back()
enum := new(ast.Enum)
f.Enums = append(f.Enums, enum)
if err := p.readEnum(enum); err != nil {
return err
}
enum.Up = f
case "service":
p.back()
srv := new(ast.Service)
f.Services = append(f.Services, srv)
if err := p.readService(srv); err != nil {
return err
}
srv.Up = f
case "extend":
p.back()
ext := new(ast.Extension)
f.Extensions = append(f.Extensions, ext)
if err := p.readExtension(ext); err != nil {
return err
}
ext.Up = f
default:
return p.errorf("unknown top-level thing %q", tok.value)
}
}
// Handle comments.
for len(p.comments) > 0 {
n := 1