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

Block expressions #102

Open
metamorphix opened this issue May 4, 2023 · 14 comments
Open

Block expressions #102

metamorphix opened this issue May 4, 2023 · 14 comments
Labels
enhancement New feature or request experimental The changes may break something or be a bad idea

Comments

@metamorphix
Copy link
Contributor

Currently, Clue does not support (first-class) block expressions.

The main challenge with introducing block expressions to Clue is how to distinguish them from table expressions.

@Maiori44 Maiori44 added enhancement New feature or request experimental The changes may break something or be a bad idea labels May 4, 2023
@Markos-Th09
Copy link
Member

Markos-Th09 commented May 4, 2023

We never really planned on doing this but here is a possible syntax

local result = {
  local a = 1
  local b = 2
  
  return a+b
}
local result

do
   local a = 1
   local b = 2
   result = a+b
end

@Maiori44
Copy link
Member

Maiori44 commented May 4, 2023

Not only tables, everything else that uses {} will cause issues

if {...} {
   //...
}

what is {...}? a table? or a code block?
({}) could fix this if we allow code blocks to be wrapped in (), I guess. (that still leaves confusion between code block and table though.)

@Maiori44
Copy link
Member

Maiori44 commented May 4, 2023

We never really planned on doing this but here is a possible syntax

local result = {
  local a = 1
  local b = 2
  
  return a+b
}
local result

do
   local a = 1
   local b = 2
   result = a+b
end

figuring out if it's a code block and not a table is the issue though.

@Markos-Th09
Copy link
Member

The solutions to these kind of problems are heuristics. With a heuristic parser it should be able to efficiently parse and differentiate between them.

@Markos-Th09
Copy link
Member

Markos-Th09 commented May 4, 2023

Also about the ambiguity, anything in the form of {...} or {a+b} and {0} is a table

@Maiori44
Copy link
Member

Maiori44 commented May 4, 2023

Also about the ambiguity, anything in the form of {...} or {a+b} and {0} is a table

but {a=3} is also a table, but is also completely valid as a code block too

@Maiori44
Copy link
Member

Maiori44 commented May 4, 2023

The solutions to these kind of problems are heuristics. With a heuristic parser it should be able to efficiently parse and differentiate between them.

No idea what this is lol

@Markos-Th09
Copy link
Member

Markos-Th09 commented May 4, 2023

Also about the ambiguity, anything in the form of {...} or {a+b} and {0} is a table

but {a=3} is also a table, but is also completely valid as a code block too

yeah there is too much ambiguity to this. The only solution to not be ambiguous is to always require a trailing comma on single element tables

@Markos-Th09
Copy link
Member

The solutions to these kind of problems are heuristics. With a heuristic parser it should be able to efficiently parse and differentiate between them.

No idea what this is lol

it is sort of making an educated guess

@Maiori44
Copy link
Member

Maiori44 commented May 4, 2023

The solutions to these kind of problems are heuristics. With a heuristic parser it should be able to efficiently parse and differentiate between them.

No idea what this is lol

it is sort of making an educated guess

ah, I see

@Markos-Th09
Copy link
Member

a hypothetical solution would be to have something like do {}

@Markos-Th09
Copy link
Member

Markos-Th09 commented May 4, 2023

Or another solution is that unless it has a return it is not a block expression as returning nothing cannot be used for anything meaningful

edit: just to be specific, I mean implicitly nothing, return nil or return is a block

@Maiori44
Copy link
Member

Maiori44 commented May 4, 2023

a hypothetical solution would be to have something like do {}

I don't like this idea myself, feels a bit too verbose

(ironic considering meta with exists)

@Maiori44
Copy link
Member

Maiori44 commented May 4, 2023

Or another solution is that unless it has a return it is not a block expression that can be used for anything meaningful

That may be the best solution, but it would require a bunch more moving around in the code for the parser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request experimental The changes may break something or be a bad idea
Projects
None yet
Development

No branches or pull requests

3 participants