M Cargo.lock => Cargo.lock +52 -32
@@ 134,7 134,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb"
dependencies = [
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 247,7 247,7 @@ dependencies = [
"actix-router",
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 468,7 468,7 @@ checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 607,7 607,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 656,7 656,7 @@ checksum = "7de77523d154e220a740e568a89f52fac7de481374bdecbbbeb283a37580ba34"
dependencies = [
"bevy_macro_utils",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 704,7 704,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 747,7 747,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 840,7 840,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustc-hash",
- "syn 2.0.57",
+ "syn 2.0.72",
"toml_edit 0.21.1",
]
@@ 909,7 909,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
"uuid",
]
@@ 966,7 966,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 1114,7 1114,7 @@ checksum = "014c80f466ed01821a2e602d63cd5076915c1af5de5fa3c074cc4a9ca898ada7"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 1328,7 1328,7 @@ checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 1726,7 1726,7 @@ dependencies = [
"diesel_table_macro_syntax",
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 1746,7 1746,7 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5"
dependencies = [
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 1816,7 1816,7 @@ checksum = "92959a9e8d13eaa13b8ae8c7b583c3bf1669ca7a8e7708a088d12587ba86effc"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 1981,7 1981,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 2042,7 2042,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 2467,6 2467,14 @@ name = "kabel"
version = "0.1.0"
[[package]]
+name = "kabel_test"
+version = "0.1.0"
+dependencies = [
+ "kabel",
+ "test_each_file",
+]
+
+[[package]]
name = "khronos-egl"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 2846,7 2854,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 2897,7 2905,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 3210,9 3218,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.79"
+version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
+checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
@@ 3234,14 3242,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd"
dependencies = [
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
name = "quote"
-version = "1.0.35"
+version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
+checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
@@ 3556,7 3564,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 3842,9 3850,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "2.0.57"
+version = "2.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "11a6ae1e52eb25aab8f3fb9fca13be982a373b8f1157ca14b897a825ba4a2d35"
+checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af"
dependencies = [
"proc-macro2",
"quote",
@@ 3887,6 3895,18 @@ dependencies = [
]
[[package]]
+name = "test_each_file"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f9576037ae2a919664866c736156fd646d1c0e4e217244b1da05f56204dd6c61"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.72",
+ "unicode-ident",
+]
+
+[[package]]
name = "thiserror"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 3903,7 3923,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 4109,7 4129,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
@@ 4360,7 4380,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
"wasm-bindgen-shared",
]
@@ 4394,7 4414,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@@ 4936,7 4956,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.57",
+ "syn 2.0.72",
]
[[package]]
M Cargo.toml => Cargo.toml +1 -1
@@ 4,7 4,7 @@ members = [
"starkingdoms-backplane",
"starkingdoms-common",
"savefile_decoder"
-, "starkingdoms-api", "kabel"]
+, "starkingdoms-api", "kabel", "kabel_test"]
resolver = "2"
[profile.dev.package."*"]
A kabel_test/Cargo.toml => kabel_test/Cargo.toml +9 -0
@@ 0,0 1,9 @@
+[package]
+name = "kabel_test"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+kabel = { path = "../kabel" }
+
+test_each_file = "0.3.3"
A kabel_test/src/lib.rs => kabel_test/src/lib.rs +61 -0
@@ 0,0 1,61 @@
+use kabel::{debug::{debug_ast, debug_token_array}, run_lexer, run_parser, run_semantic_analysis};
+use test_each_file::test_each_file;
+
+mod main;
+
+test_each_file! { for ["kab", "out"] in "./kabel_test/test/runtime/" => test }
+test_each_file! { for ["kab", "out"] in "./kabel_test/test/lexer/" => test_lexer }
+test_each_file! { for ["kab", "out"] in "./kabel_test/test/syntax/" => test_parser }
+
+fn test_lexer([program, out]: [&str; 2]) {
+ let mut output = "".to_string();
+
+ let lexer = run_lexer(program.to_string());
+
+ for error in lexer.errors.clone() {
+ output += &error.to_string();
+ output += "\n";
+ }
+ if lexer.errors.len() != 0 || lexer.output.len() == 0 {
+ assert_eq!(output, out);
+ return;
+ }
+ output += &debug_token_array(lexer.output.clone());
+ assert_eq!(output.trim(), out.trim());
+}
+
+fn test_parser([program, out]: [&str; 2]) {
+ let mut output = "".to_string();
+
+ let lexer = run_lexer(program.to_string());
+
+ for error in lexer.errors.clone() {
+ output += &error.to_string();
+ output += "\n";
+ }
+ if lexer.errors.len() != 0 || lexer.output.len() == 0 {
+ panic!("lexer error");
+ }
+
+ let (ast, parser) = run_parser(program.to_string(), lexer.output);
+
+ for error in parser.errors.clone() {
+ output += &error.to_string();
+ output += "\n";
+ }
+ if parser.errors.len() != 0 {
+ assert_eq!(output, out);
+ return;
+ }
+ output += &debug_ast(ast, 0);
+ /*let analyzer = run_semantic_analysis(program.to_string(), ast);
+ for error in analyzer.errors.clone() {
+ output += &error.to_string();
+ output += "\n";
+ }
+ assert_eq!(kabel::compile(program.to_string()), output);*/
+ assert_eq!(output.trim(), out.trim());
+}
+fn test([program, out]: [&str; 2]) {
+ assert_eq!(kabel::compile(program.to_string()).trim(), out.trim());
+}
A kabel_test/src/main.rs => kabel_test/src/main.rs +46 -0
@@ 0,0 1,46 @@
+use std::{env, fs};
+
+use kabel::{debug::{debug_ast, debug_token_array}, run_lexer, run_parser, run_semantic_analysis};
+
+fn main() {
+ let args: Vec<String> = env::args().collect();
+ let program =
+ fs::read_to_string(args[1].clone()).unwrap();
+
+ let mut output = "".to_string();
+
+ let lexer = run_lexer(program.to_string());
+
+ for error in lexer.errors.clone() {
+ output += &error.to_string();
+ output += "\n";
+ }
+ output += &format!("{:?}", lexer.output);
+ if lexer.errors.len() != 0 || lexer.output.len() == 0 {
+ println!("{}", output);
+ return;
+ }
+ //output += &debug_token_array(lexer.output.clone());
+ output += "\n\n";
+
+ let (ast, parser) = run_parser(program.to_string(), lexer.output);
+
+ for error in parser.errors.clone() {
+ output += &error.to_string();
+ output += "\n";
+ }
+ if parser.errors.len() != 0 {
+ println!("{}", output);
+ return;
+ }
+ //output += &debug_ast(ast.clone(), 0);
+ output += &format!("{:#?}", ast);
+ output += "\n\n";
+ let analyzer = run_semantic_analysis(program.to_string(), ast);
+ for error in analyzer.errors.clone() {
+ output += &error.to_string();
+ output += "\n";
+ }
+
+ println!("{}", output);
+}
A kabel_test/test/lexer/arithmetic.kab => kabel_test/test/lexer/arithmetic.kab +10 -0
@@ 0,0 1,10 @@
+1 + 1
+1+1
+1 +1
+1+ 1
+
+45*5
+3/4
+6%4
+
+3 * (8 + 4)
A kabel_test/test/lexer/arithmetic.out => kabel_test/test/lexer/arithmetic.out +28 -0
@@ 0,0 1,28 @@
+Num 1
+Plus
+Num 1
+Num 1
+Plus
+Num 1
+Num 1
+Plus
+Num 1
+Num 1
+Plus
+Num 1
+Num 45
+Star
+Num 5
+Num 3
+Slash
+Num 4
+Num 6
+Percent
+Num 4
+Num 3
+Star
+LeftParen
+Num 8
+Plus
+Num 4
+RightParen
A kabel_test/test/lexer/declaration.kab => kabel_test/test/lexer/declaration.kab +1 -0
@@ 0,0 1,1 @@
+var i = 0;
A kabel_test/test/lexer/declaration.out => kabel_test/test/lexer/declaration.out +5 -0
@@ 0,0 1,5 @@
+Var
+Ident i
+Equal
+Num 0
+Semicolon
A kabel_test/test/lexer/keywords.kab => kabel_test/test/lexer/keywords.kab +20 -0
@@ 0,0 1,20 @@
+for(var i = 0;;) {
+
+}
+
+if(true) {
+
+} else {}
+
+while(false) {
+ break;
+ continue;
+}
+
+loop {
+
+}
+
+function () {}
+
+var i;
A kabel_test/test/lexer/keywords.out => kabel_test/test/lexer/keywords.out +41 -0
@@ 0,0 1,41 @@
+For
+LeftParen
+Var
+Ident i
+Equal
+Num 0
+Semicolon
+Semicolon
+RightParen
+LeftBrace
+RightBrace
+If
+LeftParen
+True
+RightParen
+LeftBrace
+RightBrace
+Else
+LeftBrace
+RightBrace
+While
+LeftParen
+False
+RightParen
+LeftBrace
+Break
+Semicolon
+Continue
+Semicolon
+RightBrace
+Loop
+LeftBrace
+RightBrace
+Function
+LeftParen
+RightParen
+LeftBrace
+RightBrace
+Var
+Ident i
+Semicolon
A kabel_test/test/runtime/fn_absent_block.kab => kabel_test/test/runtime/fn_absent_block.kab +4 -0
@@ 0,0 1,4 @@
+var x = 3;
+if(x == 3) {
+ foo();
+}
A kabel_test/test/runtime/fn_absent_block.out => kabel_test/test/runtime/fn_absent_block.out +3 -0
@@ 0,0 1,3 @@
+Error 0004: Function "foo" not in scope at line 3, column 5
+ foo();
+ ^
A kabel_test/test/runtime/turbo_oop.kab => kabel_test/test/runtime/turbo_oop.kab +26 -0
@@ 0,0 1,26 @@
+// modules.select(type, group ...)
+//
+// select all super thrusters that are in both the 'forward' and
+// 'lowpoweronly' user-defined groups
+//
+// 'forward' and 'lowpoweronly' are vecs of modules that have
+// been tagged in the ship editor as such
+
+function sleep(h) {}
+
+var lp_forwards = modules.select(modules.types.SuperThruster, "forward", "lowpoweronly");
+var sensors = modules.select(modules.types.ShipProximitySensor);
+
+loop {
+ // yes, i think we need 'loop' - while True
+ // may confuse beginners
+
+ sleep(1); // 1 second
+
+ // if something is less than 15u away,
+ if (sensors.read() < 15) {
+ lp_forwards.activate();
+ } else {
+ lp_forwards.off(); // alias of Module.deactivate
+ }
+}
A kabel_test/test/runtime/turbo_oop.out => kabel_test/test/runtime/turbo_oop.out +0 -0
A kabel_test/test/syntax/assignment.kab => kabel_test/test/syntax/assignment.kab +3 -0
@@ 0,0 1,3 @@
+var i = 0;
+i = "string";
+var _foo = 3;
A kabel_test/test/syntax/assignment.out => kabel_test/test/syntax/assignment.out +7 -0
@@ 0,0 1,7 @@
+Program
+| Decl i
+| | Lit 0
+| Assign i
+| | Lit string
+| Decl _foo
+| | Lit 3
A kabel_test/test/syntax/function.kab => kabel_test/test/syntax/function.kab +3 -0
@@ 0,0 1,3 @@
+function foo(one, two) {
+ return one + two;
+}
A kabel_test/test/syntax/function.out => kabel_test/test/syntax/function.out +7 -0
@@ 0,0 1,7 @@
+Program
+| Function foo one two
+| | Block
+| | | Return
+| | | | Binary Add
+| | | | | Lit one
+| | | | | Lit two
A kabel_test/test/syntax/if_else.kab => kabel_test/test/syntax/if_else.kab +7 -0
@@ 0,0 1,7 @@
+if(i == 0) {
+ i = 1;
+} else if (i == 1) {
+ i = 2;
+} else {
+ i = 3;
+}
A kabel_test/test/syntax/if_else.out => kabel_test/test/syntax/if_else.out +20 -0
@@ 0,0 1,20 @@
+Program
+| If
+| | Binary Eq
+| | | Lit i
+| | | Lit 0
+| | Block
+| | | Assign i
+| | | | Lit 1
+| Else
+| | If
+| | | Binary Eq
+| | | | Lit i
+| | | | Lit 1
+| | | Block
+| | | | Assign i
+| | | | | Lit 2
+| | Else
+| | | Block
+| | | | Assign i
+| | | | | Lit 3
A kabel_test/test/syntax/no_semicolon.kab => kabel_test/test/syntax/no_semicolon.kab +3 -0
@@ 0,0 1,3 @@
+var i = 0;
+i = 2
+print("call");
A kabel_test/test/syntax/no_semicolon.out => kabel_test/test/syntax/no_semicolon.out +3 -0
@@ 0,0 1,3 @@
+Error 0002: Expected ; found print at line 3, column 1
+print("call");
+^