sudachi/plugin/connect_cost/
mod.rs

1/*
2 * Copyright (c) 2021-2024 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
17mod inhibit_connection;
18
19use serde_json::Value;
20
21use crate::config::Config;
22use crate::dic::grammar::Grammar;
23use crate::plugin::connect_cost::inhibit_connection::InhibitConnectionPlugin;
24use crate::plugin::PluginCategory;
25use crate::prelude::*;
26
27/// Trait of plugin to edit connection cost in the grammar
28pub trait EditConnectionCostPlugin: Sync + Send {
29    /// Loads necessary information for the plugin
30    fn set_up(&mut self, settings: &Value, config: &Config, grammar: &Grammar)
31        -> SudachiResult<()>;
32
33    /// Edits the grammar
34    fn edit(&self, grammar: &mut Grammar);
35}
36
37impl PluginCategory for dyn EditConnectionCostPlugin {
38    type BoxType = Box<dyn EditConnectionCostPlugin + Sync + Send>;
39    type InitFnType = unsafe fn() -> SudachiResult<Self::BoxType>;
40
41    fn configurations(cfg: &Config) -> &[Value] {
42        &cfg.connection_cost_plugins
43    }
44
45    fn bundled_impl(name: &str) -> Option<Self::BoxType> {
46        match name {
47            "InhibitConnectionPlugin" => Some(Box::<InhibitConnectionPlugin>::default()),
48            _ => None,
49        }
50    }
51
52    fn do_setup(
53        ptr: &mut Self::BoxType,
54        settings: &Value,
55        config: &Config,
56        grammar: &mut Grammar,
57    ) -> SudachiResult<()> {
58        ptr.set_up(settings, config, grammar)
59    }
60}