Split yunq compliation to library and use it in build process.
This commit is contained in:
parent
370ba9ae40
commit
1e073d5060
|
@ -8,6 +8,15 @@ version = "1.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "convert_case"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-segmentation",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked_list_allocator"
|
name = "linked_list_allocator"
|
||||||
version = "0.10.5"
|
version = "0.10.5"
|
||||||
|
@ -34,6 +43,16 @@ dependencies = [
|
||||||
"linked_list_allocator",
|
"linked_list_allocator",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prettyplease"
|
||||||
|
version = "0.2.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"syn 2.0.72",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.86"
|
version = "1.0.86"
|
||||||
|
@ -78,6 +97,17 @@ dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.72"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "testbed"
|
name = "testbed"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -92,6 +122,12 @@ version = "1.0.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-segmentation"
|
||||||
|
version = "1.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yellowstone"
|
name = "yellowstone"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -99,6 +135,7 @@ dependencies = [
|
||||||
"mammoth",
|
"mammoth",
|
||||||
"yunq",
|
"yunq",
|
||||||
"yunq-derive",
|
"yunq-derive",
|
||||||
|
"yunqc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -115,5 +152,16 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yunqc"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"convert_case",
|
||||||
|
"prettyplease",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.72",
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,3 +8,6 @@ mammoth = { path = "../mammoth" }
|
||||||
yunq = {path = "../yunq"}
|
yunq = {path = "../yunq"}
|
||||||
yunq-derive = {path = "../yunq-derive"}
|
yunq-derive = {path = "../yunq-derive"}
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
yunqc = {path = "../../../yunq/rust"}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
use std::process::Command;
|
use std::fs;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let input_file = "../../../sys/yellowstone/lib/yellowstone/yellowstone.yunq";
|
||||||
|
|
||||||
|
println!("cargo::rerun-if-changed={input_file}");
|
||||||
|
|
||||||
|
let input = fs::read_to_string(input_file).expect("Failed to read input file");
|
||||||
|
|
||||||
|
let code = yunqc::codegen(&input).expect("Failed to generate yunq code.");
|
||||||
|
|
||||||
let out = std::env::var("OUT_DIR").unwrap() + "/yunq.rs";
|
let out = std::env::var("OUT_DIR").unwrap() + "/yunq.rs";
|
||||||
|
fs::write(out, code).expect("Failed to write generated code.");
|
||||||
let status = Command::new("cargo")
|
|
||||||
.current_dir("../../../yunq/rust")
|
|
||||||
.arg("run")
|
|
||||||
.arg("--")
|
|
||||||
.arg("--input-path")
|
|
||||||
.arg("../../sys/yellowstone/lib/yellowstone/yellowstone.yunq")
|
|
||||||
.arg("--output-path")
|
|
||||||
.arg(out)
|
|
||||||
.status()
|
|
||||||
.expect("Failed to start execution");
|
|
||||||
|
|
||||||
assert!(status.success());
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,7 +255,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yunq"
|
name = "yunqc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
[package]
|
[package]
|
||||||
name = "yunq"
|
name = "yunqc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.7", features = ["derive"] }
|
|
||||||
convert_case = "0.6.0"
|
convert_case = "0.6.0"
|
||||||
prettyplease = "0.2.20"
|
prettyplease = "0.2.20"
|
||||||
proc-macro2 = { version = "1.0" }
|
proc-macro2 = { version = "1.0" }
|
||||||
quote = { version = "1.0" }
|
quote = { version = "1.0" }
|
||||||
syn = "2.0.72"
|
syn = "2.0.72"
|
||||||
|
|
||||||
|
clap = { version = "4.5.7", features = ["derive"], optional = true}
|
||||||
|
|
||||||
|
[features]
|
||||||
|
build-binary = ["clap"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "yunqc"
|
||||||
|
required-features = ["build-binary"]
|
||||||
|
|
|
@ -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::error::Error;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
@ -22,13 +18,8 @@ struct Args {
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let input = fs::read_to_string(args.input_path)?;
|
let input = fs::read_to_string(args.input_path)?;
|
||||||
let tokens = lexer::lex_input(&input)?;
|
|
||||||
|
|
||||||
let mut ast_parser = parser::Parser::new(&tokens);
|
let code = yunqc::codegen(&input)?;
|
||||||
ast_parser.parse_ast()?;
|
|
||||||
ast_parser.type_check()?;
|
|
||||||
|
|
||||||
let code = codegen::generate_code(ast_parser.ast());
|
|
||||||
|
|
||||||
fs::write(args.output_path, code)?;
|
fs::write(args.output_path, code)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue