From 16bca57e363b5ca011e78abb4241821366a0e7e9 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 16 Aug 2022 17:21:10 -0400 Subject: [PATCH] Fixed numerous problems related to type parsing --- parser/data.go | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/parser/data.go b/parser/data.go index c9a9da4..9f81fc4 100644 --- a/parser/data.go +++ b/parser/data.go @@ -24,27 +24,44 @@ func (parser *ParsingOperation) parseDataSection () ( err = parser.nextToken(lexer.TokenKindColon) if err != nil { return } + err = parser.nextToken() + if err != nil { return } section.what, err = parser.parseType() if err != nil { return } + if parser.token.Is(lexer.TokenKindNewline) { + // TODO: parse arguments + } else { + var argument Argument + argument, err = parser.parseArgument() + section.value = append(section.value, argument) + + err = parser.expect(lexer.TokenKindNewline) + if err != nil { return } + err = parser.nextToken() + if err != nil { return } + } return } // parseType parses a type notation of the form Name, {Name}, etc. func (parser *ParsingOperation) parseType () (what Type, err error) { - err = parser.nextToken(lexer.TokenKindName, lexer.TokenKindLBrace) + err = parser.expect(lexer.TokenKindName, lexer.TokenKindLBrace) if err != nil { return } what.location = parser.token.Location() if parser.token.Is(lexer.TokenKindLBrace) { what.kind = TypeKindPointer + + err = parser.nextToken() + if err != nil { return } var points Type points, err = parser.parseType() if err != nil { return } what.points = &points - err = parser.nextToken ( + err = parser.expect ( lexer.TokenKindUInt, lexer.TokenKindRBrace) if err != nil { return } @@ -54,18 +71,17 @@ func (parser *ParsingOperation) parseType () (what Type, err error) { what.length = parser.token.Value().(uint64) - err = parser.nextToken ( - lexer.TokenKindUInt, - lexer.TokenKindRBrace) + err = parser.nextToken(lexer.TokenKindRBrace) if err != nil { return } } + + err = parser.nextToken() + if err != nil { return } } else { what.name, err = parser.parseIdentifier() if err != nil { return } } - err = parser.nextToken() - if parser.token.Is(lexer.TokenKindColon) { err = parser.nextToken(lexer.TokenKindName) if err != nil { return } @@ -80,6 +96,9 @@ func (parser *ParsingOperation) parseType () (what Type, err error) { file.ErrorKindError) return } + + err = parser.nextToken() + if err != nil { return } } return