Parser properly unions position of named types

This commit is contained in:
Sasha Koshka 2024-02-15 01:07:25 -05:00
parent 6b9cdcc239
commit 159317965d

View File

@ -17,6 +17,7 @@ var startTokensType = []lexer.TokenKind {
func (this *treeParser) parseType () (entity.Type, error) { func (this *treeParser) parseType () (entity.Type, error) {
err := this.ExpectDesc(descriptionType, startTokensType...) err := this.ExpectDesc(descriptionType, startTokensType...)
if err != nil { return nil, err } if err != nil { return nil, err }
pos := this.Pos()
switch this.Kind() { switch this.Kind() {
case lexer.Ident: case lexer.Ident:
@ -25,7 +26,7 @@ func (this *treeParser) parseType () (entity.Type, error) {
if err != nil { return nil, err } if err != nil { return nil, err }
err = this.ExpectNext(lexer.TypeIdent) err = this.ExpectNext(lexer.TypeIdent)
if err != nil { return nil, err } if err != nil { return nil, err }
return this.parseTypeNamedCore(ident) return this.parseTypeNamedCore(pos, ident)
case lexer.TypeIdent: case lexer.TypeIdent:
if this.Value() == "Int" || this.Value() == "UInt" { if this.Value() == "Int" || this.Value() == "UInt" {
@ -46,7 +47,7 @@ func (this *treeParser) parseType () (entity.Type, error) {
} }
} }
return this.parseTypeNamedCore("") return this.parseTypeNamedCore(pos, "")
case lexer.Star: case lexer.Star:
return this.parseTypePointerOrSlice() return this.parseTypePointerOrSlice()
@ -69,13 +70,13 @@ func (this *treeParser) parseType () (entity.Type, error) {
panic(this.bug()) panic(this.bug())
} }
func (this *treeParser) parseTypeNamedCore (unitNickname string) (entity.Type, error) { func (this *treeParser) parseTypeNamedCore (pos errors.Position, unitNickname string) (entity.Type, error) {
err := this.Expect(lexer.TypeIdent) err := this.Expect(lexer.TypeIdent)
if err != nil { return nil, err } if err != nil { return nil, err }
defer this.Next() defer this.Next()
return &entity.TypeNamed { return &entity.TypeNamed {
Position: this.Pos(), Position: pos.Union(this.Pos()),
Name: this.Value(), Name: this.Value(),
UnitNickname: unitNickname, UnitNickname: unitNickname,
}, nil }, nil