This repository has been archived on 2024-02-27. You can view files and clone it, but cannot push or open issues or pull requests.
arf/parser/type.go

54 lines
1.5 KiB
Go
Raw Normal View History

2022-08-18 15:39:19 -06:00
package parser
2022-08-18 18:09:04 -06:00
import "git.tebibyte.media/sashakoshka/arf/types"
import "git.tebibyte.media/sashakoshka/arf/lexer"
2022-08-20 11:26:24 -06:00
// import "git.tebibyte.media/sashakoshka/arf/infoerr"
2022-08-18 18:09:04 -06:00
2022-08-20 11:26:24 -06:00
// parseTypeSection parses a blind type definition, meaning it can inherit from
// anything including primitives, but cannot define structure.
2022-08-18 15:39:19 -06:00
func (parser *ParsingOperation) parseTypeSection () (
section *TypeSection,
err error,
) {
2022-08-18 18:09:04 -06:00
err = parser.expect(lexer.TokenKindName)
if err != nil { return }
section = &TypeSection { location: parser.token.Location() }
// get permission
2022-08-20 11:26:24 -06:00
err = parser.nextToken(lexer.TokenKindPermission)
2022-08-18 18:09:04 -06:00
if err != nil { return }
2022-08-20 11:26:24 -06:00
section.permission = parser.token.Value().(types.Permission)
2022-08-18 18:09:04 -06:00
// get name
err = parser.nextToken(lexer.TokenKindName)
if err != nil { return }
2022-08-20 11:26:24 -06:00
section.name = parser.token.Value().(string)
2022-08-18 18:09:04 -06:00
2022-08-20 11:26:24 -06:00
// parse inherited type
2022-08-18 18:09:04 -06:00
err = parser.nextToken(lexer.TokenKindColon)
if err != nil { return }
err = parser.nextToken()
if err != nil { return }
2022-08-20 11:26:24 -06:00
section.inherits, err = parser.parseType()
2022-08-18 18:09:04 -06:00
if err != nil { return }
2022-08-20 11:26:24 -06:00
// parse default values
2022-08-18 18:09:04 -06:00
if parser.token.Is(lexer.TokenKindNewline) {
err = parser.nextToken()
if err != nil { return }
2022-08-20 11:26:24 -06:00
section.defaultValue, err = parser.parseInitializationValues(0)
if err != nil { return }
2022-08-18 18:09:04 -06:00
} else {
2022-08-20 11:26:24 -06:00
section.defaultValue, err = parser.parseArgument()
2022-08-18 18:09:04 -06:00
if err != nil { return }
err = parser.expect(lexer.TokenKindNewline)
if err != nil { return }
err = parser.nextToken()
if err != nil { return }
}
2022-08-18 15:39:19 -06:00
return
}