Skip to content

Commit

Permalink
t2
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Nov 23, 2024
1 parent aa97cbb commit d7b6480
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
pub struct InternalCompilation {}
use std::collections::BTreeMap;
use std::rc::Rc;

use semver::Version;

use crate::parser::{ParseOutput, Parser, ParserInitializationError};

pub enum FileEntry {
Resolved {
id: String,

parse_output: ParseOutput,
},
Unresolved,
}

#[derive(thiserror::Error, Debug)]
pub enum CompilationInitializationError {
#[error("Unsupported language version '{0}'.")]
UnsupportedLanguageVersion(Version),
}

pub struct Compilation {
parser: Parser,
files: BTreeMap<String, FileEntry>,
}

impl Compilation {
pub fn create(version: Version) -> std::result::Result<Self, CompilationInitializationError> {
let parser = match Parser::create(version) {
Ok(parser) => parser,
Err(ParserInitializationError::UnsupportedLanguageVersion(version)) => {
return Err(CompilationInitializationError::UnsupportedLanguageVersion(
version,
));
}
};

Ok(Self {
parser,
files: BTreeMap::new(),
})
}

pub fn version(&self) -> &Version {
&self.parser.version
}

pub fn add_file(&mut self, id: String, contents: &str) {


let parse_output = self.parser.parse(Parser::ROOT_KIND, contents);

self.files
.insert(id.clone(), File(Rc::new(FileData { id, parse_output })));
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d7b6480

Please sign in to comment.