Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent significant spaces #792

Open
Darvass69 opened this issue Jan 18, 2025 · 6 comments
Open

Inconsistent significant spaces #792

Darvass69 opened this issue Jan 18, 2025 · 6 comments

Comments

@Darvass69
Copy link

Darvass69 commented Jan 18, 2025

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?

@TodePond
Copy link
Owner

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
Copy link
Owner

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

@Darvass69
Copy link
Author

Darvass69 commented Jan 18, 2025

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
Copy link
Author

Darvass69 commented Jan 18, 2025

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
Copy link
Author

Darvass69 commented Jan 18, 2025

Are these expressions equivalent and valid?

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

·add··3,··add··56····!
·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!
b··*··c
+b··*c

@TodePond
Copy link
Owner

Are these expressions equivalent and valid?

yes of course

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants