@devaloop/devalang 0.0.1-alpha.1 → 0.0.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/.devalang +4 -0
  2. package/Cargo.toml +49 -45
  3. package/README.md +127 -46
  4. package/docs/CHANGELOG.md +172 -0
  5. package/docs/COMMANDS.md +60 -6
  6. package/docs/CONFIG.md +30 -0
  7. package/docs/ROADMAP.md +10 -7
  8. package/docs/SYNTAX.md +100 -18
  9. package/docs/TODO.md +31 -28
  10. package/examples/condition.deva +20 -0
  11. package/examples/group.deva +12 -0
  12. package/examples/index.deva +13 -4
  13. package/examples/loop.deva +16 -0
  14. package/examples/samples/hat-808.wav +0 -0
  15. package/examples/synth.deva +14 -0
  16. package/examples/variables.deva +9 -0
  17. package/out-tsc/bin/devalang.exe +0 -0
  18. package/out-tsc/scripts/version/fetch.js +1 -5
  19. package/package.json +5 -4
  20. package/project-version.json +3 -3
  21. package/rust/cli/build.rs +114 -28
  22. package/rust/cli/check.rs +96 -103
  23. package/rust/cli/init.rs +79 -0
  24. package/rust/cli/mod.rs +203 -1
  25. package/rust/cli/play.rs +193 -0
  26. package/rust/cli/template.rs +57 -0
  27. package/rust/config/loader.rs +13 -0
  28. package/rust/config/mod.rs +16 -0
  29. package/rust/core/audio/engine.rs +214 -0
  30. package/rust/core/audio/evaluator.rs +31 -0
  31. package/rust/core/audio/interpreter/arrow_call.rs +129 -0
  32. package/rust/core/audio/interpreter/call.rs +70 -0
  33. package/rust/core/audio/interpreter/condition.rs +69 -0
  34. package/rust/core/audio/interpreter/driver.rs +236 -0
  35. package/rust/core/audio/interpreter/let_.rs +19 -0
  36. package/rust/core/audio/interpreter/load.rs +18 -0
  37. package/rust/core/audio/interpreter/loop_.rs +67 -0
  38. package/rust/core/audio/interpreter/mod.rs +12 -0
  39. package/rust/core/audio/interpreter/sleep.rs +36 -0
  40. package/rust/core/audio/interpreter/spawn.rs +84 -0
  41. package/rust/core/audio/interpreter/tempo.rs +16 -0
  42. package/rust/core/audio/interpreter/trigger.rs +69 -0
  43. package/rust/core/audio/loader/mod.rs +1 -0
  44. package/rust/core/audio/loader/trigger.rs +52 -0
  45. package/rust/core/audio/mod.rs +6 -0
  46. package/rust/core/audio/player.rs +54 -0
  47. package/rust/core/audio/renderer.rs +54 -0
  48. package/rust/core/builder/mod.rs +70 -27
  49. package/rust/core/debugger/lexer.rs +27 -0
  50. package/rust/core/debugger/mod.rs +13 -49
  51. package/rust/core/debugger/preprocessor.rs +27 -0
  52. package/rust/core/debugger/store.rs +25 -0
  53. package/rust/core/error/mod.rs +60 -0
  54. package/rust/core/lexer/handler/arrow.rs +31 -0
  55. package/rust/core/lexer/handler/at.rs +21 -0
  56. package/rust/core/lexer/handler/brace.rs +41 -0
  57. package/rust/core/lexer/handler/colon.rs +21 -0
  58. package/rust/core/lexer/handler/comment.rs +30 -0
  59. package/rust/core/lexer/handler/dot.rs +21 -0
  60. package/rust/core/lexer/handler/driver.rs +230 -0
  61. package/rust/core/lexer/handler/identifier.rs +41 -0
  62. package/rust/core/lexer/handler/indent.rs +52 -0
  63. package/rust/core/lexer/handler/mod.rs +14 -0
  64. package/rust/core/lexer/handler/newline.rs +23 -0
  65. package/rust/core/lexer/handler/number.rs +31 -0
  66. package/rust/core/lexer/handler/operator.rs +44 -0
  67. package/rust/core/lexer/handler/string.rs +63 -0
  68. package/rust/core/lexer/mod.rs +37 -319
  69. package/rust/core/lexer/token.rs +86 -0
  70. package/rust/core/mod.rs +6 -2
  71. package/rust/core/parser/driver.rs +331 -0
  72. package/rust/core/parser/handler/arrow_call.rs +126 -0
  73. package/rust/core/parser/handler/at.rs +162 -0
  74. package/rust/core/parser/handler/bank.rs +41 -0
  75. package/rust/core/parser/handler/condition.rs +74 -0
  76. package/rust/core/parser/handler/dot.rs +112 -0
  77. package/rust/core/parser/handler/identifier/call.rs +41 -0
  78. package/rust/core/parser/handler/identifier/group.rs +75 -0
  79. package/rust/core/parser/handler/identifier/let_.rs +133 -0
  80. package/rust/core/parser/handler/identifier/mod.rs +51 -0
  81. package/rust/core/parser/handler/identifier/sleep.rs +33 -0
  82. package/rust/core/parser/handler/identifier/spawn.rs +41 -0
  83. package/rust/core/parser/handler/identifier/synth.rs +65 -0
  84. package/rust/core/parser/handler/loop_.rs +72 -0
  85. package/rust/core/parser/handler/mod.rs +8 -0
  86. package/rust/core/parser/handler/tempo.rs +47 -0
  87. package/rust/core/parser/mod.rs +3 -200
  88. package/rust/core/parser/statement.rs +96 -0
  89. package/rust/core/preprocessor/loader.rs +229 -0
  90. package/rust/core/preprocessor/mod.rs +2 -24
  91. package/rust/core/preprocessor/module.rs +42 -56
  92. package/rust/core/preprocessor/processor.rs +76 -0
  93. package/rust/core/preprocessor/resolver/bank.rs +41 -51
  94. package/rust/core/preprocessor/resolver/call.rs +123 -0
  95. package/rust/core/preprocessor/resolver/condition.rs +92 -0
  96. package/rust/core/preprocessor/resolver/driver.rs +227 -0
  97. package/rust/core/preprocessor/resolver/group.rs +61 -0
  98. package/rust/core/preprocessor/resolver/let_.rs +31 -0
  99. package/rust/core/preprocessor/resolver/loop_.rs +76 -67
  100. package/rust/core/preprocessor/resolver/mod.rs +12 -111
  101. package/rust/core/preprocessor/resolver/spawn.rs +58 -0
  102. package/rust/core/preprocessor/resolver/synth.rs +50 -0
  103. package/rust/core/preprocessor/resolver/tempo.rs +40 -61
  104. package/rust/core/preprocessor/resolver/trigger.rs +90 -154
  105. package/rust/core/preprocessor/resolver/value.rs +78 -0
  106. package/rust/core/shared/duration.rs +8 -0
  107. package/rust/core/shared/mod.rs +2 -0
  108. package/rust/core/shared/value.rs +28 -0
  109. package/rust/core/store/export.rs +28 -0
  110. package/rust/core/store/global.rs +39 -0
  111. package/rust/core/store/import.rs +28 -0
  112. package/rust/core/store/mod.rs +4 -0
  113. package/rust/core/store/variable.rs +28 -0
  114. package/rust/core/utils/mod.rs +2 -0
  115. package/rust/core/utils/path.rs +31 -0
  116. package/rust/core/utils/validation.rs +37 -0
  117. package/rust/lib.rs +161 -1
  118. package/rust/main.rs +46 -30
  119. package/rust/utils/file.rs +35 -0
  120. package/rust/utils/logger.rs +108 -34
  121. package/rust/utils/mod.rs +3 -2
  122. package/rust/utils/{loader.rs → spinner.rs} +2 -0
  123. package/rust/utils/watcher.rs +33 -0
  124. package/templates/minimal/.devalang +5 -0
  125. package/templates/minimal/README.md +202 -0
  126. package/templates/minimal/src/index.deva +2 -0
  127. package/templates/welcome/.devalang +5 -0
  128. package/templates/welcome/README.md +202 -0
  129. package/templates/welcome/samples/kick-808.wav +0 -0
  130. package/templates/welcome/src/index.deva +13 -0
  131. package/templates/welcome/src/variables.deva +5 -0
  132. package/typescript/scripts/version/fetch.ts +1 -6
  133. package/examples/exported.deva +0 -7
  134. package/rust/audio/mod.rs +0 -1
  135. package/rust/cli/new.rs +0 -1
  136. package/rust/core/parser/at.rs +0 -142
  137. package/rust/core/parser/bank.rs +0 -42
  138. package/rust/core/parser/dot.rs +0 -107
  139. package/rust/core/parser/identifer.rs +0 -91
  140. package/rust/core/parser/loop_.rs +0 -62
  141. package/rust/core/parser/tempo.rs +0 -42
  142. package/rust/core/parser/variable.rs +0 -129
  143. package/rust/core/preprocessor/dependencies.rs +0 -54
  144. package/rust/core/preprocessor/resolver/at.rs +0 -24
  145. package/rust/core/types/cli.rs +0 -160
  146. package/rust/core/types/mod.rs +0 -7
  147. package/rust/core/types/module.rs +0 -41
  148. package/rust/core/types/parser.rs +0 -73
  149. package/rust/core/types/statement.rs +0 -105
  150. package/rust/core/types/store.rs +0 -116
  151. package/rust/core/types/token.rs +0 -83
  152. package/rust/core/types/variable.rs +0 -32
  153. package/rust/runner/executer.rs +0 -44
  154. package/rust/runner/mod.rs +0 -1
  155. package/rust/utils/path.rs +0 -46
@@ -0,0 +1,54 @@
1
+ use std::collections::HashMap;
2
+
3
+ use crate::{
4
+ core::{
5
+ audio::{ engine::AudioEngine, interpreter::driver::run_audio_program },
6
+ parser::statement::Statement,
7
+ store::global::GlobalStore,
8
+ },
9
+ utils::logger::{ LogLevel, Logger },
10
+ };
11
+
12
+ pub fn render_audio_with_modules(
13
+ modules: HashMap<String, Vec<Statement>>,
14
+ output_dir: &str,
15
+ global_store: &mut GlobalStore
16
+ ) -> HashMap<String, AudioEngine> {
17
+ let mut result = HashMap::new();
18
+
19
+ for (module_name, statements) in modules {
20
+ let mut global_max_end_time: f32 = 0.0;
21
+ let mut initial_engine = AudioEngine::new(module_name.clone());
22
+
23
+ // Apply global variables to the initial engine
24
+ if let Some(module) = global_store.get_module(&module_name) {
25
+ initial_engine.set_variables(module.variable_table.clone());
26
+ }
27
+
28
+ // interprete statements to fill the audio buffer
29
+ let (mut updated_engine, _bpm, module_max_end_time) = run_audio_program(
30
+ &statements,
31
+ initial_engine,
32
+ module_name.clone(),
33
+ output_dir.to_string()
34
+ );
35
+
36
+ // Verify if the buffer is silent (all samples are zero)
37
+ if updated_engine.buffer.iter().all(|&s| s == 0) {
38
+ let logger = Logger::new();
39
+ logger.log_message(
40
+ LogLevel::Warning,
41
+ &format!("Module '{}' ignored: silent buffer (no non-zero samples)", module_name)
42
+ );
43
+ continue;
44
+ }
45
+
46
+ // Determines the maximum end time for the module
47
+ global_max_end_time = global_max_end_time.max(module_max_end_time);
48
+ updated_engine.set_duration(global_max_end_time);
49
+
50
+ result.insert(module_name, updated_engine);
51
+ }
52
+
53
+ result
54
+ }
@@ -1,37 +1,80 @@
1
- use crate::core::types::statement::{ StatementResolved };
2
- use std::fs::File;
1
+ use crate::core::audio::renderer::render_audio_with_modules;
2
+ use crate::core::parser::statement::Statement;
3
+ use crate::core::store::global::GlobalStore;
4
+ use std::{ collections::HashMap, fs::create_dir_all };
3
5
  use std::io::Write;
4
6
 
5
- pub fn build_ast(statements: &Vec<StatementResolved>) -> String {
6
- let mut ast_string = String::new();
7
+ use crate::utils::logger::Logger;
7
8
 
8
- serde_json
9
- ::to_string_pretty(statements)
10
- .map(|json| {
11
- ast_string.push_str(&json);
12
- })
13
- .unwrap_or_else(|err| {
14
- eprintln!("Error serializing AST: {}", err);
15
- std::process::exit(1);
16
- });
9
+ pub struct Builder {}
17
10
 
18
- ast_string
19
- }
11
+ impl Builder {
12
+ pub fn new() -> Self {
13
+ Builder {}
14
+ }
20
15
 
21
- pub fn write_ast_to_file(ast: &str, file_path: &str) {
22
- clear_json_directory(&file_path);
23
- create_json_directory(&file_path);
16
+ pub fn build_ast(&self, modules: &HashMap<String, Vec<Statement>>, out_dir: &str) {
17
+ for (name, statements) in modules {
18
+ let formatted_name = name.split("/").last().unwrap_or(name);
19
+ let formatted_name = formatted_name.replace(".deva", "");
24
20
 
25
- let file_path = format!("{}/ast.json", file_path);
21
+ create_dir_all(format!("{}/ast", out_dir)).expect("Failed to create AST directory");
26
22
 
27
- let mut file = File::create(&file_path).expect("Unable to create AST file");
28
- file.write_all(ast.as_bytes()).expect("Unable to write AST to file");
29
- }
23
+ let file_path = format!("{}/ast/{}.json", out_dir, formatted_name);
24
+ let mut file = std::fs::File::create(file_path).expect("Failed to create AST file");
30
25
 
31
- fn clear_json_directory(path: &str) {
32
- std::fs::remove_dir_all(path);
33
- }
26
+ let content = serde_json
27
+ ::to_string_pretty(&statements)
28
+ .expect("Failed to serialize AST");
29
+
30
+ file.write_all(content.as_bytes()).expect("Failed to write AST to file");
31
+ }
32
+ }
33
+
34
+ pub fn build_audio(
35
+ &self,
36
+ modules: &HashMap<String, Vec<Statement>>,
37
+ normalized_output_dir: &str,
38
+ global_store: &mut GlobalStore
39
+ ) {
40
+ let logger = Logger::new();
41
+
42
+ let audio_engines = render_audio_with_modules(
43
+ modules.clone(),
44
+ &normalized_output_dir,
45
+ global_store
46
+ );
47
+
48
+ create_dir_all(format!("{}/audio", normalized_output_dir)).expect(
49
+ "Failed to create audio directory"
50
+ );
51
+
52
+ for (module_name, mut audio_engine) in audio_engines {
53
+ let formatted_module_name = module_name
54
+ .split('/')
55
+ .last()
56
+ .unwrap_or(&module_name)
57
+ .replace(".deva", "");
58
+
59
+ let output_path = format!(
60
+ "{}/audio/{}.wav",
61
+ normalized_output_dir,
62
+ formatted_module_name
63
+ );
34
64
 
35
- fn create_json_directory(path: &str) {
36
- std::fs::create_dir_all(path);
65
+ match audio_engine.generate_wav_file(&output_path) {
66
+ Ok(_) => {}
67
+ Err(msg) => {
68
+ logger.log_error_with_stacktrace(
69
+ &format!(
70
+ "Unable to generate WAV file for module '{}': {}",
71
+ formatted_module_name,
72
+ msg
73
+ ),
74
+ &module_name
75
+ );
76
+ }
77
+ }
78
+ }
79
+ }
37
80
  }
@@ -0,0 +1,27 @@
1
+ use std::{ collections::HashMap, fs::create_dir_all };
2
+ use crate::core::{ debugger::Debugger, lexer::token::Token };
3
+
4
+ pub fn write_lexer_log_file(
5
+ output_dir: &str,
6
+ file_name: &str,
7
+ modules: HashMap<String, Vec<Token>>
8
+ ) {
9
+ let debugger = Debugger::new();
10
+ let mut content = String::new();
11
+
12
+ let log_directory = format!("{}/logs", output_dir);
13
+
14
+ create_dir_all(&log_directory).expect("Failed to create log directory");
15
+
16
+ for (path, tokens) in modules {
17
+ content.push_str(&format!("--- Resolved Tokens for {} ---\n", path));
18
+
19
+ for token in tokens {
20
+ content.push_str(&format!("{:?}\n", token));
21
+ }
22
+
23
+ content.push_str("\n");
24
+ }
25
+
26
+ debugger.write_log_file(&log_directory, file_name, &content);
27
+ }
@@ -1,57 +1,21 @@
1
- use crate::core::types::{ module::Module, statement::{ StatementResolved } };
1
+ pub mod preprocessor;
2
+ pub mod lexer;
3
+ pub mod store;
2
4
 
3
- pub struct Debugger {
4
- pub module: Module,
5
- }
5
+ use std::io::Write;
6
+
7
+ pub struct Debugger {}
6
8
 
7
9
  impl Debugger {
8
- pub fn new(module: &Module) -> Self {
9
- Debugger {
10
- module: module.clone(),
11
- }
10
+ pub fn new() -> Self {
11
+ Debugger {}
12
12
  }
13
13
 
14
- pub fn write_files(&self, output_dir: &str, resolved_statements: Vec<StatementResolved>) {
15
- const LEXER_FILENAME: &str = "debug_lexer.log";
16
- const STATEMENTS_FILENAME: &str = "debug_statements.log";
17
-
18
- let lexer_path = format!("{}{}", output_dir, LEXER_FILENAME);
19
- let statements_path = format!("{}{}", output_dir, STATEMENTS_FILENAME);
20
-
21
- // Collect debug information
22
- let tokens = self.module.tokens
23
- .iter()
24
- .map(|token| format!("{:?}", token))
25
- .collect::<Vec<String>>();
26
- let statements = resolved_statements
27
- .iter()
28
- .map(|stmt| format!("{:?}", stmt))
29
- .collect::<Vec<String>>();
14
+ pub fn write_log_file(&self, path: &str, filename: &str, content: &str) {
15
+ std::fs::create_dir_all(path).expect("Failed to create directory");
16
+ let file_path = format!("{}/{}", path, filename);
17
+ let mut file = std::fs::File::create(file_path).expect("Failed to create file");
30
18
 
31
- // Ensure the debug directory exists and is cleared
32
- clear_debug_directory(output_dir);
33
- create_debug_directory(output_dir);
34
-
35
- // Writing files
36
- write_tokens_debug_to_file(&tokens, &lexer_path);
37
- write_statements_debug_to_file(&statements, &statements_path);
19
+ file.write_all(content.as_bytes()).expect("Failed to write to file");
38
20
  }
39
21
  }
40
-
41
- fn clear_debug_directory(path: &str) {
42
- std::fs::remove_dir_all(path);
43
- }
44
-
45
- fn create_debug_directory(path: &str) {
46
- std::fs::create_dir_all(path);
47
- }
48
-
49
- fn write_statements_debug_to_file(statements: &Vec<String>, path: &str) {
50
- let content = statements.join("\n");
51
- std::fs::write(path, content).expect("Unable to write statements to file");
52
- }
53
-
54
- fn write_tokens_debug_to_file(tokens: &Vec<String>, path: &str) {
55
- let content = tokens.join("\n");
56
- std::fs::write(path, content).expect("Unable to write tokens to file");
57
- }
@@ -0,0 +1,27 @@
1
+ use std::{ collections::HashMap, fs::create_dir_all };
2
+ use crate::core::{ debugger::Debugger, parser::statement::Statement };
3
+
4
+ pub fn write_preprocessor_log_file(
5
+ output_dir: &str,
6
+ file_name: &str,
7
+ modules: HashMap<String, Vec<Statement>>
8
+ ) {
9
+ let debugger = Debugger::new();
10
+ let mut content = String::new();
11
+
12
+ let log_directory = format!("{}/logs", output_dir);
13
+
14
+ create_dir_all(&log_directory).expect("Failed to create log directory");
15
+
16
+ for (path, stmts) in modules {
17
+ content.push_str(&format!("--- Resolved Statements for {} ---\n", path));
18
+
19
+ for stmt in stmts {
20
+ content.push_str(&format!("{:?}\n", stmt));
21
+ }
22
+
23
+ content.push_str("\n");
24
+ }
25
+
26
+ debugger.write_log_file(&log_directory, file_name, &content);
27
+ }
@@ -0,0 +1,25 @@
1
+ use std::{ collections::HashMap, fs::create_dir_all };
2
+ use crate::core::{ debugger::Debugger, preprocessor::module::Module };
3
+
4
+ pub fn write_store_log_file(output_dir: &str, file_name: &str, modules: HashMap<String, Module>) {
5
+ let debugger = Debugger::new();
6
+ let mut content = String::new();
7
+
8
+ let log_directory = format!("{}/logs", output_dir);
9
+ create_dir_all(&log_directory).expect("Failed to create log directory");
10
+
11
+ for (path, module) in modules {
12
+ content.push_str(&format!("--- Module: {} ---\n", path));
13
+
14
+ for (index, var_value) in module.variable_table.variables.iter().enumerate() {
15
+ let var_name = var_value.0.clone();
16
+ let var_data = var_value.1;
17
+
18
+ content.push_str(&format!("{}: {:?} = {:?}\n", index + 1, var_name, var_data));
19
+ }
20
+
21
+ content.push_str("\n");
22
+ }
23
+
24
+ debugger.write_log_file(&log_directory, file_name, &content);
25
+ }
@@ -0,0 +1,60 @@
1
+ use crate::core::parser::{ statement::{ Statement, StatementKind }, driver::Parser };
2
+
3
+ pub struct ErrorHandler {
4
+ errors: Vec<Error>,
5
+ }
6
+
7
+ pub struct Error {
8
+ pub message: String,
9
+ pub line: usize,
10
+ pub column: usize,
11
+ }
12
+
13
+ impl ErrorHandler {
14
+ pub fn new() -> Self {
15
+ Self { errors: Vec::new() }
16
+ }
17
+
18
+ pub fn add_error(&mut self, message: String, line: usize, column: usize) {
19
+ let error_statement = Error {
20
+ message,
21
+ line,
22
+ column,
23
+ };
24
+ self.errors.push(error_statement);
25
+ }
26
+
27
+ pub fn has_errors(&self) -> bool {
28
+ !self.errors.is_empty()
29
+ }
30
+
31
+ pub fn get_errors(&self) -> &Vec<Error> {
32
+ &self.errors
33
+ }
34
+
35
+ pub fn clear_errors(&mut self) {
36
+ self.errors.clear();
37
+ }
38
+
39
+ pub fn detect_from_statements(&mut self, parser: &mut Parser, statements: &[Statement]) {
40
+ for stmt in statements {
41
+ match &stmt.kind {
42
+ StatementKind::Unknown => {
43
+ self.add_error(
44
+ "Unknown statement".to_string(),
45
+ stmt.line,
46
+ stmt.column
47
+ );
48
+ }
49
+ StatementKind::Error { message } => {
50
+ self.add_error(
51
+ message.clone(),
52
+ stmt.line,
53
+ stmt.column
54
+ );
55
+ }
56
+ _ => {}
57
+ }
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,31 @@
1
+ use crate::core::lexer::token::{ Token, TokenKind };
2
+
3
+ pub fn handle_arrow_lexer(
4
+ char: char,
5
+ chars: &mut std::iter::Peekable<std::str::Chars>,
6
+ current_indent: &mut usize,
7
+ indent_stack: &mut Vec<usize>,
8
+ tokens: &mut Vec<Token>,
9
+ line: &mut usize,
10
+ column: &mut usize
11
+ ) {
12
+ let mut arrow_call = char.to_string();
13
+
14
+ while let Some(&c) = chars.peek() {
15
+ if c == '>' {
16
+ chars.next();
17
+ arrow_call.push(c);
18
+ *column += 1;
19
+ } else {
20
+ break;
21
+ }
22
+ }
23
+
24
+ tokens.push(Token {
25
+ kind: TokenKind::Arrow,
26
+ lexeme: arrow_call,
27
+ line: *line,
28
+ column: *column,
29
+ indent: *current_indent,
30
+ });
31
+ }
@@ -0,0 +1,21 @@
1
+ use crate::core::lexer::token::{Token, TokenKind};
2
+
3
+ pub fn handle_at_lexer(
4
+ char: char,
5
+ chars: &mut std::iter::Peekable<std::str::Chars>,
6
+ current_indent: &mut usize,
7
+ indent_stack: &mut Vec<usize>,
8
+ tokens: &mut Vec<Token>,
9
+ line: &mut usize,
10
+ column: &mut usize
11
+ ) {
12
+ tokens.push(Token {
13
+ kind: TokenKind::At,
14
+ lexeme: char.to_string(),
15
+ line: *line,
16
+ column: *column,
17
+ indent: *current_indent,
18
+ });
19
+
20
+ *column += 1;
21
+ }
@@ -0,0 +1,41 @@
1
+ use crate::core::lexer::token::{ Token, TokenKind };
2
+
3
+ pub fn handle_rbrace_lexer(
4
+ char: char,
5
+ chars: &mut std::iter::Peekable<std::str::Chars>,
6
+ current_indent: &mut usize,
7
+ indent_stack: &mut Vec<usize>,
8
+ tokens: &mut Vec<Token>,
9
+ line: &mut usize,
10
+ column: &mut usize
11
+ ) {
12
+ tokens.push(Token {
13
+ kind: TokenKind::RBrace,
14
+ lexeme: char.to_string(),
15
+ line: *line,
16
+ column: *column,
17
+ indent: *current_indent,
18
+ });
19
+
20
+ *column += 1;
21
+ }
22
+
23
+ pub fn handle_lbrace_lexer(
24
+ char: char,
25
+ chars: &mut std::iter::Peekable<std::str::Chars>,
26
+ current_indent: &mut usize,
27
+ indent_stack: &mut Vec<usize>,
28
+ tokens: &mut Vec<Token>,
29
+ line: &mut usize,
30
+ column: &mut usize
31
+ ) {
32
+ tokens.push(Token {
33
+ kind: TokenKind::LBrace,
34
+ lexeme: char.to_string(),
35
+ line: *line,
36
+ column: *column,
37
+ indent: *current_indent,
38
+ });
39
+
40
+ *column += 1;
41
+ }
@@ -0,0 +1,21 @@
1
+ use crate::core::lexer::token::{Token, TokenKind};
2
+
3
+ pub fn handle_colon_lexer(
4
+ char: char,
5
+ chars: &mut std::iter::Peekable<std::str::Chars>,
6
+ current_indent: &mut usize,
7
+ indent_stack: &mut Vec<usize>,
8
+ tokens: &mut Vec<Token>,
9
+ line: &mut usize,
10
+ column: &mut usize
11
+ ) {
12
+ tokens.push(Token {
13
+ kind: TokenKind::Colon,
14
+ lexeme: char.to_string(),
15
+ line: *line,
16
+ column: *column,
17
+ indent: *current_indent,
18
+ });
19
+
20
+ *column += 1;
21
+ }
@@ -0,0 +1,30 @@
1
+ use crate::core::lexer::token::{Token, TokenKind};
2
+
3
+ pub fn handle_comment_lexer(
4
+ char: char,
5
+ chars: &mut std::iter::Peekable<std::str::Chars>,
6
+ current_indent: &mut usize,
7
+ indent_stack: &mut Vec<usize>,
8
+ tokens: &mut Vec<Token>,
9
+ line: &mut usize,
10
+ column: &mut usize
11
+ ) {
12
+ let mut comment = String::new();
13
+
14
+ while let Some(&c) = chars.peek() {
15
+ if c == '\n' {
16
+ break;
17
+ }
18
+ comment.push(c);
19
+ chars.next();
20
+ *column += 1;
21
+ }
22
+
23
+ tokens.push(Token {
24
+ kind: TokenKind::Comment,
25
+ lexeme: comment.trim().to_string(),
26
+ line: *line,
27
+ column: *column,
28
+ indent: *current_indent,
29
+ });
30
+ }
@@ -0,0 +1,21 @@
1
+ use crate::core::lexer::token::{ Token, TokenKind };
2
+
3
+ pub fn handle_dot_lexer(
4
+ char: char,
5
+ chars: &mut std::iter::Peekable<std::str::Chars>,
6
+ current_indent: &mut usize,
7
+ indent_stack: &mut Vec<usize>,
8
+ tokens: &mut Vec<Token>,
9
+ line: &mut usize,
10
+ column: &mut usize
11
+ ) {
12
+ tokens.push(Token {
13
+ kind: TokenKind::Dot,
14
+ lexeme: char.to_string(),
15
+ line: *line,
16
+ column: *column,
17
+ indent: *current_indent,
18
+ });
19
+
20
+ *column += 1;
21
+ }