(error: &SyntaxError)
| 56 | } |
| 57 | |
| 58 | fn format_syntax_error(error: &SyntaxError) -> String { |
| 59 | match error { |
| 60 | SyntaxError::UnexpectedToken(_, byte, _) => { |
| 61 | let ch = *byte as char; |
| 62 | if ch.is_ascii_graphic() { |
| 63 | format!("Syntax error: unexpected character `{ch}`") |
| 64 | } else { |
| 65 | format!("Syntax error: unexpected byte 0x{byte:02X}") |
| 66 | } |
| 67 | } |
| 68 | SyntaxError::UnrecognizedToken(_, byte, _) => { |
| 69 | let ch = *byte as char; |
| 70 | if ch.is_ascii_graphic() { |
| 71 | format!("Syntax error: unrecognized character `{ch}`") |
| 72 | } else { |
| 73 | format!("Syntax error: unrecognized byte 0x{byte:02X}") |
| 74 | } |
| 75 | } |
| 76 | SyntaxError::UnexpectedEndOfFile(_, _) => { |
| 77 | "Syntax error: unexpected end of file".to_string() |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /// Build a human-friendly comma-separated list of expected tokens. |
| 83 | /// |
no outgoing calls
no test coverage detected