mindustry logic execution, map- and schematic- parsing and rendering
fix lexer
bendn 2023-09-15
parent 4b0759c · commit c49b373
-rw-r--r--lemu/Cargo.toml2
-rw-r--r--lemu/src/hello.mlog2
-rw-r--r--lemu/src/lexer.rs12
-rw-r--r--lemu/src/lib.rs1
4 files changed, 10 insertions, 7 deletions
diff --git a/lemu/Cargo.toml b/lemu/Cargo.toml
index 458452c..016a137 100644
--- a/lemu/Cargo.toml
+++ b/lemu/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "lemu"
-version = "0.2.5"
+version = "0.2.6"
edition = "2021"
description = "M-LOG runner"
authors = ["bend-n <[email protected]>"]
diff --git a/lemu/src/hello.mlog b/lemu/src/hello.mlog
new file mode 100644
index 0000000..3aac8c4
--- /dev/null
+++ b/lemu/src/hello.mlog
@@ -0,0 +1,2 @@
+print "hello world"
+stop
diff --git a/lemu/src/lexer.rs b/lemu/src/lexer.rs
index 1592514..63d5eda 100644
--- a/lemu/src/lexer.rs
+++ b/lemu/src/lexer.rs
@@ -11,19 +11,19 @@ macro_rules! instrs {
#[regex("#[^\n]+")]
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"(true)|(false)", |lex| lex.slice().parse::<bool>().ok().map(f64::from), priority = 10)]
#[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)]
+ #[regex(r#""[0-9]+(\.[0-9]+)?""#, callback = |lex| lex.slice()[1..lex.slice().len()-1].parse().ok(), priority = 13)]
Num(f64),
- #[regex(r#""([^\\"\n])*""#, callback = |lex| Cow::from(&lex.slice()[1..lex.slice().len()-1]), priority = 5)]
+ #[regex(r#""([^\\"\n])*""#, callback = |lex| Cow::from(&lex.slice()[1..lex.slice().len()-1]), priority = 12)]
#[regex(r#"@[^ "\n]*"#, |lex| Cow::from(&lex.slice()[1..]))]
- #[regex(r#""[^"]*""#, |lex| Cow::from(lex.slice()[1..lex.slice().len()-1].replace(r"\n", "\n")))]
+ #[regex(r#""[^"]*""#, callback = |lex| Cow::from(lex.slice()[1..lex.slice().len()-1].replace(r"\n", "\n")), priority = 8)]
String(Cow<'strings, str>),
- #[regex("[^0-9 \t\n]+", priority = 9)]
+ #[regex("[^0-9 \t\n]+", priority = 7)]
Ident(&'strings str),
- $(#[token($z)] $v,)+
+ $(#[token($z, priority = 8)] $v,)+
}
impl std::fmt::Display for Token<'_> {
diff --git a/lemu/src/lib.rs b/lemu/src/lib.rs
index 8b3620d..47ae3f0 100644
--- a/lemu/src/lib.rs
+++ b/lemu/src/lib.rs
@@ -176,4 +176,5 @@ 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);
+ test!(run hello.mlog; output = b"hello world");
}