Skip to main content

sudachi/dic/read/
error.rs

1/*
2 *  Copyright (c) 2025 Works Applications Co., Ltd.
3 *
4 *  Licensed under the Apache License, Version 2.0 (the "License");
5 *  you may not use this file except in compliance with the License.
6 *  You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *   Unless required by applicable law or agreed to in writing, software
11 *  distributed under the License is distributed on an "AS IS" BASIS,
12 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 *  See the License for the specific language governing permissions and
14 *  limitations under the License.
15 */
16
17pub type SudachiNomResult<I, O> = nom::IResult<I, O, SudachiNomError<I>>;
18
19/// Custum nom error
20#[derive(Debug, PartialEq)]
21pub enum SudachiNomError<I> {
22    /// Failed to parse utf16 string
23    Utf16String,
24    /// Failed to parse utf8 string
25    Utf8String,
26    /// Failed to parse variable-length integer
27    InvalidVarInt,
28    Nom(I, nom::error::ErrorKind),
29    OutOfBounds(String, usize, usize),
30}
31
32impl<I> nom::error::ParseError<I> for SudachiNomError<I> {
33    fn from_error_kind(input: I, kind: nom::error::ErrorKind) -> Self {
34        SudachiNomError::Nom(input, kind)
35    }
36    fn append(_: I, _: nom::error::ErrorKind, other: Self) -> Self {
37        other
38    }
39}