JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
88 stars 4 forks source link

Class parsing consumes newline if class is just one line #219

Closed JSAbrahams closed 2 years ago

JSAbrahams commented 2 years ago

Description of Bug

When parsing a class, when it is a single line, the newline at the end of the line is consumed by the parse class function. This causes the file parses to throw an exception because it expects a newline at the end of the line. The exception is thrown at the location of the next token.

Expected behavior

The class parses should not consume any newline token.

Probable fix

This is one situation where we need to peek multiple tokens ahead.

JSAbrahams commented 2 years ago

It should actually be possible to precede a block with an arbitrary amount of newlines. This functionality has been implemented in the case of classes, and when parsing blocks themselves. However, all other places which take blocks should peek ahead to see if there is (a string of) newlines before parsing a block. Should check, off the top of my head: