rule.rs 1.4 KB
Newer Older
1
use crate::inter::{IRawRepository, IRawGrammar, ILocation};
2

P
Phodal Huang 已提交
3
pub struct RuleFactory {}
4 5

impl RuleFactory {
P
Phodal Huang 已提交
6
    pub fn get_compiled_rule_id(repository: IRawRepository, helper: Box<&dyn IRuleFactoryHelper>) {}
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21
    pub fn create_capture_rule() {}
}


pub struct Rule {
    pub location: ILocation,
    pub id: i32,
    pub name: Option<String>,
    pub content_name: Option<String>,
}

impl Rule {
    pub fn new(location: ILocation, id: i32, name: Option<String>, content_name: Option<String>) -> Self {
        Rule { location, id, name, content_name }
22
    }
23
}
24

P
Phodal Huang 已提交
25
pub trait AbstractRule {}
26 27 28

pub struct IncludeOnlyRule {
    pub rule: Rule
P
Phodal Huang 已提交
29
}
P
Phodal Huang 已提交
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
impl AbstractRule for IncludeOnlyRule {}

pub struct BeginWhileRule {
    pub rule: Rule
}

impl AbstractRule for BeginWhileRule {}

pub struct MatchRule {
    pub rule: Rule
}

impl AbstractRule for MatchRule {}

pub struct BeginEndRule {
    pub rule: Rule
}

impl AbstractRule for BeginEndRule {}

pub struct CaptureRule {
    pub rule: Rule
}

impl AbstractRule for CaptureRule {}


P
Phodal Huang 已提交
58 59 60
// todo: trait with types
// https://users.rust-lang.org/t/impl-trait-with-generic-function-for-generic-struct/27083/2
pub trait IRuleRegistry {
61
    fn get_rule(&self, pattern_id: i32) -> Rule;
P
Phodal Huang 已提交
62 63 64 65 66
    // fn register_rule(&self);
}

pub trait IGrammarRegistry {
    fn get_external_grammar(&self, scope_name: String, repository: IRawRepository) -> Option<IRawGrammar>;
P
Phodal Huang 已提交
67 68 69
}

pub trait IRuleFactoryHelper: IGrammarRegistry + IRuleRegistry {}