Skip to content

Commit

Permalink
feat: Add support for else clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez committed Oct 7, 2024
1 parent bfcd477 commit 9a4f33f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ fn process_file(
};
let res = engine.eval::<bool>(cond).unwrap();
include.push(res && *include.last().unwrap());
} else if trimmed.starts_with("#ELSE") || trimmed.starts_with("//ELSE") {
let res = !*include.last().unwrap();
include.pop();
include.push(res);
} else if trimmed.starts_with("#ENDIF") || trimmed.starts_with("//ENDIF") {
include.pop();
// Trim #+ and //+
Expand Down
15 changes: 6 additions & 9 deletions template/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#REPLACE riscv32imac-unknown-none-elf rust_target
[target.riscv32imac-unknown-none-elf]
#IF !option("probe-rs")
runner = "espflash flash --monitor"
#ENDIF
#IF option("probe-rs")
#REPLACE esp32c6 mcu
#+runner = "probe-rs run --chip=esp32c6"
runner = "probe-rs run --chip=esp32c6"
#ELSE
#+runner = "espflash flash --monitor"
#ENDIF

[env]
#IF !option("probe-rs")
ESP_LOGLEVEL="INFO"
#ENDIF
#IF option("probe-rs")
DEFMT_LOG="info"
#ELSE
ESP_LOGLEVEL="INFO"
#ENDIF

[build]
Expand All @@ -37,7 +35,6 @@ target = "riscv32imac-unknown-none-elf"
[unstable]
#IF option("alloc")
build-std = ["alloc", "core"]
#ENDIF
#IF !option("alloc")
#ELSE
#+build-std = ["core"]
#ENDIF
7 changes: 2 additions & 5 deletions template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ esp-backtrace = { version = "0.14.1", features = [
"esp32c6",
"exception-handler",
"panic-handler",
#IF !option("probe-rs")
"println",
#ENDIF
#IF option("probe-rs")
#+"defmt",
#ELSE
"println",
#ENDIF
]}

Expand All @@ -28,8 +27,6 @@ esp-hal = { version = "0.20.1", features = [
#IF !option("probe-rs")
#REPLACE esp32c6 mcu
esp-println = { version = "0.11.0", features = ["esp32c6", "log"] }
#ENDIF
#IF !option("probe-rs")
log = { version = "0.4.21" }
#ENDIF
#IF option("alloc")
Expand Down
3 changes: 1 addition & 2 deletions template/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use esp_hal::timer::timg::TimerGroup;
//IF option("probe-rs")
//+ use defmt_rtt as _;
//+ use defmt::info;
//ENDIF
//IF !option("probe-rs")
//ELSE
use log::info;
//ENDIF

Expand Down

0 comments on commit 9a4f33f

Please sign in to comment.