GulfOfMexico icon indicating copy to clipboard operation
GulfOfMexico copied to clipboard

Inconsistent significant spaces

Open Darvass69 opened this issue 11 months ago • 6 comments

I found some inconsistencies with significant whitespace and functions in code containing parentheses. Here are some examples from the README, but inconsistencies and errors are also present in the examples and the testing suite. (some spaces are marked with '•︎' to make them easier to see)

Most spaces are fine and look like this:

print(await next score)!
name.pop()!
print(2 + 2 === 5)!
const var player1 = new Player()!

// Replacing parentheses with spaces
print•︎await•︎next•︎score•︎!
name.pop•︎•!
print•︎2•︎+•︎2•︎===•︎5•︎!
const•︎var•︎player1•︎=•︎new•︎Player•︎•︎!

// Gives a grouping like this
(print await next score)!
(name.pop)!
(print 2 + 2 === 5)!
(const var player1 = new Player)!

But sometimes, we have something that breaks the pattern.

Date.now() -= 3600000!
Date.now•︎•︎•︎-=•︎3600000!
(Date.now)(-= 3600000)!
// should be
Date.now•︎•︎•︎-=•︎•︎•︎3600000!
(Date.now) -= (3600000)!
(add (3, (add (5, 6))))!
•︎add•︎•︎3,•︎•︎add•︎•︎5,•︎6•︎•︎•︎•︎!
(add 3, add (5, 6))!
// should be either
add•︎•︎3,•︎•︎add•︎5,•︎6•︎•︎•︎•︎!
(add 3, (add 5, 6))!
// or
add•︎•︎•︎3,•︎•︎add•︎•︎5,•︎6•︎•︎•︎•︎!
add (3, add (5, 6))!

And function declaration often don’t work.

function add(a, b) => a + b!
function•︎add•︎a,•︎b•︎•︎=>•︎a•︎+•︎b!
(function add a, b) (=> a + b)!

function main() => {}
function•︎main•︎•︎•︎=>•︎{}
(function main) (=> {})

addEventListener("keydown", (e) => keys[e.key] = true)!
addEventListener•︎"keydown",•︎•︎e•︎•︎=>•︎keys[e.key]•︎=•︎true•︎!
(addEventListener "keydown",)  e  (=> keys[e.key] = true )!

addEventListener("click", () => score++)!
addEventListener•︎"click",•︎•︎•︎•︎=>•︎score++•︎!
(addEventListener "click",) (=> score++)!

So, what is the intended way of marking function calls and declaration? Are there more than 1 valid way?

Darvass69 avatar Jan 18 '25 01:01 Darvass69

the testing suite uses intentionally forgiving spacing because they were specifically made to test an incomplete implementation. the readme and examples are the source of truth

TodePond avatar Jan 18 '25 07:01 TodePond

you are under the wrong impression of how the grouping works and you have just discovered one of the reasons why building a dreamberd compiler is incredibly hard

TodePond avatar Jan 18 '25 07:01 TodePond

Can you elaborate on how it works and what I got wrong? My concern is that if it allows to much freedom, it might make ambiguous syntax that can’t be resolved.

Darvass69 avatar Jan 18 '25 16:01 Darvass69

Also, how are statements affected by spaces? Or what happens if we have an indented block, and continue an expression on a new line? Like this:

if (true) {
   const const a = 1 *
   1 + 2! // what do we do with spaces on this line here?
}

I would like clear rules on what is supposed to work, and what doesn’t.

Darvass69 avatar Jan 18 '25 17:01 Darvass69

Are these expressions equivalent and valid?

(add (3, (add (5, 6))))!
(add (3, (add (5,  6))))!

·add··3,··add··5,·6····!
·add··3,··add··5,··6····!
function add(a, b) => a + b!
function    add(a, b) => a + b!
function add    (    a, b) => a + b!
function add(a,        b) => a + b!
function add(a, b      )          => a + b!
function add(a, b) =>          a + b!
a·+·b··*··c
a·+b··*c

Darvass69 avatar Jan 18 '25 23:01 Darvass69

Are these expressions equivalent and valid?

yes of course

TodePond avatar Jan 19 '25 00:01 TodePond