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

feat: multiline expressions #2871

Merged
merged 6 commits into from
Jul 1, 2024
Merged

feat: multiline expressions #2871

merged 6 commits into from
Jul 1, 2024

Conversation

Julusian
Copy link
Member

@Julusian Julusian commented May 21, 2024

This provides a bunch of improvements to expressions.

The most visible difference is that expression input fields are now displayed as multiline:
image

Expression input fields will now validate their expression in the ui, and will show as red when it failed to parse (execution is not tested)

Additionally, to make this more friendly, it includes some new syntax:

  • Comments are now allowed. Same as javascript, both // and /* ... */
  • Expressions can be multiline. Arbitrary line breaks are allowed, which allows for better formatting.
  • return is a supported operation. Not exactly useful right now, but this can be nice to make an expression more readable in what the output value is
  • It is possible to define intermediary variable inside an expression. Something such as a = 1 ; return a + 2 is now valid and will compute a value of 3. The values of these are not persisted outside of the execution the expression.
  • The 'full' range of assignment operators is functional, including things like +=, and ++

Combine all of these, and you can now break up long complex expressions into multiple stages, with comments and intermediary variables.
The value of the last statement is taken as the output. eg 10 20 30 is 3 statements, and the result will be 30.

The statement parsing isn't perfect js, the parser is allowing multiple statements on a single line separated by only a space. I worry that this could result in the parsing being more brittle, but I'm not sure if we should be worried about that.

Maybe next could be support for full if statements, or loops, but not as part of this PR.

@Julusian Julusian force-pushed the feat/multiline-expressions branch from 3af9fd6 to 0e605dc Compare June 20, 2024 19:14
@Julusian Julusian force-pushed the feat/multiline-expressions branch from 0e605dc to 4b9cf2b Compare June 20, 2024 19:41
@Julusian Julusian marked this pull request as ready for review June 20, 2024 19:41
@Julusian Julusian merged commit b017e2b into main Jul 1, 2024
13 of 14 checks passed
@Julusian Julusian deleted the feat/multiline-expressions branch July 1, 2024 13:56
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

Successfully merging this pull request may close these issues.

1 participant