mani-language / Mani

Máni ... an awesome, super simple programming language!
https://mani-language.github.io/
Mozilla Public License 2.0
28 stars 7 forks source link

Add support for switch-case in mani #102

Closed ankitshubham97 closed 5 years ago

ankitshubham97 commented 5 years ago

name: Switch-case about: I have added the feature of switch-case to the language.

Is your PR related to a feature request or Bug report? If applicable, please list feature request number or bug report ID.

It is related to an improvement feature #79.

Describe your PR A clear and concise description of what your pull request is changing or adding.

It is adding the feature of switch statements.

Describe intended use A clear and concise description of the intended use of the feature. Along with example code.

From #79: The addition of switch statements would make this language just that little bit better. It would remove the need for mass amounts of if statements. Sample code:

let a = 1;
switch (a) {
case 1 :
say "a";
case 2 :
say "b";
case 3 :
say "c";
}

How did you fix the bug? If applicable, how did you fix the bug? Please use code snippets too.

N/A

Is it in the form of a library

If applicable what is the library called?

N/A

Does your PR replace an existing system If applicable, please describe how this PR changes the use of a related item.

No.

Additional comments Limitations:

crazywolf132 commented 5 years ago

Great work. I am just going to hold off merging until it supports more than one line per case.

I will add a WIP tag to the title.

ankitshubham97 commented 5 years ago

@crazywolf132 Commit 1625e28 now takes care of supporting more than one line per case.

ankitshubham97 commented 5 years ago

@crazywolf132 I have a query. In src/com/mani/lang/core/Interpreter.java,:

  @Override
  public Void visitBreakStmt(Stmt.Break stmt) {
    throw new Return();
  }

Why are we throwing a RuntimeException for 'break' statements? Is it because it is still unimplemented?

crazywolf132 commented 5 years ago

@ankitshubham97 That was just how i chose to take care of break statements. If you believe there is a better way, by all means. Feel free to change it.

If you think this is good to go, please create a test case for it. Then we can merge.

crazywolf132 commented 5 years ago

@Kalekdan Anything to add?

ankitshubham97 commented 5 years ago

@crazywolf132 Added test in c098248.

crazywolf132 commented 5 years ago

Great work

ankitshubham97 commented 5 years ago

Thanks! #79 can be closed now.