generate: Add Any type to parser and syntax tree
This commit is contained in:
parent
8dac25035f
commit
419c3651bf
@ -116,6 +116,7 @@ func (this *parser) parseType() (Type, error) {
|
|||||||
case "String": return TypeString { }, this.Next()
|
case "String": return TypeString { }, this.Next()
|
||||||
case "Buffer": return TypeBuffer { }, this.Next()
|
case "Buffer": return TypeBuffer { }, this.Next()
|
||||||
case "Table": return TypeTable { }, this.Next()
|
case "Table": return TypeTable { }, this.Next()
|
||||||
|
case "Any": return TypeAny { }, this.Next()
|
||||||
}
|
}
|
||||||
return this.parseTypeNamed()
|
return this.parseTypeNamed()
|
||||||
case TokenLBracket:
|
case TokenLBracket:
|
||||||
|
@ -31,6 +31,7 @@ func TestParse(test *testing.T) {
|
|||||||
0x0002: Field { Name: "Followers", Type: TypeInt { Bits: 32 } },
|
0x0002: Field { Name: "Followers", Type: TypeInt { Bits: 32 } },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
correct.Types["Anything"] = TypeAny { }
|
||||||
test.Log("CORRECT:", &correct)
|
test.Log("CORRECT:", &correct)
|
||||||
|
|
||||||
got, err := ParseReader("test.pdl", strings.NewReader(`
|
got, err := ParseReader("test.pdl", strings.NewReader(`
|
||||||
@ -48,6 +49,8 @@ func TestParse(test *testing.T) {
|
|||||||
0001 Bio String,
|
0001 Bio String,
|
||||||
0002 Followers U32,
|
0002 Followers U32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Anything Any
|
||||||
`))
|
`))
|
||||||
if err != nil { test.Fatal(parse.Format(err)) }
|
if err != nil { test.Fatal(parse.Format(err)) }
|
||||||
test.Log("GOT: ", got)
|
test.Log("GOT: ", got)
|
||||||
|
@ -99,6 +99,12 @@ func (typ TypeNamed) String() string {
|
|||||||
return typ.Name
|
return typ.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TypeAny struct { }
|
||||||
|
|
||||||
|
func (typ TypeAny) String() string {
|
||||||
|
return "Any"
|
||||||
|
}
|
||||||
|
|
||||||
func HashType(typ Type) [16]byte {
|
func HashType(typ Type) [16]byte {
|
||||||
// TODO: if we ever want to make the compiler more efficient, this would
|
// TODO: if we ever want to make the compiler more efficient, this would
|
||||||
// be a good place to start, complex string concatenation in a hot path
|
// be a good place to start, complex string concatenation in a hot path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user