Skip to content

Commit

Permalink
添加从逻辑码直接构建Bang语言代码的选项
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Aug 17, 2023
1 parent 1be0f51 commit b54b79e
Show file tree
Hide file tree
Showing 5 changed files with 463 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mindustry_logic_bang_lang"
version = "0.10.3"
version = "0.10.4"
edition = "2021"

authors = ["A4-Tacks <[email protected]>"]
Expand Down
37 changes: 33 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub const HELP_MSG: &str = concat_lines! {
"\t", "T: compile MdtBangLang to MdtTagCode (Builded TagDown)";
"\t", "f: compile MdtLogicCode to MdtTagCode";
"\t", "F: compile MdtLogicCode to MdtTagCode (Builded TagDown)";
"\t", "R: compile MdtLogicCode to MdtBangLang";
"\t", "C: compile MdtTagCode to MdtLogicCode";
;
"input from stdin";
Expand Down Expand Up @@ -92,10 +93,7 @@ fn main() {
},
"A" => {
let ast = from_stdin_build_ast();
let mut meta = Default::default();
ast.display_source(&mut meta);
assert!(meta.pop_lf());
println!("{}", meta.buffer());
display_ast(&ast);
},
"t" => {
let ast = from_stdin_build_ast();
Expand Down Expand Up @@ -152,6 +150,30 @@ fn main() {
println!("{}", line);
}
},
"R" => {
match TagCodes::from_str(&read_stdin()) {
Ok(lines) => {
let ast = Expand::try_from(&lines)
.unwrap_or_else(|(idx, e)| {
let lines_str = lines.iter()
.map(|line| format!("\t{line}"))
.collect::<Vec<_>>();
err!(
"已构建的行:\n{}\n在构建第{}行时出错: {}",
lines_str.join("\n"),
idx + 1,
e
);
exit(4);
});
display_ast(&ast);
},
Err((line, e)) => {
err!("line: {}, {:?}", line, e);
exit(4);
},
}
},
mode => {
err!("mode {:?} no pattern", mode);
help();
Expand All @@ -160,6 +182,13 @@ fn main() {
}
}

fn display_ast(ast: &Expand) {
let mut meta = Default::default();
ast.display_source(&mut meta);
assert!(meta.pop_lf());
println!("{}", meta.buffer());
}

fn build_tag_down(meta: &mut CompileMeta) {
let tag_codes = meta.tag_codes_mut();
tag_codes.build_tagdown()
Expand Down
Loading

0 comments on commit b54b79e

Please sign in to comment.