1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
#[derive(Debug, PartialEq)] pub struct ParserError { pub info: Option<ErrorInfo>, pub kind: ErrorKind, } #[derive(Debug, PartialEq)] pub struct ErrorInfo { pub slice: String, pub line: usize, pub pos: usize, } #[derive(Debug, PartialEq)] pub enum ErrorKind { Generic, ExpectedEntry, ExpectedToken { token: char }, ExpectedCharRange { range: String }, ExpectedMessageField { entry_id: String }, ExpectedTermField { entry_id: String }, ForbiddenWhitespace, ForbiddenCallee, ForbiddenKey, MissingDefaultVariant, MissingVariants, MissingValue, MissingVariantKey, MissingLiteral, MultipleDefaultVariants, MessageReferenceAsSelector, VariantAsSelector, MessageAttributeAsSelector, TermAttributeAsSelector, UnterminatedStringExpression, } pub fn get_error_desc(err: &ErrorKind) -> (&'static str, String, &'static str) { match err { ErrorKind::Generic => ("E0001", "generic error".to_owned(), ""), ErrorKind::ExpectedEntry => ( "E0002", "Expected an entry start".to_owned(), "Expected one of ('a'...'Z' | '_' | #') here", ), ErrorKind::ExpectedToken { token } => ("E0003", format!("expected token `{}`", token), ""), ErrorKind::ExpectedCharRange { range } => ( "E0004", format!("Expected a character from range ({})", range), "", ), ErrorKind::ExpectedMessageField { entry_id } => ( "E0005", format!( "Expected message `{}` to have a value or attributes", entry_id ), "", ), ErrorKind::ExpectedTermField { entry_id } => ( "E0006", format!("Expected term `{}` to have a value", entry_id), "", ), ErrorKind::ForbiddenWhitespace => ( "E0007", "Keyword cannot end with a whitespace".to_owned(), "", ), ErrorKind::ForbiddenCallee => ( "E0008", "The callee has to be a simple, upper-case, identifier".to_owned(), "", ), ErrorKind::ForbiddenKey => ( "E0009", "The key has to be a simple identifier".to_owned(), "", ), ErrorKind::MissingDefaultVariant => ( "E0010", "Expected one of the variants to be marked as default (*).".to_owned(), "", ), ErrorKind::MissingVariants => ( "E0011", "Expected at least one variant after \"->\".".to_owned(), "", ), ErrorKind::MissingValue => ("E0012", "Expected value".to_owned(), ""), ErrorKind::MissingVariantKey => ("E0013", "Expected variant key".to_owned(), ""), ErrorKind::MissingLiteral => ("E0014", "Expected literal".to_owned(), ""), ErrorKind::MultipleDefaultVariants => ( "E0015", "Only one variant can be marked as default (*)".to_owned(), "", ), ErrorKind::MessageReferenceAsSelector => ( "E0016", "Message references cannot be used as selectors".to_owned(), "", ), ErrorKind::VariantAsSelector => ( "E0017", "Variants cannot be used as selectors".to_owned(), "", ), ErrorKind::MessageAttributeAsSelector => ( "E0018", "Attributes of messages cannot be used as selectors.".to_owned(), "", ), ErrorKind::TermAttributeAsSelector => ( "E0019", "Attributes of terms cannot be used as selectors.".to_owned(), "", ), ErrorKind::UnterminatedStringExpression => { ("E0020", "Underminated string expression".to_owned(), "") } } }