2022-08-18 15:39:19 -06:00
|
|
|
package parser
|
|
|
|
|
2022-08-29 23:11:10 -06:00
|
|
|
import "git.tebibyte.media/arf/arf/types"
|
|
|
|
import "git.tebibyte.media/arf/arf/lexer"
|
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 () (
|
2022-09-04 17:55:47 -06:00
|
|
|
section TypeSection,
|
2022-08-18 15:39:19 -06:00
|
|
|
err error,
|
|
|
|
) {
|
2022-08-18 18:09:04 -06:00
|
|
|
err = parser.expect(lexer.TokenKindName)
|
|
|
|
if err != nil { return }
|
|
|
|
|
2022-09-03 20:58:35 -06:00
|
|
|
section.location = parser.token.Location()
|
2022-08-18 18:09:04 -06:00
|
|
|
|
|
|
|
// 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-09-03 20:56:08 -06:00
|
|
|
section.what, 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-09-13 09:12:38 -06:00
|
|
|
section.value, err = parser.parseDefaultValues(0)
|
2022-08-19 00:34:17 -06:00
|
|
|
if err != nil { return }
|
2022-08-18 18:09:04 -06:00
|
|
|
} else {
|
2022-09-04 01:31:35 -06:00
|
|
|
section.value, 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
|
|
|
|
}
|