Skip to content

Updated run_prompt to handle multiline statements#50

Open
spralja wants to merge 3 commits intomainfrom
spralja/prompt-statement
Open

Updated run_prompt to handle multiline statements#50
spralja wants to merge 3 commits intomainfrom
spralja/prompt-statement

Conversation

@spralja
Copy link
Copy Markdown
Collaborator

@spralja spralja commented Mar 3, 2022

Previously multiline statements were not possible because the scanner automatically appends the EOF token

Originally I thought fixing this might involve complicate syntax checking like makin sure that all '(' are
closed etc.

I think this solution is the simplest to implement, that is that: every statement is ended with a empty input
(newline).

Previously multiline statements were not possible because the scanner automatically appends the EOF token

Originally I thought fixing this might involve complicate syntax checking like makin sure that all '(' are
closed etc.

I think this solution is the simplest to implement, that is every statement is ended with a empty input
(newline).
while True:
line = input("$ : ")
statement = line
while line:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its fine for now just not a nice user experience to press enter 2 times... An alternative might be to allow a specific keybinding (shift+enter) to insert a newline to stdin and stdout. Otherwise we can also implement something along these lines

while line.endsWith('{'):
   ...

This way it adds a newline when needed not everytime.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but what about

1 ==
1
;

There is just to many edge cases

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but shift enter thing sounds nice

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk I feel like that should be an error lol, or maybe we make it so it waits until ;?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(value) {
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its fine for now just not a nice user experience to press enter 2 times... An alternative might be to allow a specific keybinding (shift+enter) to insert a newline to stdin and stdout. Otherwise we can also implement something along these lines

while line.endsWith('{'):
   ...

This way it adds a newline when needed not everytime.

It seems that detecting shift+enter is not the easiest because it's platform dependent, with there being difficulty covering major systems (I'm personally using Ubuntu WSL and the most commonly used library doesn't support it)

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.

The parser should request the next line when a statement is not finished

2 participants