Split yunq compliation to library and use it in build process.
This commit is contained in:
parent
370ba9ae40
commit
1e073d5060
7 changed files with 89 additions and 28 deletions
2
yunq/rust/Cargo.lock
generated
2
yunq/rust/Cargo.lock
generated
|
|
@ -255,7 +255,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||
|
||||
[[package]]
|
||||
name = "yunq"
|
||||
name = "yunqc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
|
|
|
|||
|
|
@ -1,12 +1,20 @@
|
|||
[package]
|
||||
name = "yunq"
|
||||
name = "yunqc"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.7", features = ["derive"] }
|
||||
convert_case = "0.6.0"
|
||||
prettyplease = "0.2.20"
|
||||
proc-macro2 = { version = "1.0" }
|
||||
quote = { version = "1.0" }
|
||||
syn = "2.0.72"
|
||||
|
||||
clap = { version = "4.5.7", features = ["derive"], optional = true}
|
||||
|
||||
[features]
|
||||
build-binary = ["clap"]
|
||||
|
||||
[[bin]]
|
||||
name = "yunqc"
|
||||
required-features = ["build-binary"]
|
||||
|
|
|
|||
15
yunq/rust/src/lib.rs
Normal file
15
yunq/rust/src/lib.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
mod codegen;
|
||||
mod lexer;
|
||||
mod parser;
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
pub fn codegen(input: &str) -> Result<String, Box<dyn Error>> {
|
||||
let tokens = lexer::lex_input(input)?;
|
||||
|
||||
let mut ast_parser = parser::Parser::new(&tokens);
|
||||
ast_parser.parse_ast()?;
|
||||
ast_parser.type_check()?;
|
||||
|
||||
Ok(codegen::generate_code(ast_parser.ast()))
|
||||
}
|
||||
|
|
@ -1,7 +1,3 @@
|
|||
mod codegen;
|
||||
mod lexer;
|
||||
mod parser;
|
||||
|
||||
use std::error::Error;
|
||||
use std::fs;
|
||||
|
||||
|
|
@ -22,13 +18,8 @@ struct Args {
|
|||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args = Args::parse();
|
||||
let input = fs::read_to_string(args.input_path)?;
|
||||
let tokens = lexer::lex_input(&input)?;
|
||||
|
||||
let mut ast_parser = parser::Parser::new(&tokens);
|
||||
ast_parser.parse_ast()?;
|
||||
ast_parser.type_check()?;
|
||||
|
||||
let code = codegen::generate_code(ast_parser.ast());
|
||||
let code = yunqc::codegen(&input)?;
|
||||
|
||||
fs::write(args.output_path, code)?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue