Fix trailing comma handling in ParseFieldlist

This is pretty ugly since it checks for every token type that could follow to make it a valid field but the previous check was flat out wrong
This commit is contained in:
0x4261756D 2024-02-21 16:01:58 +01:00
parent 83b0416c03
commit 04f5804dff

View File

@ -1186,11 +1186,12 @@ class Parser
while(index < tokens.Length && IsFieldsep(tokens[index])) while(index < tokens.Length && IsFieldsep(tokens[index]))
{ {
index += 1; index += 1;
fields.Add(ParseField(tokens)); if(index < tokens.Length && tokens[index].type is TokenType.SquareOpen or
} TokenType.Name or TokenType.Nil or TokenType.True or TokenType.False or TokenType.Numeral or TokenType.StringLiteral or
if(index < tokens.Length && IsFieldsep(tokens[index])) TokenType.DotDotDot or TokenType.CurlyOpen or TokenType.Function or TokenType.Minus or TokenType.Hash or TokenType.Not or TokenType.Nil or TokenType.RoundOpen)
{ {
index += 1; fields.Add(ParseField(tokens));
}
} }
// NOTE: Since at least 1 field is parsed the list accesses are safe // NOTE: Since at least 1 field is parsed the list accesses are safe
return new FieldlistNode(exps: fields, startRegion: fields[0].startRegion, endRegion: fields[^1].endRegion); return new FieldlistNode(exps: fields, startRegion: fields[0].startRegion, endRegion: fields[^1].endRegion);