export type T struct { a int; b float64; c string; d *int }
func main() {
-//NOTE: INTERFACES PARSE INCORRECTLY: parser's Fields() stops at '('
var s string;
var t reflect.Type;
name, typ, tag, offset = st.Field(1);
assert(typ.String(), "float32");
- //TODO! this is bad - can't put a method in an interface!
- t = reflect.ParseTypeString("", "interface {a int}");
- assert(t.String(), "interface {a int}");
+ t = reflect.ParseTypeString("", "interface {a() *int}");
+ assert(t.String(), "interface {a() *int}");
t = reflect.ParseTypeString("", "*(a int8, b int32)");
assert(t.String(), "*(a int8, b int32)");
+ t = reflect.ParseTypeString("", "*(a int8, b int32) float");
+ assert(t.String(), "*(a int8, b int32) float");
+
+ t = reflect.ParseTypeString("", "*(a int8, b int32) (a float, b float)");
+ assert(t.String(), "*(a int8, b int32) (a float, b float)");
+
t = reflect.ParseTypeString("", "[32]int32");
assert(t.String(), "[32]int32");
at = t.(reflect.ArrayType);
}
// Parse array of fields for struct, interface, and func arguments
-func (p *Parser) Fields(sep string) *[]Field {
+func (p *Parser) Fields(sep, term string) *[]Field {
a := new([]Field, 10);
nf := 0;
- for p.token != "" && !special(p.token[0]) {
+ for p.token != "" && p.token != term {
if nf == len(a) {
a1 := new([]Field, 2*nf);
for i := 0; i < nf; i++ {
return a[0:nf];
}
+// A single type packaged as a field for a function return
+func (p *Parser) OneField() *[]Field {
+ a := new([]Field, 1);
+ a[0].name = "";
+ a[0].typ = p.Type("");
+ return a;
+}
+
func (p *Parser) Struct(name string, tokstart int) *StubType {
- f := p.Fields(";");
+ f := p.Fields(";", "}");
if p.token != "}" {
return MissingStub;
}
}
func (p *Parser) Interface(name string, tokstart int) *StubType {
- f := p.Fields(";");
+ f := p.Fields(";", "}");
if p.token != "}" {
return MissingStub;
}
func (p *Parser) Func(name string, tokstart int) *StubType {
// may be 1 or 2 parenthesized lists
- f1 := NewStructTypeStruct("", "", p.Fields(","));
+ f1 := NewStructTypeStruct("", "", p.Fields(",", ")"));
if p.token != ")" {
return MissingStub;
}
end := p.index;
p.Next();
if p.token != "(" {
- // 1 list: the in parameters only
- return NewStubType(name, NewFuncTypeStruct(name, p.str[tokstart:end], f1, nil));
+ // 1 list: the in parameters are a list. Is there a single out parameter?
+ if p.token == "" || p.token == "}" || p.token == "," || p.token == ";" {
+ return NewStubType(name, NewFuncTypeStruct(name, p.str[tokstart:end], f1, nil));
+ }
+ // A single out parameter.
+ f2 := NewStructTypeStruct("", "", p.OneField());
+ return NewStubType(name, NewFuncTypeStruct(name, p.str[tokstart:end], f1, f2));
+ } else {
+ p.Next();
}
- p.Next();
- f2 := NewStructTypeStruct("", "", p.Fields(","));
+ f2 := NewStructTypeStruct("", "", p.Fields(",", ")"));
if p.token != ")" {
return MissingStub;
}