1
0

Compare commits

..

No commits in common. "8bcf59f216178622a0f2711dbea82e7a280f7ed0" and "b308c1852f76d21ca52c69620975590fd4871818" have entirely different histories.

13 changed files with 527 additions and 83 deletions

View File

@ -0,0 +1,273 @@
"Index", "Eruption length (mins)","Eruption wait (mins)"
1, 3.600, 79
2, 1.800, 54
3, 3.333, 74
4, 2.283, 62
5, 4.533, 85
6, 2.883, 55
7, 4.700, 88
8, 3.600, 85
9, 1.950, 51
10, 4.350, 85
11, 1.833, 54
12, 3.917, 84
13, 4.200, 78
14, 1.750, 47
15, 4.700, 83
16, 2.167, 52
17, 1.750, 62
18, 4.800, 84
19, 1.600, 52
20, 4.250, 79
21, 1.800, 51
22, 1.750, 47
23, 3.450, 78
24, 3.067, 69
25, 4.533, 74
26, 3.600, 83
27, 1.967, 55
28, 4.083, 76
29, 3.850, 78
30, 4.433, 79
31, 4.300, 73
32, 4.467, 77
33, 3.367, 66
34, 4.033, 80
35, 3.833, 74
36, 2.017, 52
37, 1.867, 48
38, 4.833, 80
39, 1.833, 59
40, 4.783, 90
41, 4.350, 80
42, 1.883, 58
43, 4.567, 84
44, 1.750, 58
45, 4.533, 73
46, 3.317, 83
47, 3.833, 64
48, 2.100, 53
49, 4.633, 82
50, 2.000, 59
51, 4.800, 75
52, 4.716, 90
53, 1.833, 54
54, 4.833, 80
55, 1.733, 54
56, 4.883, 83
57, 3.717, 71
58, 1.667, 64
59, 4.567, 77
60, 4.317, 81
61, 2.233, 59
62, 4.500, 84
63, 1.750, 48
64, 4.800, 82
65, 1.817, 60
66, 4.400, 92
67, 4.167, 78
68, 4.700, 78
69, 2.067, 65
70, 4.700, 73
71, 4.033, 82
72, 1.967, 56
73, 4.500, 79
74, 4.000, 71
75, 1.983, 62
76, 5.067, 76
77, 2.017, 60
78, 4.567, 78
79, 3.883, 76
80, 3.600, 83
81, 4.133, 75
82, 4.333, 82
83, 4.100, 70
84, 2.633, 65
85, 4.067, 73
86, 4.933, 88
87, 3.950, 76
88, 4.517, 80
89, 2.167, 48
90, 4.000, 86
91, 2.200, 60
92, 4.333, 90
93, 1.867, 50
94, 4.817, 78
95, 1.833, 63
96, 4.300, 72
97, 4.667, 84
98, 3.750, 75
99, 1.867, 51
100, 4.900, 82
101, 2.483, 62
102, 4.367, 88
103, 2.100, 49
104, 4.500, 83
105, 4.050, 81
106, 1.867, 47
107, 4.700, 84
108, 1.783, 52
109, 4.850, 86
110, 3.683, 81
111, 4.733, 75
112, 2.300, 59
113, 4.900, 89
114, 4.417, 79
115, 1.700, 59
116, 4.633, 81
117, 2.317, 50
118, 4.600, 85
119, 1.817, 59
120, 4.417, 87
121, 2.617, 53
122, 4.067, 69
123, 4.250, 77
124, 1.967, 56
125, 4.600, 88
126, 3.767, 81
127, 1.917, 45
128, 4.500, 82
129, 2.267, 55
130, 4.650, 90
131, 1.867, 45
132, 4.167, 83
133, 2.800, 56
134, 4.333, 89
135, 1.833, 46
136, 4.383, 82
137, 1.883, 51
138, 4.933, 86
139, 2.033, 53
140, 3.733, 79
141, 4.233, 81
142, 2.233, 60
143, 4.533, 82
144, 4.817, 77
145, 4.333, 76
146, 1.983, 59
147, 4.633, 80
148, 2.017, 49
149, 5.100, 96
150, 1.800, 53
151, 5.033, 77
152, 4.000, 77
153, 2.400, 65
154, 4.600, 81
155, 3.567, 71
156, 4.000, 70
157, 4.500, 81
158, 4.083, 93
159, 1.800, 53
160, 3.967, 89
161, 2.200, 45
162, 4.150, 86
163, 2.000, 58
164, 3.833, 78
165, 3.500, 66
166, 4.583, 76
167, 2.367, 63
168, 5.000, 88
169, 1.933, 52
170, 4.617, 93
171, 1.917, 49
172, 2.083, 57
173, 4.583, 77
174, 3.333, 68
175, 4.167, 81
176, 4.333, 81
177, 4.500, 73
178, 2.417, 50
179, 4.000, 85
180, 4.167, 74
181, 1.883, 55
182, 4.583, 77
183, 4.250, 83
184, 3.767, 83
185, 2.033, 51
186, 4.433, 78
187, 4.083, 84
188, 1.833, 46
189, 4.417, 83
190, 2.183, 55
191, 4.800, 81
192, 1.833, 57
193, 4.800, 76
194, 4.100, 84
195, 3.966, 77
196, 4.233, 81
197, 3.500, 87
198, 4.366, 77
199, 2.250, 51
200, 4.667, 78
201, 2.100, 60
202, 4.350, 82
203, 4.133, 91
204, 1.867, 53
205, 4.600, 78
206, 1.783, 46
207, 4.367, 77
208, 3.850, 84
209, 1.933, 49
210, 4.500, 83
211, 2.383, 71
212, 4.700, 80
213, 1.867, 49
214, 3.833, 75
215, 3.417, 64
216, 4.233, 76
217, 2.400, 53
218, 4.800, 94
219, 2.000, 55
220, 4.150, 76
221, 1.867, 50
222, 4.267, 82
223, 1.750, 54
224, 4.483, 75
225, 4.000, 78
226, 4.117, 79
227, 4.083, 78
228, 4.267, 78
229, 3.917, 70
230, 4.550, 79
231, 4.083, 70
232, 2.417, 54
233, 4.183, 86
234, 2.217, 50
235, 4.450, 90
236, 1.883, 54
237, 1.850, 54
238, 4.283, 77
239, 3.950, 79
240, 2.333, 64
241, 4.150, 75
242, 2.350, 47
243, 4.933, 86
244, 2.900, 63
245, 4.583, 85
246, 3.833, 82
247, 2.083, 57
248, 4.367, 82
249, 2.133, 67
250, 4.350, 74
251, 2.200, 54
252, 4.450, 83
253, 3.567, 73
254, 4.500, 73
255, 4.150, 88
256, 3.817, 80
257, 3.917, 71
258, 4.450, 83
259, 2.000, 56
260, 4.283, 79
261, 4.767, 78
262, 4.533, 84
263, 1.850, 58
264, 4.250, 83
265, 1.983, 43
266, 2.250, 60
267, 4.750, 75
268, 4.117, 81
269, 2.150, 46
270, 4.417, 90
271, 1.817, 46
272, 4.467, 74
1 Index Eruption length (mins) Eruption wait (mins)
2 1 3.600 79
3 2 1.800 54
4 3 3.333 74
5 4 2.283 62
6 5 4.533 85
7 6 2.883 55
8 7 4.700 88
9 8 3.600 85
10 9 1.950 51
11 10 4.350 85
12 11 1.833 54
13 12 3.917 84
14 13 4.200 78
15 14 1.750 47
16 15 4.700 83
17 16 2.167 52
18 17 1.750 62
19 18 4.800 84
20 19 1.600 52
21 20 4.250 79
22 21 1.800 51
23 22 1.750 47
24 23 3.450 78
25 24 3.067 69
26 25 4.533 74
27 26 3.600 83
28 27 1.967 55
29 28 4.083 76
30 29 3.850 78
31 30 4.433 79
32 31 4.300 73
33 32 4.467 77
34 33 3.367 66
35 34 4.033 80
36 35 3.833 74
37 36 2.017 52
38 37 1.867 48
39 38 4.833 80
40 39 1.833 59
41 40 4.783 90
42 41 4.350 80
43 42 1.883 58
44 43 4.567 84
45 44 1.750 58
46 45 4.533 73
47 46 3.317 83
48 47 3.833 64
49 48 2.100 53
50 49 4.633 82
51 50 2.000 59
52 51 4.800 75
53 52 4.716 90
54 53 1.833 54
55 54 4.833 80
56 55 1.733 54
57 56 4.883 83
58 57 3.717 71
59 58 1.667 64
60 59 4.567 77
61 60 4.317 81
62 61 2.233 59
63 62 4.500 84
64 63 1.750 48
65 64 4.800 82
66 65 1.817 60
67 66 4.400 92
68 67 4.167 78
69 68 4.700 78
70 69 2.067 65
71 70 4.700 73
72 71 4.033 82
73 72 1.967 56
74 73 4.500 79
75 74 4.000 71
76 75 1.983 62
77 76 5.067 76
78 77 2.017 60
79 78 4.567 78
80 79 3.883 76
81 80 3.600 83
82 81 4.133 75
83 82 4.333 82
84 83 4.100 70
85 84 2.633 65
86 85 4.067 73
87 86 4.933 88
88 87 3.950 76
89 88 4.517 80
90 89 2.167 48
91 90 4.000 86
92 91 2.200 60
93 92 4.333 90
94 93 1.867 50
95 94 4.817 78
96 95 1.833 63
97 96 4.300 72
98 97 4.667 84
99 98 3.750 75
100 99 1.867 51
101 100 4.900 82
102 101 2.483 62
103 102 4.367 88
104 103 2.100 49
105 104 4.500 83
106 105 4.050 81
107 106 1.867 47
108 107 4.700 84
109 108 1.783 52
110 109 4.850 86
111 110 3.683 81
112 111 4.733 75
113 112 2.300 59
114 113 4.900 89
115 114 4.417 79
116 115 1.700 59
117 116 4.633 81
118 117 2.317 50
119 118 4.600 85
120 119 1.817 59
121 120 4.417 87
122 121 2.617 53
123 122 4.067 69
124 123 4.250 77
125 124 1.967 56
126 125 4.600 88
127 126 3.767 81
128 127 1.917 45
129 128 4.500 82
130 129 2.267 55
131 130 4.650 90
132 131 1.867 45
133 132 4.167 83
134 133 2.800 56
135 134 4.333 89
136 135 1.833 46
137 136 4.383 82
138 137 1.883 51
139 138 4.933 86
140 139 2.033 53
141 140 3.733 79
142 141 4.233 81
143 142 2.233 60
144 143 4.533 82
145 144 4.817 77
146 145 4.333 76
147 146 1.983 59
148 147 4.633 80
149 148 2.017 49
150 149 5.100 96
151 150 1.800 53
152 151 5.033 77
153 152 4.000 77
154 153 2.400 65
155 154 4.600 81
156 155 3.567 71
157 156 4.000 70
158 157 4.500 81
159 158 4.083 93
160 159 1.800 53
161 160 3.967 89
162 161 2.200 45
163 162 4.150 86
164 163 2.000 58
165 164 3.833 78
166 165 3.500 66
167 166 4.583 76
168 167 2.367 63
169 168 5.000 88
170 169 1.933 52
171 170 4.617 93
172 171 1.917 49
173 172 2.083 57
174 173 4.583 77
175 174 3.333 68
176 175 4.167 81
177 176 4.333 81
178 177 4.500 73
179 178 2.417 50
180 179 4.000 85
181 180 4.167 74
182 181 1.883 55
183 182 4.583 77
184 183 4.250 83
185 184 3.767 83
186 185 2.033 51
187 186 4.433 78
188 187 4.083 84
189 188 1.833 46
190 189 4.417 83
191 190 2.183 55
192 191 4.800 81
193 192 1.833 57
194 193 4.800 76
195 194 4.100 84
196 195 3.966 77
197 196 4.233 81
198 197 3.500 87
199 198 4.366 77
200 199 2.250 51
201 200 4.667 78
202 201 2.100 60
203 202 4.350 82
204 203 4.133 91
205 204 1.867 53
206 205 4.600 78
207 206 1.783 46
208 207 4.367 77
209 208 3.850 84
210 209 1.933 49
211 210 4.500 83
212 211 2.383 71
213 212 4.700 80
214 213 1.867 49
215 214 3.833 75
216 215 3.417 64
217 216 4.233 76
218 217 2.400 53
219 218 4.800 94
220 219 2.000 55
221 220 4.150 76
222 221 1.867 50
223 222 4.267 82
224 223 1.750 54
225 224 4.483 75
226 225 4.000 78
227 226 4.117 79
228 227 4.083 78
229 228 4.267 78
230 229 3.917 70
231 230 4.550 79
232 231 4.083 70
233 232 2.417 54
234 233 4.183 86
235 234 2.217 50
236 235 4.450 90
237 236 1.883 54
238 237 1.850 54
239 238 4.283 77
240 239 3.950 79
241 240 2.333 64
242 241 4.150 75
243 242 2.350 47
244 243 4.933 86
245 244 2.900 63
246 245 4.583 85
247 246 3.833 82
248 247 2.083 57
249 248 4.367 82
250 249 2.133 67
251 250 4.350 74
252 251 2.200 54
253 252 4.450 83
254 253 3.567 73
255 254 4.500 73
256 255 4.150 88
257 256 3.817 80
258 257 3.917 71
259 258 4.450 83
260 259 2.000 56
261 260 4.283 79
262 261 4.767 78
263 262 4.533 84
264 263 1.850 58
265 264 4.250 83
266 265 1.983 43
267 266 2.250 60
268 267 4.750 75
269 268 4.117 81
270 269 2.150 46
271 270 4.417 90
272 271 1.817 46
273 272 4.467 74

15
examples/clue_solver.ds Normal file
View File

@ -0,0 +1,15 @@
suspects = ("White", "Green");
rooms = ("Library", "Kitchen");
weapons = ("Rope", "Lead Pipe");
make_guess = {
current_room = input.0;
if length(suspects) == 1
&& length(rooms) == 1
&& length(weapons) == 1
then
output 'It was ' + suspects.0 + ' in the ' + rooms.0 + ' with the ' + weapons.0 '!';
else
output 'I accuse ' + random(suspects) + ' in the ' + current_room + ' with the ' + random(weapons) '!';
};

114
examples/collections.ds Normal file
View File

@ -0,0 +1,114 @@
# transform
list = (1, 2, 3);
test = transform(list, 'input + 1');
assert_equal((2, 3, 4), test);
# string
test = string(42);
assert_equal("42", test);
test = string(42.42);
assert_equal("42.42", test);
test = string(false);
assert_equal("false", test);
# create_table
table = create_table(
("text", "num"),
(
("foo", 1),
("bar", 2)
)
);
# rows
test = rows(table);
assert_equal(
(
("foo", 1),
("bar", 2)
),
test
);
# insert
test = insert(
table,
(
("foo", 1),
("bar", 2)
)
);
assert_equal(
create_table(
("text", "num"),
(
("foo", 1),
("bar", 2),
("foo", 1),
("bar", 2)
)
),
test
);
# select
table = create_table(
("text", "number", "bool"),
(
("a", 1, true),
("b", 2, true),
("a", 3, true)
)
);
test_table = create_table(
("text", "bool"),
(
("a", true),
("b", true),
("a", true)
)
);
assert_equal(select(table, ("text", "bool")), test_table);
test_table = create_table(
("text", "number", "bool"),
(
("a", 1, true),
("a", 3, true)
)
);
assert_equal(where(table, 'text == "a"'), test_table);
# count
table = create_table(
("text", "number", "bool"),
(
("a", 1, true),
("b", 2, true),
("a", 3, true)
)
);
test = count(table);
assert_equal(3, test);
test = count("123");
assert_equal(3, test);
test = count(1, 2, 3);
assert_equal(3, test);
map.x.z.y = 1;
test = count(map);
assert_equal(1, test);

4
examples/data_formats.ds Normal file
View File

@ -0,0 +1,4 @@
dob = from_toml("1979-05-27T07:32:00-08:00");
toml = to_toml(dob);
assert_equal(toml, "1979-05-27T07:32:00-08:00");

4
examples/fetch.ds Normal file
View File

@ -0,0 +1,4 @@
raw_data = download("https://api.sampleapis.com/futurama/cast");
data = from_json(raw_data);
assert_equal("Billy West", data.0.name);

View File

@ -0,0 +1,6 @@
# This will read a CSV file and display it as a line plot in a GUI window.
read_file("examples/assets/faithful.csv")
-> from_csv(input)
-> rows(input)
-> transform(input, 'input.1')
-> plot(input);

12
examples/list.ds Normal file
View File

@ -0,0 +1,12 @@
# Lists are created by grouping items in partheses and separating them with
# commas.
numbers = (1, 2, 3);
# To access the values in a list, use an integer as an index.
x = numbers.0;
y = numbers.1;
z = numbers.2;
assert_equal(x + y, z);

9
examples/scope.ds Normal file
View File

@ -0,0 +1,9 @@
foo = "bar";
func = 'foo';
assert_equal("bar", func());
foo = "xyz";
assert_equal("xyz", func());

29
examples/table.ds Normal file
View File

@ -0,0 +1,29 @@
table = create_table(
("text", "number", "bool"),
(
("a", 1, true),
("b", 2, true),
("a", 3, true)
)
);
test_table = create_table(
("text", "bool"),
(
("a", true),
("b", true),
("a", true)
)
);
assert_equal(select(table, ("text", "bool")), test_table);
test_table = create_table(
("text", "number", "bool"),
(
("a", 1, true),
("a", 3, true)
)
);
assert_equal(where(table, 'text == "a"'), test_table);

13
examples/variables.ds Normal file
View File

@ -0,0 +1,13 @@
# Dust is data-oriented, so variables are declared with minimal syntax. A
# single character, the assignment operator (`=`), sets a variable.
x = 1;
y = "hello dust!";
z = 42.0;
list = (3, 2, x);
big_list = (x, y, z, list);
map.x = "foobar";
function = '
message = "I am a function!";
output message;
';

View File

@ -1,5 +1,6 @@
//! The top level of Dust's API with functions to interpret Dust code.
use egui::util::id_type_map;
use tree_sitter::{Node, Parser, Tree, TreeCursor};
use crate::{language, Error, Result, Value, VariableMap};
@ -97,8 +98,8 @@ impl Evaluator {
) -> Vec<Result<Value>> {
let mut results = Vec::with_capacity(self.items.len());
for item in &self.items {
match item {
for root in &self.items {
match root {
Item::Comment(comment) => results.push(Ok(Value::String(comment.clone()))),
Item::Statement(statement) => {
results.push(statement.run(context, &mut cursor, source))
@ -294,7 +295,6 @@ impl Operation {
Ok(Value::Empty)
}
"==" => Ok(Value::Boolean(left == right)),
_ => return Err(Error::CustomMessage("Operator not supported.".to_string())),
};
@ -350,8 +350,6 @@ impl ControlFlow {
#[cfg(test)]
mod tests {
use crate::{Function, Table};
use super::*;
#[test]
@ -379,82 +377,6 @@ mod tests {
eval("'`one`'"),
vec![Ok(Value::String("`one`".to_string()))]
);
assert_eq!(
eval("\"'one'\""),
vec![Ok(Value::String("'one'".to_string()))]
);
}
#[test]
fn evaluate_list() {
assert_eq!(
eval("(1, 2, 'foobar')"),
vec![Ok(Value::List(vec![
Value::Integer(1),
Value::Integer(2),
Value::String("foobar".to_string()),
]))]
);
}
#[test]
fn evaluate_function() {
let function_str = "function <message, answer> {
output message;
output 'The answer is ' + answer;
}";
assert_eq!(
eval("{ x = 1, foo = 'bar' }"),
vec![Ok(Value::Function(Function::new(function_str)))]
);
}
#[test]
fn evaluate_map() {
let mut map = VariableMap::new();
map.set_value("x", Value::Integer(1)).unwrap();
map.set_value("foo", Value::String("bar".to_string()))
.unwrap();
assert_eq!(eval("{ x = 1, foo = 'bar' }"), vec![Ok(Value::Map(map))]);
}
#[test]
fn evaluate_table() {
let mut table = Table::new(vec!["messages".to_string(), "numbers".to_string()]);
table
.insert(vec![Value::String("hiya".to_string()), Value::Integer(42)])
.unwrap();
table
.insert(vec![Value::String("foo".to_string()), Value::Integer(-57)])
.unwrap();
table
.insert(vec![Value::String("bar".to_string()), Value::Float(99.99)])
.unwrap();
assert_eq!(
eval(
"table <messages, numbers>
row ('hiya', 42)
row ('foo', -57)
row ('bar', 99.99)"
),
vec![Ok(Value::Table(table.clone()))]
);
assert_eq!(
eval(
"my_table = table <messages, numbers>
row ('hiya', 42);
my_table += ('foo', -57);
my_table += ('bar', 99.99);
my_table"
),
vec![Ok(Value::Table(table))]
);
}
#[test]

View File

@ -66,8 +66,6 @@ impl Value {
"string" => {
let without_quotes = &value_snippet[1..value_snippet.len() - 1];
println!("{without_quotes}");
Ok(Value::String(without_quotes.to_string()))
}
"boolean" => {

45
tests/dust_examples.rs Normal file
View File

@ -0,0 +1,45 @@
use std::fs::read_to_string;
use dust_lib::*;
#[test]
fn collections() {
let file_contents = read_to_string("examples/collections.ds").unwrap();
eval(&file_contents).unwrap();
}
#[test]
fn list() {
let file_contents = read_to_string("examples/list.ds").unwrap();
eval(&file_contents).unwrap();
}
#[test]
fn table() {
let file_contents = read_to_string("examples/table.ds").unwrap();
eval(&file_contents).unwrap();
}
#[test]
fn variables() {
let file_contents = read_to_string("examples/variables.ds").unwrap();
eval(&file_contents).unwrap();
}
#[test]
fn scope() {
let file_contents = read_to_string("examples/scope.ds").unwrap();
eval(&file_contents).unwrap();
}
#[test]
fn data_formats() {
let file_contents = read_to_string("examples/data_formats.ds").unwrap();
eval(&file_contents).unwrap();
}