2022-08-14 20:38:57 -06:00
|
|
|
package parser
|
|
|
|
|
2022-08-29 23:11:10 -06:00
|
|
|
import "git.tebibyte.media/arf/arf/lexer"
|
|
|
|
import "git.tebibyte.media/arf/arf/infoerr"
|
2022-08-14 20:38:57 -06:00
|
|
|
|
|
|
|
// parse body parses the body of an arf file, after the metadata header.
|
2022-10-11 21:57:27 -06:00
|
|
|
func (parser *parsingOperation) parseBody () (err error) {
|
2022-08-15 19:20:13 -06:00
|
|
|
for {
|
|
|
|
err = parser.expect(lexer.TokenKindName)
|
2022-08-15 13:09:07 -06:00
|
|
|
if err != nil { return }
|
2022-08-15 19:20:13 -06:00
|
|
|
sectionType := parser.token.Value().(string)
|
2022-09-04 17:30:59 -06:00
|
|
|
|
2022-08-15 19:20:13 -06:00
|
|
|
switch sectionType {
|
|
|
|
case "data":
|
2022-09-04 17:30:59 -06:00
|
|
|
section, parseErr := parser.parseDataSection()
|
|
|
|
err = parser.tree.addSection(section)
|
|
|
|
if err != nil { return }
|
2022-09-05 09:28:27 -06:00
|
|
|
if parseErr != nil { return parseErr }
|
2022-09-04 15:13:49 -06:00
|
|
|
|
2022-08-15 19:20:13 -06:00
|
|
|
case "type":
|
2022-09-04 17:30:59 -06:00
|
|
|
section, parseErr := parser.parseTypeSection()
|
|
|
|
err = parser.tree.addSection(section)
|
|
|
|
if err != nil { return }
|
2022-09-05 09:28:27 -06:00
|
|
|
if parseErr != nil { return parseErr }
|
2022-09-04 15:13:49 -06:00
|
|
|
|
2022-08-15 19:20:13 -06:00
|
|
|
case "face":
|
2022-09-04 17:30:59 -06:00
|
|
|
section, parseErr := parser.parseFaceSection()
|
|
|
|
err = parser.tree.addSection(section)
|
|
|
|
if err != nil { return }
|
2022-09-05 09:28:27 -06:00
|
|
|
if parseErr != nil { return parseErr }
|
2022-09-04 15:13:49 -06:00
|
|
|
|
2022-08-15 19:20:13 -06:00
|
|
|
case "enum":
|
2022-09-04 17:30:59 -06:00
|
|
|
section, parseErr := parser.parseEnumSection()
|
|
|
|
err = parser.tree.addSection(section)
|
|
|
|
if err != nil { return }
|
2022-09-05 09:28:27 -06:00
|
|
|
if parseErr != nil { return parseErr }
|
2022-09-04 15:13:49 -06:00
|
|
|
|
2022-08-15 19:20:13 -06:00
|
|
|
case "func":
|
2022-09-04 17:30:59 -06:00
|
|
|
section, parseErr := parser.parseFuncSection()
|
|
|
|
err = parser.tree.addSection(section)
|
|
|
|
if err != nil { return }
|
2022-09-05 09:28:27 -06:00
|
|
|
if parseErr != nil { return parseErr }
|
2022-09-04 15:13:49 -06:00
|
|
|
|
2022-08-15 19:20:13 -06:00
|
|
|
default:
|
|
|
|
err = parser.token.NewError (
|
|
|
|
"unknown section type \"" + sectionType + "\"",
|
2022-08-17 22:58:40 -06:00
|
|
|
infoerr.ErrorKindError)
|
2022-08-15 19:20:13 -06:00
|
|
|
return
|
2022-08-15 13:09:07 -06:00
|
|
|
}
|
2022-08-14 20:38:57 -06:00
|
|
|
}
|
|
|
|
}
|
2022-09-04 17:30:59 -06:00
|
|
|
|
|
|
|
// addSection adds a section to the tree, ensuring it has a unique name within
|
|
|
|
// the module.
|
|
|
|
func (tree *SyntaxTree) addSection (section Section) (err error) {
|
|
|
|
_, exists := tree.sections[section.Name()]
|
|
|
|
if exists {
|
|
|
|
err = section.NewError (
|
|
|
|
"cannot have multiple sections with the same name",
|
|
|
|
infoerr.ErrorKindError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
tree.sections[section.Name()] = section
|
|
|
|
return
|
|
|
|
}
|