Skip to content

Commit

Permalink
refactor: split language module in two (language & tree)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpombrio committed Mar 21, 2024
1 parent 8b26474 commit f86fada
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 97 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use super::compiled::{
LanguageCompiled, LanguageId, NotationSetId, SortId,
};
use super::specs::{LanguageSpec, NotationSetSpec};
use crate::language::storage::Storage;
use crate::language::LanguageError;
use super::storage::Storage;
use super::LanguageError;
use crate::style::ValidNotation;
use crate::util::{bug, IndexedMap};

Expand Down
7 changes: 0 additions & 7 deletions src/language/language_set/mod.rs

This file was deleted.

15 changes: 5 additions & 10 deletions src/language/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
mod forest;
mod language_set;
mod location;
mod node;
mod compiled;
mod interface;
mod specs;
mod storage;
mod text;

use partial_pretty_printer as ppp;
use std::fmt;

pub use language_set::{
AritySpec, ConstructSpec, GrammarSpec, LanguageSpec, NotationSetSpec, SortSpec,
};
pub use location::Location;
pub use node::{Node, NodeId};
pub use interface::{Arity, Construct, Language};
pub use specs::{AritySpec, ConstructSpec, GrammarSpec, LanguageSpec, NotationSetSpec, SortSpec};
pub use storage::Storage;

#[derive(thiserror::Error, fmt::Debug)]
Expand Down
File renamed without changes.
22 changes: 6 additions & 16 deletions src/language/storage.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
use super::forest::Forest;
use super::language_set::{
compile_language, compile_notation_set, Language, LanguageCompiled, LanguageSpec,
NotationSetSpec,
};
use super::node::{Node, NodeData, NodeId};
use super::compiled::{compile_language, compile_notation_set, LanguageCompiled};
use super::interface::Language;
use super::specs::{LanguageSpec, NotationSetSpec};
use super::LanguageError;
use crate::tree::NodeForest;
use crate::util::IndexedMap;

/// Stores all documents and languages.
pub struct Storage {
pub(super) languages: IndexedMap<LanguageCompiled>,
pub(super) forest: Forest<NodeData>,
pub(super) next_id: NodeId,
pub(crate) node_forest: NodeForest,
}

impl Storage {
pub fn new() -> Storage {
Storage {
languages: IndexedMap::new(),
forest: Forest::new(NodeData::invalid_dummy()),
next_id: NodeId(0),
node_forest: NodeForest::new(),
}
}

Expand Down Expand Up @@ -49,12 +45,6 @@ impl Storage {
pub fn get_language(&self, name: &str) -> Option<Language> {
Some(Language::from_id(self.languages.id(name)?))
}

pub(super) fn next_id(&mut self) -> NodeId {
let id = self.next_id.0;
self.next_id.0 += 1;
NodeId(id)
}
}

impl Default for Storage {
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
mod language;
mod pretty_doc;
mod style;
mod tree;
mod util;

pub use language::{
AritySpec, ConstructSpec, GrammarSpec, LanguageSpec, Location, Node, NotationSetSpec, SortSpec,
Storage,
AritySpec, ConstructSpec, GrammarSpec, LanguageSpec, NotationSetSpec, SortSpec, Storage,
};
pub use pretty_doc::DocRef;
pub use tree::{Location, Node};
3 changes: 2 additions & 1 deletion src/pretty_doc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::language::{Location, Node, NodeId, Storage};
use crate::language::Storage;
use crate::style::{
Condition, CursorHalf, Style, StyleLabel, ValidNotation, HOLE_STYLE, LEFT_CURSOR_STYLE,
RIGHT_CURSOR_STYLE,
};
use crate::tree::{Location, Node, NodeId};
use crate::util::{bug, SynlessBug};
use partial_pretty_printer as ppp;
use std::fmt;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/language/location.rs → src/tree/location.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::node::Node;
use super::storage::Storage;
use crate::language::Storage;

/// A location between nodes, or within text, where a cursor could go.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
8 changes: 8 additions & 0 deletions src/tree/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod forest;
mod location;
mod node;
mod text;

pub use location::Location;
pub(crate) use node::NodeForest;
pub use node::{Node, NodeId};
Loading

0 comments on commit f86fada

Please sign in to comment.