Fix parsing bug with type declarations

This commit is contained in:
Mattia Giambirtone 2023-11-08 15:05:44 +01:00
parent 8cac75ecef
commit 13eea04e74
Signed by: nocturn9x
GPG Key ID: 8270F9F467971E59
1 changed files with 8 additions and 6 deletions

View File

@ -1232,7 +1232,7 @@ proc parseTypeFields(self: Parser): seq[tuple[name: IdentExpr, valueType: Expres
argPrivate: bool
argType: Expression
argDefault: Expression
while not self.match(RightBrace) and not self.done():
while not self.check(RightBrace) and not self.done():
self.expect(Identifier, "expecting type member name")
argName = newIdentExpr(self.peek(-1), self.scopeDepth)
argPrivate = not self.match("*")
@ -1261,15 +1261,16 @@ proc typeDecl(self: Parser): TypeDecl =
if self.match(LeftBracket):
self.parseGenerics(result)
self.expect("=", "expecting '=' after type name")
case self.peek().lexeme:
of "ref":
var hasNone = false
case self.peek().kind:
of Ref:
discard self.step()
self.expect("object", "expecting 'object' after 'ref'")
result.isRef = true
of "enum":
of Enum:
discard self.step()
result.isEnum = true
of "object":
of Object:
discard self.step()
else:
result.value = self.expression()
@ -1307,8 +1308,9 @@ proc typeDecl(self: Parser): TypeDecl =
result.members.add(variant)
if self.match(","):
continue
elif self.match("}"):
elif self.check("}"):
break
self.expect(RightBrace, "expecting '}' after type declaration")