| 150 | } |
| 151 | |
| 152 | TokenKind::Mut => { |
| 153 | // Check for shorthand let (ident := expr) |
| 154 | if self.cursor.peek_n(1) == TokenKind::Ident |
| 155 | && self.cursor.peek_n(2) == TokenKind::ColonAssign |
| 156 | { |
| 157 | self.parse_shorthand_let_stmt() |
| 158 | } else { |
| 159 | self.parse_expr_stmt() |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | _ => self.parse_expr_stmt(), |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | pub fn token_to_visibility(token_kind: TokenKind) -> Visibility { |
| 169 | match token_kind { |
| 170 | TokenKind::Private => Visibility::Private, |
| 171 | TokenKind::Module => Visibility::Module, |
| 172 | TokenKind::Package => Visibility::Internal, |
| 173 | _ => Visibility::Public, |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | #[derive(Debug)] |
| 178 | pub struct ParseResult<'a, 'bump> { |
| 179 | pub statements: Vec<Stmt<'a, 'bump>, Arc<GrowableAtomicBump<'bump>>>, |
| 180 | pub diagnostics: ParserDiagnostics<'a>, |
| 181 | } |
| 182 | |
| 183 | pub fn parse_program<'a, 'bump>( |
| 184 | src: &str, |
| 185 | file_name: &'bump str, |
| 186 | context: Arc<StringPool>, |
| 187 | bump: Arc<GrowableAtomicBump<'bump>>, |
| 188 | ) -> ParseResult<'a, 'bump> { |
| 189 | let lexer: Lexer = Lexer::new(context.clone()); |
| 190 | let tokens: Tokens<'a, 'bump> = lexer.tokenize(src, file_name, bump.clone()); |