Download qataaum/compiler/parser/src/error.rs from Snapkitty/sov-kernel-monster: direct link, hf CLI and curl.
- Browser
- Download file 2.87 kB
-
https://huggingface.co/Snapkitty/sov-kernel-monster/resolve/main/qataaum/compiler/parser/src/error.rs
- Command line
-
hf download hf://Snapkitty/sov-kernel-monster/qataaum/compiler/parser/src/error.rs
-
curl -L -o error.rs https://huggingface.co/Snapkitty/sov-kernel-monster/resolve/main/qataaum/compiler/parser/src/error.rs
2.87 kB
| //! Parser error types | |
| //! | |
| //! Clean-room implementation - not derived from Qiskit | |
| use std::fmt; | |
| /// Result type for parser operations | |
| pub type ParseResult<T> = Result<T, ParseError>; | |
| /// Parser error types | |
| pub enum ParseError { | |
| /// Lexical error - invalid token | |
| LexError { | |
| message: String, | |
| line: usize, | |
| column: usize, | |
| }, | |
| /// Syntax error - unexpected token | |
| SyntaxError { | |
| expected: String, | |
| found: String, | |
| line: usize, | |
| column: usize, | |
| }, | |
| /// Semantic error - valid syntax but invalid meaning | |
| SemanticError { | |
| message: String, | |
| line: usize, | |
| column: usize, | |
| }, | |
| /// Version mismatch | |
| VersionError { | |
| expected: String, | |
| found: String, | |
| }, | |
| /// Unsupported feature | |
| UnsupportedFeature { | |
| feature: String, | |
| line: usize, | |
| column: usize, | |
| }, | |
| /// End of file reached unexpectedly | |
| UnexpectedEof { | |
| expected: String, | |
| }, | |
| } | |
| impl fmt::Display for ParseError { | |
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| match self { | |
| ParseError::LexError { message, line, column } => { | |
| write!(f, "Lexical error at {}:{}: {}", line, column, message) | |
| } | |
| ParseError::SyntaxError { expected, found, line, column } => { | |
| write!( | |
| f, | |
| "Syntax error at {}:{}: expected {}, found {}", | |
| line, column, expected, found | |
| ) | |
| } | |
| ParseError::SemanticError { message, line, column } => { | |
| write!(f, "Semantic error at {}:{}: {}", line, column, message) | |
| } | |
| ParseError::VersionError { expected, found } => { | |
| write!(f, "Version error: expected {}, found {}", expected, found) | |
| } | |
| ParseError::UnsupportedFeature { feature, line, column } => { | |
| write!( | |
| f, | |
| "Unsupported feature at {}:{}: {}", | |
| line, column, feature | |
| ) | |
| } | |
| ParseError::UnexpectedEof { expected } => { | |
| write!(f, "Unexpected end of file: expected {}", expected) | |
| } | |
| } | |
| } | |
| } | |
| impl std::error::Error for ParseError {} | |
| mod tests { | |
| use super::*; | |
| fn test_error_display() { | |
| let err = ParseError::LexError { | |
| message: "invalid character".to_string(), | |
| line: 1, | |
| column: 5, | |
| }; | |
| assert_eq!( | |
| err.to_string(), | |
| "Lexical error at 1:5: invalid character" | |
| ); | |
| } | |
| } | |
| // Made with Bob | |