Skip to content

Commit 0230260

Browse files
committed
Add basic support for variables
1 parent 45bf114 commit 0230260

File tree

11 files changed

+585
-38
lines changed

11 files changed

+585
-38
lines changed

Cargo.lock

Lines changed: 76 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust_slim/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ readme = "readme.md"
1313

1414
[dependencies]
1515
slim_protocol = { path = "../slim_protocol" }
16-
convert_case = "0.6.0"
16+
convert_case = "0.6"
1717
rust_slim_macros = { path = "../rust_slim_macros", optional = true }
1818
thiserror = "1"
1919

rust_slim_macros/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ description = "Macros for the RustSlim server"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
convert_case = "0.6.0"
12-
proc-macro2 = "1.0.69"
13-
quote = "1.0.33"
11+
convert_case = "0.6"
12+
proc-macro2 = "1"
13+
quote = "1"
1414
syn = { version = "2", features = ["extra-traits", "full"] }
1515

1616
[lib]

slim_protocol/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ description = "General Slim Protocol stuff. Used internally by rust_slim and Tem
1010
[dependencies]
1111
ulid = "1"
1212
thiserror = "1"
13-
read_char = "0.1.1"
13+
read_char = "0.1"

slim_protocol/src/slim_deserialize.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,34 @@ impl FromSlimReader for Instruction {
160160
args: data,
161161
})
162162
}
163+
"callAndAssign" => {
164+
let symbol = data
165+
.pop()
166+
.ok_or(FromSlimReaderError::Other("Expected symbol".into()))?;
167+
let instance = data
168+
.pop()
169+
.ok_or(FromSlimReaderError::Other("Expected instance".into()))?;
170+
let function = data
171+
.pop()
172+
.ok_or(FromSlimReaderError::Other("Expected function".into()))?;
173+
data.reverse();
174+
Ok(Instruction::CallAndAssign {
175+
id,
176+
instance,
177+
function,
178+
symbol,
179+
args: data,
180+
})
181+
}
182+
"assign" => {
183+
let symbol = data
184+
.pop()
185+
.ok_or(FromSlimReaderError::Other("Expected symbol".into()))?;
186+
let value = data
187+
.pop()
188+
.ok_or(FromSlimReaderError::Other("Expected value".into()))?;
189+
Ok(Instruction::Assign { id, symbol, value })
190+
}
163191
other => todo!("Not implemented {other}"),
164192
}
165193
}

temoc/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ readme = "readme.md"
1111

1212
[dependencies]
1313
anyhow = "1"
14-
chrono = "0.4.31"
14+
chrono = "0.4"
1515
clap = { version = "4", features = ["derive"] }
16-
convert_case = "0.6.0"
17-
markdown = "1.0.0-alpha.14"
18-
toml = "0.8.8"
16+
convert_case = "0.6"
17+
markdown = "1.0.0-alpha.15"
18+
toml = "0.8"
1919
ulid = "1"
2020
slim_protocol = { path = "../slim_protocol" }
21-
regex = "1.10.5"
22-
rand = "0.8.5"
21+
regex = "1"
22+
rand = "0.8"
2323

2424
[dev-dependencies]
2525
rust_slim = { path = "../rust_slim/", features = ["macros"] }

temoc/examples/calculator_2.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ And we still need to implement exponential:
3232
| 1 | 2 | 1 |
3333
| 2 | 2 | 4 |
3434
| 3 | 2 | 9 |
35-
| 3 | 3 | 27 |
35+
| 3 | 3 | 27 |
36+
37+
Variables:
38+
39+
[//]: # (decisionTable Calculator.Fixtures.CalculatorFixture )
40+
41+
| a | b | sum? |
42+
|----|---|------|
43+
| 1 | 2 | $V= |
44+
| $V | 2 | 5 |
45+
| 2 | 1 | $V |

temoc/src/app.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::processor::{
2-
execute_instructions_and_print_result, process_markdown_into_instructions, Filter,
2+
execute_instructions_and_print_result, process_markdown_into_instructions, Filter, State,
33
};
44
use crate::slim_server_connector::SlimServerConnector;
55
use anyhow::Result;
@@ -97,13 +97,15 @@ impl App {
9797
return Ok(false);
9898
}
9999
let mut slim_server = self.slim_server_connector.start_and_connect()?;
100+
let mut state = State::default();
100101
let mut connection = SlimConnection::new(slim_server.reader()?, slim_server.writer()?)?;
101102
let fail = execute_instructions_and_print_result(
102103
&mut connection,
103104
&file.as_ref().to_string_lossy(),
104105
instructions,
105106
expected_result,
106107
self.show_snoozed,
108+
&mut state,
107109
)?;
108110
connection.close()?;
109111
slim_server.close()?;

temoc/src/processor/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use anyhow::{anyhow, Result};
1111
use markdown::mdast::Node;
1212
use regex::Regex;
1313
use slim_protocol::{Instruction, SlimConnection};
14+
use std::collections::HashMap;
1415
use std::{
1516
fs::read_to_string,
1617
io::{Read, Write},
@@ -21,6 +22,21 @@ mod markdown_commands;
2122
mod slim_instructions_from_commands;
2223
mod validate_result;
2324

25+
#[derive(Debug, Default)]
26+
pub struct State {
27+
symbols: HashMap<String, String>,
28+
}
29+
30+
impl State {
31+
pub fn set_symbol(&mut self, key: String, value: String) {
32+
self.symbols.insert(key, value);
33+
}
34+
35+
pub fn get_symbol(&self, key: &str) -> Option<&String> {
36+
self.symbols.get(key)
37+
}
38+
}
39+
2440
#[derive(Debug, Clone)]
2541
pub struct Filter {
2642
filters: Vec<FilterType>,
@@ -91,9 +107,10 @@ pub fn execute_instructions_and_print_result<R: Read, W: Write>(
91107
instructions: Vec<Instruction>,
92108
expected_result: Vec<ExpectedResulWithSnooze>,
93109
show_snoozed: bool,
110+
state: &mut State,
94111
) -> Result<bool> {
95112
let result = connection.send_instructions(&instructions)?;
96-
let failures = validate_result(file_path, expected_result, result)?;
113+
let failures = validate_result(file_path, expected_result, result, state)?;
97114
print_fail_or_ok(show_snoozed, failures)
98115
}
99116

0 commit comments

Comments
 (0)