2022-08-14 20:38:57 -06:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import "git.tebibyte.media/sashakoshka/arf/lexer"
|
2022-08-17 22:58:40 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/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) {
|
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)
|
|
|
|
switch sectionType {
|
|
|
|
case "data":
|
|
|
|
var section *DataSection
|
|
|
|
section, err = parser.parseDataSection()
|
|
|
|
if parser.tree.dataSections == nil {
|
|
|
|
parser.tree.dataSections =
|
|
|
|
make(map[string] *DataSection)
|
|
|
|
}
|
|
|
|
parser.tree.dataSections[section.name] = section
|
2022-08-17 11:26:18 -06:00
|
|
|
if err != nil { return }
|
2022-08-15 19:20:13 -06:00
|
|
|
case "type":
|
2022-08-18 15:39:19 -06:00
|
|
|
var section *TypeSection
|
|
|
|
section, err = parser.parseTypeSection()
|
|
|
|
if parser.tree.typeSections == nil {
|
|
|
|
parser.tree.typeSections =
|
|
|
|
make(map[string] *TypeSection)
|
|
|
|
}
|
2022-08-20 10:50:32 -06:00
|
|
|
parser.tree.typeSections[section.name] = section
|
2022-08-18 15:39:19 -06:00
|
|
|
if err != nil { return }
|
2022-08-20 11:24:56 -06:00
|
|
|
case "objt":
|
|
|
|
var section *ObjtSection
|
|
|
|
section, err = parser.parseObjtSection()
|
2022-08-20 11:29:04 -06:00
|
|
|
if parser.tree.objtSections == nil {
|
|
|
|
parser.tree.objtSections =
|
|
|
|
make(map[string] *ObjtSection)
|
2022-08-20 11:24:56 -06:00
|
|
|
}
|
|
|
|
parser.tree.objtSections[section.name] = section
|
|
|
|
if err != nil { return }
|
2022-08-15 19:20:13 -06:00
|
|
|
case "face":
|
|
|
|
case "enum":
|
2022-08-21 00:42:25 -06:00
|
|
|
var section *EnumSection
|
|
|
|
section, err = parser.parseEnumSection()
|
|
|
|
if parser.tree.enumSections == nil {
|
|
|
|
parser.tree.enumSections =
|
|
|
|
make(map[string] *EnumSection)
|
|
|
|
}
|
|
|
|
parser.tree.enumSections[section.name] = section
|
|
|
|
if err != nil { return }
|
2022-08-15 19:20:13 -06:00
|
|
|
case "func":
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|