func exprToName(e *ast.Expr) *ast.NameExpr { if e.GetBuiltIn() != nil { if e.GetBuiltIn().GetSymbol().String() == "==" { if e.GetBuiltIn().GetExpr().GetTerminal() != nil { t := e.GetBuiltIn().GetExpr().GetTerminal() if t.DoubleValue != nil { return ast.NewDoubleName(t.GetDoubleValue()) } if t.IntValue != nil { return ast.NewIntName(t.GetIntValue()) } if t.UintValue != nil { return ast.NewUintName(t.GetUintValue()) } if t.BoolValue != nil { return ast.NewBoolName(t.GetBoolValue()) } if t.StringValue != nil { return ast.NewStringName(t.GetStringValue()) } if t.BytesValue != nil { return ast.NewBytesName(t.GetBytesValue()) } } else { panic("todo") } } else { panic("todo") } } if e.GetFunction() != nil { if e.GetFunction().GetName() == "not" { return ast.NewAnyNameExcept(exprToName(e.GetFunction().GetParams()[0])) } if e.GetFunction().GetName() == "or" { return ast.NewNameChoice( exprToName(e.GetFunction().GetParams()[0]), exprToName(e.GetFunction().GetParams()[1]), ) } panic("todo") } if e.GetTerminal() != nil { if e.GetTerminal().BoolValue != nil { if e.GetTerminal().GetBoolValue() { return ast.NewAnyName() } else { panic("todo") } } else { panic("todo") } } panic("todo") }
func (this *nameToNumber) translateName(current *context, name *ast.NameExpr, child *ast.Pattern) (*ast.Pattern, error) { switch n := name.GetValue().(type) { case *ast.Name: if current.index { if n.IntValue == nil { return nil, &errExpectedArray{name.String(), current} } c := &context{current.msg, false} newp, err := this.translate(c, child) if err != nil { return nil, err } return ast.NewTreeNode(name, newp), nil } if n.StringValue == nil { return nil, &errExpectedField{name.String(), current} } f := getField(this.descMap.LookupFields(current.msg), n.GetStringValue()) if f == nil { return nil, &errUnknownField{name.String(), current} } msg := this.descMap.LookupMessage(f) c := &context{msg, f.IsRepeated()} newp, err := this.translate(c, child) if err != nil { return nil, err } newName := ast.NewUintName(uint64(f.GetNumber())) return ast.NewTreeNode(newName, newp), nil case *ast.AnyName: if current.index { c := &context{current.msg, false} newp, err := this.translate(c, child) if err != nil { return nil, err } return ast.NewTreeNode(name, newp), nil } else { return nil, &errAnyFieldNotSupported{name.String()} } case *ast.AnyNameExcept: return nil, &errAnyNameExceptNotSupported{name.String()} case *ast.NameChoice: l, err1 := this.translateName(current, n.GetLeft(), child) r, err2 := this.translateName(current, n.GetRight(), child) return ast.NewOr(l, r), anyErr(err1, err2) } panic(fmt.Sprintf("unknown name typ %T", name)) }