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

73 lines
2.0 KiB
Go
Raw Normal View History

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.
func (parser *ParsingOperation) parseBody () (err error) {
for {
err = parser.expect(lexer.TokenKindName)
2022-08-15 13:09:07 -06:00
if err != nil { return }
sectionType := parser.token.Value().(string)
switch sectionType {
case "data":
section, parseErr := parser.parseDataSection()
err = parser.tree.addSection(section)
if err != nil { return }
if parseErr != nil { return parseErr }
case "type":
section, parseErr := parser.parseTypeSection()
err = parser.tree.addSection(section)
if err != nil { return }
if parseErr != nil { return parseErr }
case "objt":
section, parseErr := parser.parseObjtSection()
err = parser.tree.addSection(section)
if err != nil { return }
if parseErr != nil { return parseErr }
case "face":
section, parseErr := parser.parseFaceSection()
err = parser.tree.addSection(section)
if err != nil { return }
if parseErr != nil { return parseErr }
case "enum":
section, parseErr := parser.parseEnumSection()
err = parser.tree.addSection(section)
if err != nil { return }
if parseErr != nil { return parseErr }
case "func":
section, parseErr := parser.parseFuncSection()
err = parser.tree.addSection(section)
if err != nil { return }
if parseErr != nil { return parseErr }
default:
err = parser.token.NewError (
"unknown section type \"" + sectionType + "\"",
infoerr.ErrorKindError)
return
2022-08-15 13:09:07 -06:00
}
2022-08-14 20:38:57 -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
}