Skip to content

Commit

Permalink
feat(lura-js): add some kind of resilient generator
Browse files Browse the repository at this point in the history
  • Loading branch information
aripiprazole committed Nov 13, 2023
1 parent c0758c3 commit 2ec5ed6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
10 changes: 2 additions & 8 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions lura-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ fn main() -> eyre::Result<()> {
.get_in_db(&manifest.db, &package)
.ok_or_else(|| eyre!("could not locate the package"))?;

let source = lura_js::dump_into_string(manifest.db, current_source)?;
let mut source = Vec::new();
if let Err(err) = lura_js::dump_into_string(manifest.db, current_source, &mut source) {
eprintln!("{err}");
}

println!("{}", source)
println!("{}", String::from_utf8(source)?);
}

lura_ariadne::AriadneReport::default()
Expand Down
4 changes: 2 additions & 2 deletions lura-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ im.workspace = true

axum = "0.6.20"
deno_core = "0.229.0"
resast = "0.5.0"
resw = "0.5.1"
resast = "0.4.1"
resw = "0.5.0"
eyre.workspace = true
32 changes: 29 additions & 3 deletions lura-js/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{path::Path, rc::Rc};

use deno_core::{error::AnyError, FastString};
use eyre::{bail, eyre};
use lura_hir::source::top_level::TopLevel;
use lura_hir::{
solver::Definition,
source::{expr::Expr, HirSource},
Expand Down Expand Up @@ -52,7 +54,31 @@ pub fn walk_on_expr<'a>(db: &dyn HirDb, expr: Expr) -> js::Expr<'a> {
}
}

pub fn dump_into_string(db: &dyn HirDb, source: HirSource) -> eyre::Result<String> {
let _ = (db, source);
todo!()
pub fn transform_top_level(db: &dyn HirDb, top_level: TopLevel) -> eyre::Result<js::ProgramPart> {
let _ = db;
match top_level {
TopLevel::Error(_) => bail!("errors are not supported"),
TopLevel::Using(_) => bail!("using are not supported"),
TopLevel::Command(_) => bail!("commands are not supported"),
TopLevel::BindingGroup(_) => bail!("binding declarations are not supported"),
TopLevel::ClassDecl(_) => bail!("class declarations are not supported"),
TopLevel::InstanceDecl(_) => bail!("instance declarations are not supported"),
TopLevel::TraitDecl(_) => bail!("trait declarations are not supported"),
TopLevel::DataDecl(_) => bail!("data declarations are not supported"),
TopLevel::TypeDecl(_) => bail!("type declarations are not supported"),
}
}

pub fn dump_into_string<W: std::io::Write>(
db: &dyn HirDb,
source: HirSource,
w: W,
) -> eyre::Result<()> {
let mut writer = resw::Writer::new(w);
for top_level in source.contents(db) {
let program_part = transform_top_level(db, *top_level)?;

writer.write_part(&program_part)?;
}
Ok(())
}

0 comments on commit 2ec5ed6

Please sign in to comment.