From 6a6fe8353e7c7e1569ebb95f732c515aaaa3e256 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 21 Aug 2022 11:17:56 -0400 Subject: [PATCH] Add untested enum parsing --- parser/enum.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/parser/enum.go b/parser/enum.go index 0618df8..ca7c822 100644 --- a/parser/enum.go +++ b/parser/enum.go @@ -50,3 +50,43 @@ func (parser *ParsingOperation) parseEnumSection () ( } return } + +// parseEnumMembers parses a list of members for an enum section. Indentation +// level is assumed. +func (parser *ParsingOperation) parseEnumMembers ( + into *EnumSection, +) ( + err error, +) { + + for { + // if we've left the block, stop parsing + if !parser.token.Is(lexer.TokenKindIndent) { return } + if parser.token.Value().(int) != 1 { return } + + // get name + err = parser.nextToken(lexer.TokenKindName) + if err != nil { return } + name := parser.token.Value().(string) + + // parse default value + var argument Argument + if parser.token.Is(lexer.TokenKindNewline) { + err = parser.nextToken() + if err != nil { return } + + argument, err = parser.parseInitializationValues(1) + into.members[name] = argument + if err != nil { return } + } else { + argument, err = parser.parseArgument() + into.members[name] = argument + if err != nil { return } + + err = parser.expect(lexer.TokenKindNewline) + if err != nil { return } + err = parser.nextToken() + if err != nil { return } + } + } +}