From 85b7938843e18df1a9298612a93a871fb44c2f92 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 15 Aug 2022 21:20:13 -0400 Subject: [PATCH] ParseBody now has a loop, and errors on unrecognized section type --- parser/body.go | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/parser/body.go b/parser/body.go index 98bf5f3..4f6fae6 100644 --- a/parser/body.go +++ b/parser/body.go @@ -1,26 +1,34 @@ package parser +import "git.tebibyte.media/sashakoshka/arf/file" import "git.tebibyte.media/sashakoshka/arf/lexer" // parse body parses the body of an arf file, after the metadata header. func (parser *ParsingOperation) parseBody () (err error) { - err = parser.nextToken(lexer.TokenKindName) - if err != nil { return } - - switch parser.token.Value().(string) { - case "data": - var section *DataSection - section, err = parser.parseDataSection() + for { + err = parser.expect(lexer.TokenKindName) if err != nil { return } - if parser.tree.dataSections == nil { - parser.tree.dataSections = make(map[string] *DataSection) - } - parser.tree.dataSections[section.name] = section - case "type": - case "face": - case "enum": - case "func": - } - return + sectionType := parser.token.Value().(string) + switch sectionType { + case "data": + var section *DataSection + section, err = parser.parseDataSection() + if err != nil { return } + if parser.tree.dataSections == nil { + parser.tree.dataSections = + make(map[string] *DataSection) + } + parser.tree.dataSections[section.name] = section + case "type": + case "face": + case "enum": + case "func": + default: + err = parser.token.NewError ( + "unknown section type \"" + sectionType + "\"", + file.ErrorKindError) + return + } + } }