2022-09-13 14:31:08 -06:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import "git.tebibyte.media/arf/arf/lexer"
|
|
|
|
import "git.tebibyte.media/arf/arf/infoerr"
|
|
|
|
|
|
|
|
// parseType parses a type notation of the form Name, {Name}, etc.
|
2022-10-11 21:57:27 -06:00
|
|
|
func (parser *parsingOperation) parseType () (what Type, err error) {
|
2022-09-13 14:31:08 -06:00
|
|
|
err = parser.expect(lexer.TokenKindName, lexer.TokenKindLBrace)
|
|
|
|
if err != nil { return }
|
|
|
|
what.location = parser.token.Location()
|
2022-09-29 00:04:44 -06:00
|
|
|
what.kind = TypeKindBasic
|
2022-09-13 14:31:08 -06:00
|
|
|
|
|
|
|
if parser.token.Is(lexer.TokenKindLBrace) {
|
|
|
|
what.kind = TypeKindPointer
|
|
|
|
|
|
|
|
err = parser.nextToken()
|
|
|
|
if err != nil { return }
|
|
|
|
|
|
|
|
var points Type
|
|
|
|
points, err = parser.parseType()
|
|
|
|
if err != nil { return }
|
|
|
|
what.points = &points
|
|
|
|
|
|
|
|
err = parser.expect (
|
|
|
|
lexer.TokenKindRBrace,
|
|
|
|
lexer.TokenKindElipsis)
|
|
|
|
if err != nil { return }
|
|
|
|
|
|
|
|
if parser.token.Is(lexer.TokenKindElipsis) {
|
|
|
|
what.kind = TypeKindVariableArray
|
|
|
|
|
|
|
|
err = parser.nextToken(lexer.TokenKindRBrace)
|
|
|
|
if err != nil { return }
|
|
|
|
}
|
|
|
|
|
|
|
|
err = parser.nextToken()
|
|
|
|
if err != nil { return }
|
|
|
|
} else {
|
|
|
|
what.name, err = parser.parseIdentifier()
|
|
|
|
if err != nil { return }
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
if !parser.token.Is(lexer.TokenKindColon) { break }
|
2022-09-16 20:22:07 -06:00
|
|
|
|
|
|
|
err = parser.nextToken()
|
|
|
|
if err != nil { return }
|
|
|
|
err = parser.skipWhitespace()
|
|
|
|
if err != nil { return }
|
2022-09-17 09:50:27 -06:00
|
|
|
|
2022-09-27 13:48:47 -06:00
|
|
|
err = parser.expect(lexer.TokenKindName, lexer.TokenKindUInt)
|
2022-09-13 14:31:08 -06:00
|
|
|
if err != nil { return }
|
|
|
|
|
|
|
|
if parser.token.Is(lexer.TokenKindName) {
|
|
|
|
// parse type qualifier
|
|
|
|
qualifier := parser.token.Value().(string)
|
|
|
|
switch qualifier {
|
|
|
|
case "mut":
|
|
|
|
what.mutable = true
|
|
|
|
default:
|
|
|
|
err = parser.token.NewError (
|
|
|
|
"unknown type qualifier \"" +
|
|
|
|
qualifier + "\"",
|
|
|
|
infoerr.ErrorKindError)
|
|
|
|
return
|
|
|
|
}
|
2022-09-17 09:50:27 -06:00
|
|
|
err = parser.nextToken()
|
|
|
|
if err != nil { return }
|
|
|
|
|
2022-09-14 13:16:56 -06:00
|
|
|
} else if parser.token.Is(lexer.TokenKindUInt) {
|
2022-09-13 14:31:08 -06:00
|
|
|
// parse fixed array length
|
|
|
|
what.length = parser.token.Value().(uint64)
|
2022-09-16 22:58:08 -06:00
|
|
|
err = parser.nextToken()
|
|
|
|
if err != nil { return }
|
2022-09-14 13:16:56 -06:00
|
|
|
|
2022-09-13 14:31:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-13 16:16:18 -06:00
|
|
|
return
|
|
|
|
}
|