diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-11-02 13:22:00 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-11-02 13:22:00 +0100 |
commit | c655e653fce25f44cf10b2fbed564aadcff7235f (patch) | |
tree | 8f8e49a0e46dd338e18bbbaa2f4dc033aab9ea2e /vala/valaparser.vala | |
parent | 8152d9144c337925688bfd10d277fa167e913472 (diff) | |
download | vala-c655e653fce25f44cf10b2fbed564aadcff7235f.tar.gz |
parser: Split out Parser.parse_switch_section_statement()
Diffstat (limited to 'vala/valaparser.vala')
-rw-r--r-- | vala/valaparser.vala | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 93031cee1..02b69cc0a 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -2182,28 +2182,34 @@ public class Vala.Parser : CodeVisitor { var stmt = new SwitchStatement (condition, get_src (begin)); expect (TokenType.OPEN_BRACE); while (current () != TokenType.CLOSE_BRACE) { - begin = get_location (); - var section = new SwitchSection (get_src (begin)); - do { - if (accept (TokenType.CASE)) { - section.add_label (new SwitchLabel (parse_expression (), get_src (begin))); - while (current () == TokenType.COMMA) { - expect (TokenType.COMMA); - section.add_label (new SwitchLabel (parse_expression (), get_src (begin))); - } - } else { - expect (TokenType.DEFAULT); - section.add_label (new SwitchLabel.with_default (get_src (begin))); - } - expect (TokenType.COLON); - } while (current () == TokenType.CASE || current () == TokenType.DEFAULT); - parse_statements (section); - stmt.add_section (section); + stmt.add_section ((SwitchSection) parse_switch_section_statement ()); } expect (TokenType.CLOSE_BRACE); return stmt; } + Statement parse_switch_section_statement () throws ParseError { + var begin = get_location (); + var section = new SwitchSection (get_src (begin)); + do { + if (accept (TokenType.CASE)) { + section.add_label (new SwitchLabel (parse_expression (), get_src (begin))); + while (current () == TokenType.COMMA) { + expect (TokenType.COMMA); + section.add_label (new SwitchLabel (parse_expression (), get_src (begin))); + } + expect (TokenType.COLON); + } else if (accept (TokenType.DEFAULT)) { + section.add_label (new SwitchLabel.with_default (get_src (begin))); + expect (TokenType.COLON); + } else { + throw new ParseError.SYNTAX ("expected `case' or `default' switch label"); + } + } while (current () == TokenType.CASE || current () == TokenType.DEFAULT); + parse_statements (section); + return section; + } + Statement parse_while_statement () throws ParseError { var begin = get_location (); expect (TokenType.WHILE); |