From 7a1c8aa1369d5afbc8b76e0912bf7a8a226bcd94 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 8 Sep 2020 08:53:15 +0800 Subject: [PATCH] feat: init scope depdency --- scie-grammar/src/grammar/mod.rs | 1 - .../src/{grammar => }/grammar_registry.rs | 14 ++--- scie-grammar/src/lib.rs | 4 +- scie-grammar/src/scope_dependency.rs | 59 +++++++++++++++++++ scie-grammar/src/{ => support}/matcher.rs | 0 scie-grammar/src/support/mod.rs | 1 + scie-grammar/src/sync_register.rs | 4 ++ 7 files changed, 73 insertions(+), 10 deletions(-) rename scie-grammar/src/{grammar => }/grammar_registry.rs (73%) create mode 100644 scie-grammar/src/scope_dependency.rs rename scie-grammar/src/{ => support}/matcher.rs (100%) create mode 100644 scie-grammar/src/sync_register.rs diff --git a/scie-grammar/src/grammar/mod.rs b/scie-grammar/src/grammar/mod.rs index 0d2d645..bc8683d 100644 --- a/scie-grammar/src/grammar/mod.rs +++ b/scie-grammar/src/grammar/mod.rs @@ -1,6 +1,5 @@ pub mod grammar; pub mod grammar_reader; -pub mod grammar_registry; pub mod line_tokens; pub mod local_stack_element; diff --git a/scie-grammar/src/grammar/grammar_registry.rs b/scie-grammar/src/grammar_registry.rs similarity index 73% rename from scie-grammar/src/grammar/grammar_registry.rs rename to scie-grammar/src/grammar_registry.rs index 4b179dc..d59e5bd 100644 --- a/scie-grammar/src/grammar/grammar_registry.rs +++ b/scie-grammar/src/grammar_registry.rs @@ -28,15 +28,13 @@ impl GrammarRegistry { _initial_scope_name: String, _initial_language: i32, _configuration: IGrammarConfiguration, - ) { + ) {} + // todo: modify logic to here for _collectDependenciesForDep + pub fn _load_grammar(&self, initial_scope_name: String, _initial_language: i32, _token_type: Option) { } - // todo: modify logic to here for _collectDependenciesForDep - pub fn load_grammar( - &self, - _initial_scope_name: String, - _initial_language: i32, - _configuration: IGrammarConfiguration, - ) { + + pub fn load_grammar(&self, initial_scope_name: String) { + self._load_grammar(initial_scope_name, 0, None) } } diff --git a/scie-grammar/src/lib.rs b/scie-grammar/src/lib.rs index b7b986a..51a465e 100644 --- a/scie-grammar/src/lib.rs +++ b/scie-grammar/src/lib.rs @@ -11,6 +11,8 @@ extern crate regex; pub mod grammar; pub mod inter; -pub mod matcher; pub mod rule; pub mod support; +pub mod grammar_registry; +pub mod sync_register; +pub mod scope_dependency; diff --git a/scie-grammar/src/scope_dependency.rs b/scie-grammar/src/scope_dependency.rs new file mode 100644 index 0000000..92220ec --- /dev/null +++ b/scie-grammar/src/scope_dependency.rs @@ -0,0 +1,59 @@ +use crate::inter::IRawRule; +use std::collections::HashSet; + +#[derive(Clone, Debug, Serialize)] +pub struct PartialScopeDependency { + pub scope_name: String, + pub include: String +} + +impl PartialScopeDependency { + pub fn to_key(&self) -> String { + format!("{:?}#{:?}", self.scope_name, self.include) + } +} + +#[derive(Clone, Debug, Serialize)] +pub struct FullScopeDependency { + pub scope_name: String +} + +#[derive(Clone, Debug, Serialize)] +pub enum ScopeDependency { + FullScopeDependency(FullScopeDependency), + PartialScopeDependency(PartialScopeDependency) +} + +#[derive(Clone, Debug, Serialize)] +pub struct ScopeDependencyCollector { + pub full: Vec, + pub partial: Vec, + // pub visited_rule: HashSet, + pub _seen_full: HashSet, + pub _seen_partial: HashSet, +} + +impl ScopeDependencyCollector { + pub fn new() -> ScopeDependencyCollector { + ScopeDependencyCollector { + full: vec![], + partial: vec![], + // visited_rule: Default::default(), + _seen_full: Default::default(), + _seen_partial: Default::default() + } + } + + pub fn add(&mut self, dep: ScopeDependency) { + match dep { + ScopeDependency::FullScopeDependency(full_dep) => { + // self._seen_full.get_or_insert(full_dep.scope_name); + // self._seen_full.get(&*full_dep.scope_name.clone()); + }, + ScopeDependency::PartialScopeDependency(_) => { + + }, + } + } +} + diff --git a/scie-grammar/src/matcher.rs b/scie-grammar/src/support/matcher.rs similarity index 100% rename from scie-grammar/src/matcher.rs rename to scie-grammar/src/support/matcher.rs diff --git a/scie-grammar/src/support/mod.rs b/scie-grammar/src/support/mod.rs index d2f9fd3..70a0660 100644 --- a/scie-grammar/src/support/mod.rs +++ b/scie-grammar/src/support/mod.rs @@ -1 +1,2 @@ pub mod regex_source; +pub mod matcher; diff --git a/scie-grammar/src/sync_register.rs b/scie-grammar/src/sync_register.rs new file mode 100644 index 0000000..fe721bc --- /dev/null +++ b/scie-grammar/src/sync_register.rs @@ -0,0 +1,4 @@ +pub struct SyncRegister { + +} + -- GitLab