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/dereference.go

32 lines
837 B
Go
Raw Normal View History

2022-10-11 09:31:44 -06:00
package parser
2022-10-11 11:31:17 -06:00
import "git.tebibyte.media/arf/arf/lexer"
2022-10-11 09:31:44 -06:00
func (parser *ParsingOperation) parseDereference () (
dereference Dereference,
err error,
) {
2022-10-11 11:31:17 -06:00
err = parser.expect(lexer.TokenKindLBrace)
if err != nil { return }
dereference.location = parser.token.Location()
// parse the value we are dereferencing
err = parser.nextToken(validArgumentStartTokens...)
if err != nil { return }
dereference.argument, err = parser.parseArgument()
if err != nil { return }
// if there is an offset, parse it
2022-10-11 11:35:11 -06:00
err = parser.expect(lexer.TokenKindUInt, lexer.TokenKindRBrace)
2022-10-11 11:31:17 -06:00
if err != nil { return }
if parser.token.Is(lexer.TokenKindUInt) {
dereference.offset = parser.token.Value().(uint64)
}
2022-10-11 11:35:11 -06:00
err = parser.nextToken(lexer.TokenKindRBrace)
2022-10-11 11:31:17 -06:00
if err != nil { return }
err = parser.nextToken()
if err != nil { return }
2022-10-11 09:31:44 -06:00
return
}