UnionCompilerDesign / compiler_core

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

Parser - Switch Statements #129

Closed tbreimer14 closed 3 weeks ago

tbreimer14 commented 3 weeks ago

This closes #100

tbreimer14 commented 3 weeks ago

@CalebLItalien I removed SynatxElement::CaseVal and changed the privacy of the two helper methods in the last push. My initial thought for having a separate CaseVal element was that maybe it would be nice for SemAnalysis, since it would only have to look for a BlockExp and CaseVal as children for a Case SyntaxElement. But I agree that would be redundant as SemAnalysis would just have to pry into the CaseVal anyways to see if the actual value was a valid SyntaxElement.

I think that parse_case_block should keep that name, though. That method actually does the work of creating the BlockExp, and hands it to parse_switch_cases which then constructs each Case Syntax Element. I thought it necessary to have a parse_case_block instead of using parse_block since parse_block only looks for a "}" token to end the block, but I think for parsing a switch statement we also have to look for case or default token as well, since Case blocks aren't wrapped by parentheses. I feel like this is kind of unusual and perhaps case blocks aren't truly "blocks," but I'm not sure.