| 82 | } |
| 83 | |
| 84 | pub fn parse(&mut self) -> Result<Module, ParsingError> { |
| 85 | let node = self.start_node(); |
| 86 | let mut body = vec![]; |
| 87 | while self.cur_kind() != Kind::Eof { |
| 88 | if self.consume_whitespace_and_comments() { |
| 89 | continue; |
| 90 | } |
| 91 | let stmt = if is_at_compound_statement(self.cur_token()) { |
| 92 | self.parse_compound_statement() |
| 93 | } else { |
| 94 | self.parse_simple_statement() |
| 95 | }; |
| 96 | match stmt { |
| 97 | Ok(stmt) => body.push(stmt), |
| 98 | Err(err) => return Err(err), |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | let mut node = self.finish_node(node); |
| 103 | // Remove the EOF offset |
| 104 | node.end.saturating_sub(1); |
| 105 | |
| 106 | Ok(Module::new(node, body)) |
| 107 | } |
| 108 | |
| 109 | fn start_node(&self) -> Node { |
| 110 | let token = self.cur_token(); |