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

Improve return statement #7

Open
epatrizio opened this issue Oct 20, 2023 · 2 comments
Open

Improve return statement #7

epatrizio opened this issue Oct 20, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@epatrizio
Copy link
Owner

Many questions came up during return implementation about adding some syntax strong controls.
for example, return options only in a specific context (in a function blocks for example)

Where to implement this stuff : in menhir parser.mly ?
What is the best practice ?

béta version :
67691ab

Spec :
https://www.lua.org/manual/5.4/manual.html#3.3.4

@epatrizio epatrizio added the help wanted Extra attention is needed label Oct 20, 2023
@epatrizio
Copy link
Owner Author

Same issue with break statement :
break must be inside a loop (for, while, repeat)

@epatrizio
Copy link
Owner Author

Idea for break statement implementation in parser.mly :

let block_no_break :=
  | stats = list(stat); retstat = option(retstat); {
    if List.for_all (fun stat -> stat <> Sbreak) stats then 
      match retstat with
      | None -> stats
      | Some retstat -> stats @ [ retstat ]
    else error "break statement outside a loop"
}

But it seems a bit tricky to implement.
For example, if true then break end isn't possible in chunk but ok in a for block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant