From 5127b806304f98be01a4a393488cdbc63ac879bb Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 5 Sep 2022 11:28:27 -0400 Subject: [PATCH] Parser has been updated to handle new syntax --- parser/body.go | 12 ++++++------ parser/data_test.go | 8 ++++---- parser/misc.go | 41 +++++++++++++++++++++-------------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/parser/body.go b/parser/body.go index 15b9092..bb852a0 100644 --- a/parser/body.go +++ b/parser/body.go @@ -15,37 +15,37 @@ func (parser *ParsingOperation) parseBody () (err error) { section, parseErr := parser.parseDataSection() err = parser.tree.addSection(section) if err != nil { return } - if parseErr != 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 } + if parseErr != nil { return parseErr } case "objt": section, parseErr := parser.parseObjtSection() err = parser.tree.addSection(section) if err != nil { return } - if parseErr != 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 } + if parseErr != nil { return parseErr } case "enum": section, parseErr := parser.parseEnumSection() err = parser.tree.addSection(section) if err != nil { return } - if parseErr != 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 } + if parseErr != nil { return parseErr } default: err = parser.token.NewError ( diff --git a/parser/data_test.go b/parser/data_test.go index 5daed72..08c77d9 100644 --- a/parser/data_test.go +++ b/parser/data_test.go @@ -25,15 +25,15 @@ data ro gIntegerArrayInitialized:Int:16 4785 92 data ro jObject:thing.Thing.thing.thing - .this 324 .that 2139 + .this 324 data ro kNestedObject:Obj - .this - .bird0 324 - .bird1 "hello world" .that .bird2 123.8439 .bird3 9328.21348239 + .this + .bird0 324 + .bird1 "hello world" data ro lMutIntegerArray16:Int:16:mut data ro mIntegerArrayInitialized:Int:16:mut 3948 diff --git a/parser/misc.go b/parser/misc.go index 9ccc17c..b2a54d5 100644 --- a/parser/misc.go +++ b/parser/misc.go @@ -44,19 +44,11 @@ func (parser *ParsingOperation) parseType () (what Type, err error) { what.points = &points err = parser.expect ( - lexer.TokenKindUInt, lexer.TokenKindRBrace, lexer.TokenKindElipsis) if err != nil { return } - if parser.token.Is(lexer.TokenKindUInt) { - what.kind = TypeKindArray - - what.length = parser.token.Value().(uint64) - - err = parser.nextToken(lexer.TokenKindRBrace) - if err != nil { return } - } else if parser.token.Is(lexer.TokenKindElipsis) { + if parser.token.Is(lexer.TokenKindElipsis) { what.kind = TypeKindVariableArray err = parser.nextToken(lexer.TokenKindRBrace) @@ -70,19 +62,28 @@ func (parser *ParsingOperation) parseType () (what Type, err error) { if err != nil { return } } - if parser.token.Is(lexer.TokenKindColon) { - err = parser.nextToken(lexer.TokenKindName) + for { + if !parser.token.Is(lexer.TokenKindColon) { break } + + err = parser.nextToken(lexer.TokenKindName, lexer.TokenKindUInt) if err != nil { return } - qualifier := parser.token.Value().(string) - switch qualifier { - case "mut": - what.mutable = true - default: - err = parser.token.NewError ( - "unknown type qualifier \"" + qualifier + "\"", - infoerr.ErrorKindError) - return + if parser.token.Is(lexer.TokenKindName) { + // parse type qualifier + qualifier := parser.token.Value().(string) + switch qualifier { + case "mut": + what.mutable = true + default: + err = parser.token.NewError ( + "unknown type qualifier \"" + + qualifier + "\"", + infoerr.ErrorKindError) + return + } + } else { + // parse fixed array length + what.length = parser.token.Value().(uint64) } err = parser.nextToken()