mindustry logic execution, map- and schematic- parsing and rendering
support 0x and 0b
bendn 2023-09-14
parent 50be676 · commit 7b3b31c
-rw-r--r--lemu/Cargo.toml2
-rw-r--r--lemu/src/lexer.rs3
-rw-r--r--lemu/src/lib.rs1
-rw-r--r--lemu/src/numbers.mlog4
4 files changed, 9 insertions, 1 deletions
diff --git a/lemu/Cargo.toml b/lemu/Cargo.toml
index f1ddd9e..49d88bd 100644
--- a/lemu/Cargo.toml
+++ b/lemu/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "lemu"
-version = "0.2.2"
+version = "0.2.3"
edition = "2021"
description = "M-LOG runner"
authors = ["bend-n <[email protected]>"]
diff --git a/lemu/src/lexer.rs b/lemu/src/lexer.rs
index 4d85822..57b0239 100644
--- a/lemu/src/lexer.rs
+++ b/lemu/src/lexer.rs
@@ -1,5 +1,6 @@
use beef::lean::Cow;
use logos::{Lexer as RealLexer, Logos, Span};
+
macro_rules! instrs {
($($z:literal => $v:ident,)+) => {
#[derive(Logos, Debug, PartialEq, Clone)]
@@ -11,6 +12,8 @@ macro_rules! instrs {
Comment(&'strings str),
#[regex(r"[0-9]+(\.[0-9]+)?", |lex| lex.slice().parse().ok())]
#[regex(r"(true)|(false)", |lex| lex.slice().parse::<bool>().ok().map(f64::from))]
+ #[regex(r#"0[xX][0-9a-fA-F]+"#, |lex| u64::from_str_radix(&lex.slice()[2..], 16).map(|v| v as f64).ok())]
+ #[regex(r#"0[bB][01]+"#, |lex| u64::from_str_radix(&lex.slice()[2..], 2).map(|v| v as f64).ok())]
#[regex(r#""[0-9]+(\.[0-9]+)?""#, callback = |lex| lex.slice()[1..lex.slice().len()-1].parse().ok(), priority = 6)]
Num(f64),
#[regex(r#""([^\\"\n])*""#, callback = |lex| Cow::from(&lex.slice()[1..lex.slice().len()-1]), priority = 5)]
diff --git a/lemu/src/lib.rs b/lemu/src/lib.rs
index 19edb48..8b3620d 100644
--- a/lemu/src/lib.rs
+++ b/lemu/src/lib.rs
@@ -174,5 +174,6 @@ mod test {
}
test!(run fib.mlog; output = b"12586269025");
+ test!(run numbers.mlog; output = b"121212");
test!(run celliterate.mlog 500 times; cell[0][0] = 500.0);
}
diff --git a/lemu/src/numbers.mlog b/lemu/src/numbers.mlog
new file mode 100644
index 0000000..120ae6d
--- /dev/null
+++ b/lemu/src/numbers.mlog
@@ -0,0 +1,4 @@
+print 0b1100
+print 0xc
+print 12
+stop \ No newline at end of file