Skip to content

Commit

Permalink
fixed main
Browse files Browse the repository at this point in the history
  • Loading branch information
lexa-diky committed May 9, 2024
1 parent c32bc2d commit 9885125
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
44 changes: 34 additions & 10 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::compiler::ast::{AstParser, AstParserError};
use crate::compiler::ast::{AstNode, AstParser, AstParserError};
use crate::compiler::{Compilation, CompilerSource, HexoCompilerContext};
use crate::compiler::cst::{CstParser, CstParserError};
use crate::compiler::cst::{CstFile, CstParser, CstParserError};
use crate::compiler::rst::{HexoFile, RstCompiler, RstCompilerError};

#[derive(Debug)]
pub(crate) enum CompilerError {
IO(std::io::Error),
AST(AstParserError),
CST(CstParserError),
RST(RstCompilerError),
}

pub(crate) struct HexoCompiler {
Expand All @@ -21,20 +23,42 @@ impl HexoCompiler {
}
}

pub(crate) fn compile<TSource: CompilerSource>(&self, source: TSource) -> Result<Compilation, CompilerError> {
pub(crate) fn compile_ast<TSource: CompilerSource>(&self, source: &TSource) -> Result<AstNode, CompilerError> {
let ast_parser = AstParser::new();
let cst_parser = CstParser::new();

let source_text = source.read()
.map_err(|e| CompilerError::IO(e))?;

let ast = ast_parser.parse(source_text)
.map_err(|e| CompilerError::AST(e))?;
return Ok(
ast_parser.parse(source_text)
.map_err(|e| CompilerError::AST(e))?
);
}

pub(crate) fn compile_cst<TSource: CompilerSource>(&self, source: &TSource) -> Result<CstFile, CompilerError> {
let ast = self.compile_ast(source)?;
let cst_parser = CstParser::new();

return Ok(
cst_parser.parse(source.path(), ast)
.map_err(|e| CompilerError::CST(e))?
);
}

pub(crate) fn compile_rst<TSource: CompilerSource>(&self, source: &TSource) -> Result<HexoFile, CompilerError> {
let cst = self.compile_cst(source)?;
let rst_compiler = RstCompiler::new(self);

return Ok(
rst_compiler.compile(&cst)
.map_err(|e| CompilerError::RST(e))?
);
}

println!("{:#?}", ast);
pub(crate) fn compile<TSource: CompilerSource>(&self, source: &TSource) -> Result<Compilation, CompilerError> {
let cst = self.compile_cst(source)?;
let rst_compiler = RstCompiler::new(self);
let rst = rst_compiler.compile(&cst);

let cst = cst_parser.parse(source.path(), ast)
.map_err(|e| CompilerError::CST(e))?;
println!("{:#?}", cst);

return Ok(Compilation::empty());
Expand Down
22 changes: 22 additions & 0 deletions src/compiler/rst/compiler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::compiler::cst::CstFile;
use crate::compiler::HexoCompiler;
use crate::compiler::rst::node::HexoFile;

#[derive(Debug)]
pub(crate) enum RstCompilerError {}

pub(crate) struct RstCompiler<'a> {
parent: &'a HexoCompiler,
}

impl RstCompiler<'_> {
pub(crate) fn new(parent: &HexoCompiler) -> RstCompiler {
RstCompiler {
parent: parent
}
}

pub(crate) fn compile(&self, cst: &CstFile) -> Result<HexoFile, RstCompilerError> {
return todo!();
}
}
6 changes: 5 additions & 1 deletion src/compiler/rst/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
mod node;
mod node;
mod compiler;

pub(crate) use compiler::{RstCompiler, RstCompilerError};
pub(crate) use node::*;
4 changes: 3 additions & 1 deletion src/compiler/rst/node.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pub(crate) struct HexoFile {}
pub(crate) struct HexoFile {

}
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::Read;
use std::path::PathBuf;
use compiler::CompilerSource;

use crate::cli::run_build;
use crate::cli::{run_build, run_cli};
use crate::compiler::{FileCompilerSource, HexoCompiler, HexoCompilerContext, StringCompilerSource};

mod cli;
Expand All @@ -15,7 +15,7 @@ mod resolver_legacy;
mod compiler;

fn main() {
let compiler = HexoCompiler::new(HexoCompilerContext::new());
run_cli()
}

#[test]
Expand All @@ -27,7 +27,7 @@ fn new_compiler() {
PathBuf::from("sample.hexo"),
);

let compilation_result = compiler.compile(source).unwrap();
let compilation_result = compiler.compile(&source).unwrap();
}

// list files in directory test cases
Expand Down

0 comments on commit 9885125

Please sign in to comment.