generate: Parse primitive types into actual types rather than named types

This commit is contained in:
Sasha Koshka 2025-07-10 21:53:21 -04:00
parent 3bf365a7a9
commit 5a3296a842
2 changed files with 27 additions and 5 deletions

View File

@ -95,6 +95,28 @@ func (this *parser) parseType() (Type, error) {
switch this.Kind() {
case TokenIdent:
switch this.Value() {
case "U8": return TypeInt { Bits: 8 }, this.Next()
case "U16": return TypeInt { Bits: 16 }, this.Next()
case "U32": return TypeInt { Bits: 32 }, this.Next()
case "U64": return TypeInt { Bits: 64 }, this.Next()
case "U128": return TypeInt { Bits: 128 }, this.Next()
case "U256": return TypeInt { Bits: 256 }, this.Next()
case "I8": return TypeInt { Bits: 8, Signed: true }, this.Next()
case "I16": return TypeInt { Bits: 16, Signed: true }, this.Next()
case "I32": return TypeInt { Bits: 32, Signed: true }, this.Next()
case "I64": return TypeInt { Bits: 64, Signed: true }, this.Next()
case "I128": return TypeInt { Bits: 128, Signed: true }, this.Next()
case "I256": return TypeInt { Bits: 256, Signed: true }, this.Next()
case "F16": return TypeFloat { Bits: 16 }, this.Next()
case "F32": return TypeFloat { Bits: 32 }, this.Next()
case "F64": return TypeFloat { Bits: 64 }, this.Next()
case "F128": return TypeFloat { Bits: 128 }, this.Next()
case "F256": return TypeFloat { Bits: 256 }, this.Next()
case "String": return TypeString { }, this.Next()
case "Buffer": return TypeBuffer { }, this.Next()
case "Table": return TypeTable { }, this.Next()
}
return this.parseTypeNamed()
case TokenLBracket:
return this.parseTypeArray()

View File

@ -11,8 +11,8 @@ func TestParse(test *testing.T) {
Name: "Connect",
Type: TypeTableDefined {
Fields: map[uint16] Field {
0x0000: Field { Name: "Name", Type: TypeNamed { Name: "String" } },
0x0001: Field { Name: "Password", Type: TypeNamed { Name: "String" } },
0x0000: Field { Name: "Name", Type: TypeString { } },
0x0001: Field { Name: "Password", Type: TypeString { } },
},
},
}
@ -26,9 +26,9 @@ func TestParse(test *testing.T) {
}
correct.Types["User"] = TypeTableDefined {
Fields: map[uint16] Field {
0x0000: Field { Name: "Name", Type: TypeNamed { Name: "String" } },
0x0001: Field { Name: "Bio", Type: TypeNamed { Name: "String" } },
0x0002: Field { Name: "Followers", Type: TypeNamed { Name: "U32" } },
0x0000: Field { Name: "Name", Type: TypeString { } },
0x0001: Field { Name: "Bio", Type: TypeString { } },
0x0002: Field { Name: "Followers", Type: TypeInt { Bits: 32 } },
},
}
test.Log("CORRECT:", &correct)