UnionCompilerDesign / compiler_core

The core of the compiler, runtime, and builder setup.
MIT License
1 stars 1 forks source link

Parser - Switch Statements #100

Closed CalebLItalien closed 3 weeks ago

CalebLItalien commented 1 month ago

Details

Add support for switch, case, and default to the parser through a single unified function parse_switch_statement.

Issue Type

Requirements

Notes

CalebLItalien commented 4 weeks ago

@tbreimer14 are you using the match statement code for this? I think the match statement code should be pretty similar.

tbreimer14 commented 3 weeks ago

Exactly what I've been doing! Just think we need a parse_case_block method too to handle "break;" indicating the end of a case body.

CalebLItalien commented 3 weeks ago

We already have a 'parse_break' I believe? Do we want it to be a parser error if there isn't a break statement in a case?

tbreimer14 commented 3 weeks ago

Right, I forgot we don't actually need a break token to end a case block. I don't see a parse_break on the frontend branch, is that supposed to parse the token? I think we would still need a special method to parse a case body though, since it would end when the next case started, and not with a "}" like parse_block expects. Definitely could be wrong though, let me know if I'm misunderstanding something.