2022-08-14 20:38:57 -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-16 08:44:02 -06:00
|
|
|
|
|
|
|
// parseData parses a data section.
|
2022-08-15 13:09:07 -06:00
|
|
|
func (parser *ParsingOperation) parseDataSection () (
|
2022-09-04 17:55:47 -06:00
|
|
|
section DataSection,
|
2022-08-15 13:09:07 -06:00
|
|
|
err error,
|
|
|
|
) {
|
2022-08-16 08:44:02 -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-16 08:44:02 -06:00
|
|
|
|
|
|
|
err = parser.nextToken(lexer.TokenKindPermission)
|
|
|
|
if err != nil { return }
|
|
|
|
section.permission = parser.token.Value().(types.Permission)
|
|
|
|
|
|
|
|
err = parser.nextToken(lexer.TokenKindName)
|
|
|
|
if err != nil { return }
|
|
|
|
section.name = parser.token.Value().(string)
|
|
|
|
|
|
|
|
err = parser.nextToken(lexer.TokenKindColon)
|
|
|
|
if err != nil { return }
|
2022-08-16 15:21:10 -06:00
|
|
|
err = parser.nextToken()
|
|
|
|
if err != nil { return }
|
2022-08-16 08:44:02 -06:00
|
|
|
section.what, err = parser.parseType()
|
|
|
|
if err != nil { return }
|
|
|
|
|
2022-09-05 13:04:39 -06:00
|
|
|
// skip the rest of the section if we are only skimming it
|
|
|
|
if parser.skimming {
|
|
|
|
section.external = true
|
|
|
|
err = parser.skipIndentLevel(1)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-27 16:42:00 -06:00
|
|
|
// see if value exists
|
|
|
|
if parser.token.Is(lexer.TokenKindNewline) {
|
|
|
|
parser.nextToken()
|
2022-09-29 00:01:31 -06:00
|
|
|
// if we have exited the section, return
|
2022-09-27 16:42:00 -06:00
|
|
|
if !parser.token.Is(lexer.TokenKindIndent) { return }
|
|
|
|
if parser.token.Value().(int) != 1 { return }
|
2022-09-16 10:16:23 -06:00
|
|
|
|
2022-09-27 16:42:00 -06:00
|
|
|
err = parser.nextToken()
|
2022-08-16 15:21:10 -06:00
|
|
|
if err != nil { return }
|
2022-09-27 16:42:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if external
|
|
|
|
if parser.token.Is(lexer.TokenKindName) {
|
2022-09-16 10:16:23 -06:00
|
|
|
if parser.token.Value().(string) == "external" {
|
|
|
|
section.external = true
|
2022-09-27 16:42:00 -06:00
|
|
|
|
2022-09-16 10:16:23 -06:00
|
|
|
err = parser.nextToken(lexer.TokenKindNewline)
|
2022-09-27 16:42:00 -06:00
|
|
|
if err != nil { return }
|
2022-09-16 10:16:23 -06:00
|
|
|
err = parser.nextToken()
|
|
|
|
if err != nil { return }
|
|
|
|
return
|
|
|
|
}
|
2022-08-16 15:21:10 -06:00
|
|
|
}
|
2022-09-27 16:42:00 -06:00
|
|
|
|
|
|
|
// get value
|
|
|
|
section.argument, err = parser.parseArgument()
|
|
|
|
err = parser.expect(lexer.TokenKindNewline)
|
|
|
|
if err != nil { return }
|
|
|
|
|
|
|
|
err = parser.nextToken()
|
|
|
|
if err != nil { return }
|
|
|
|
|
2022-08-16 08:44:02 -06:00
|
|
|
return
|
|
|
|
}
|