Parse an expression from a byte slice. # Errors - Lexer errors if the input contains invalid tokens - Parser errors if the tokens don't form a valid expression - Unexpected EOF if the input is incomplete
(&mut self, source: &[u8])
| 49 | /// - Parser errors if the tokens don't form a valid expression |
| 50 | /// - Unexpected EOF if the input is incomplete |
| 51 | pub fn parse_expr(&mut self, source: &[u8]) -> Result<Expr<'heap>, JExprDiagnostic> { |
| 52 | let lexer = lexer::Lexer::new(source); |
| 53 | |
| 54 | let mut state = ParserState::new(self.heap, lexer, self.spans); |
| 55 | |
| 56 | let expr = parser::expr::parse_expr(&mut state) |
| 57 | .change_category(JExprDiagnosticCategory::Parser)?; |
| 58 | |
| 59 | state |
| 60 | .finish() |
| 61 | .change_category(JExprDiagnosticCategory::Parser)?; |
| 62 | |
| 63 | Ok(expr) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | #[cfg(test)] |
no test coverage detected