@devaloop/devalang 0.0.1-alpha.2 → 0.0.1-alpha.3
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.
- package/Cargo.toml +46 -46
- package/README.md +7 -6
- package/docs/CHANGELOG.md +11 -6
- package/docs/ROADMAP.md +5 -1
- package/docs/TODO.md +6 -31
- package/examples/exported.deva +1 -1
- package/examples/index.deva +1 -0
- package/out-tsc/bin/devalang.exe +0 -0
- package/package.json +1 -2
- package/project-version.json +3 -3
- package/rust/cli/build.rs +57 -40
- package/rust/cli/check.rs +47 -111
- package/rust/cli/init.rs +1 -1
- package/rust/cli/mod.rs +174 -2
- package/rust/{utils/config.rs → config/loader.rs} +3 -2
- package/rust/{core/types/config.rs → config/mod.rs} +5 -5
- package/rust/core/builder/mod.rs +21 -27
- package/rust/core/debugger/lexer.rs +12 -0
- package/rust/core/debugger/mod.rs +12 -49
- package/rust/core/debugger/preprocessor.rs +23 -0
- package/rust/core/error/mod.rs +60 -0
- package/rust/core/lexer/{at.rs → handler/at.rs} +1 -1
- package/rust/core/lexer/{brace.rs → handler/brace.rs} +1 -1
- package/rust/core/lexer/{colon.rs → handler/colon.rs} +1 -1
- package/rust/core/lexer/{comment.rs → handler/comment.rs} +3 -3
- package/rust/core/lexer/{dot.rs → handler/dot.rs} +1 -1
- package/rust/core/lexer/{equal.rs → handler/equal.rs} +1 -1
- package/rust/core/lexer/{identifier.rs → handler/identifier.rs} +1 -1
- package/rust/core/lexer/{indent.rs → handler/indent.rs} +10 -5
- package/rust/core/lexer/handler/mod.rs +238 -0
- package/rust/core/lexer/{newline.rs → handler/newline.rs} +6 -10
- package/rust/core/lexer/{number.rs → handler/number.rs} +1 -1
- package/rust/core/lexer/handler/string.rs +66 -0
- package/rust/core/lexer/mod.rs +25 -14
- package/rust/core/lexer/token.rs +55 -0
- package/rust/core/mod.rs +5 -2
- package/rust/core/parser/handler/at.rs +166 -0
- package/rust/core/parser/handler/bank.rs +38 -0
- package/rust/core/parser/handler/dot.rs +112 -0
- package/rust/core/parser/handler/identifier.rs +134 -0
- package/rust/core/parser/handler/loop_.rs +55 -0
- package/rust/core/parser/handler/mod.rs +6 -0
- package/rust/core/parser/handler/tempo.rs +47 -0
- package/rust/core/parser/mod.rs +204 -166
- package/rust/core/parser/statement.rs +91 -0
- package/rust/core/preprocessor/loader.rs +105 -0
- package/rust/core/preprocessor/mod.rs +2 -24
- package/rust/core/preprocessor/module.rs +37 -56
- package/rust/core/preprocessor/processor.rs +41 -0
- package/rust/core/preprocessor/resolver.rs +372 -0
- package/rust/core/shared/duration.rs +8 -0
- package/rust/core/shared/mod.rs +2 -0
- package/rust/core/shared/value.rs +18 -0
- package/rust/core/store/export.rs +28 -0
- package/rust/core/store/global.rs +39 -0
- package/rust/core/store/import.rs +28 -0
- package/rust/core/store/mod.rs +4 -0
- package/rust/core/store/variable.rs +28 -0
- package/rust/core/utils/mod.rs +2 -0
- package/rust/core/utils/validation.rs +35 -0
- package/rust/lib.rs +0 -1
- package/rust/main.rs +17 -19
- package/rust/utils/logger.rs +69 -34
- package/rust/utils/mod.rs +3 -5
- package/templates/minimal/.devalang +1 -1
- package/templates/welcome/.devalang +1 -1
- package/rust/audio/mod.rs +0 -1
- package/rust/core/lexer/bracket.rs +0 -41
- package/rust/core/lexer/driver.rs +0 -286
- package/rust/core/lexer/quote.rs +0 -61
- package/rust/core/parser/at.rs +0 -142
- package/rust/core/parser/bank.rs +0 -42
- package/rust/core/parser/dot.rs +0 -137
- package/rust/core/parser/identifer.rs +0 -91
- package/rust/core/parser/loop_.rs +0 -62
- package/rust/core/parser/tempo.rs +0 -42
- package/rust/core/parser/variable.rs +0 -129
- package/rust/core/preprocessor/dependencies.rs +0 -54
- package/rust/core/preprocessor/resolver/at.rs +0 -24
- package/rust/core/preprocessor/resolver/bank.rs +0 -59
- package/rust/core/preprocessor/resolver/loop_.rs +0 -82
- package/rust/core/preprocessor/resolver/mod.rs +0 -113
- package/rust/core/preprocessor/resolver/tempo.rs +0 -70
- package/rust/core/preprocessor/resolver/trigger.rs +0 -176
- package/rust/core/types/cli.rs +0 -182
- package/rust/core/types/mod.rs +0 -8
- package/rust/core/types/module.rs +0 -41
- package/rust/core/types/parser.rs +0 -73
- package/rust/core/types/statement.rs +0 -105
- package/rust/core/types/store.rs +0 -116
- package/rust/core/types/token.rs +0 -83
- package/rust/core/types/variable.rs +0 -32
- package/rust/runner/executer.rs +0 -44
- package/rust/runner/mod.rs +0 -1
- /package/rust/{utils → core/utils}/path.rs +0 -0
- /package/rust/utils/{loader.rs → spinner.rs} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
use crate::core::{ preprocessor::module::Module, shared::value::Value, store::global::GlobalStore };
|
|
2
|
+
|
|
3
|
+
pub fn is_valid_entity(entity: &str, module: &Module, global_store: &GlobalStore) -> bool {
|
|
4
|
+
let built_ins = ["kick", "snare", "hat", "clap"];
|
|
5
|
+
|
|
6
|
+
if built_ins.contains(&entity) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if let Some(val) = module.variable_table.get(entity) {
|
|
11
|
+
match val {
|
|
12
|
+
Value::Sample(_) => true,
|
|
13
|
+
_ => false,
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
pub fn is_valid_identifier(ident: &str, module: &Module) -> bool {
|
|
21
|
+
let built_ins = ["auto"];
|
|
22
|
+
|
|
23
|
+
if built_ins.contains(&ident) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if let Some(val) = module.variable_table.get(ident) {
|
|
28
|
+
match val {
|
|
29
|
+
Value::Identifier(_) => true,
|
|
30
|
+
_ => false,
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
false
|
|
34
|
+
}
|
|
35
|
+
}
|
package/rust/lib.rs
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// TODO WebAssembly support
|
package/rust/main.rs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
pub mod core;
|
|
2
2
|
pub mod cli;
|
|
3
|
-
pub mod runner;
|
|
4
|
-
pub mod audio;
|
|
5
3
|
pub mod utils;
|
|
4
|
+
pub mod config;
|
|
6
5
|
|
|
7
|
-
use std::
|
|
6
|
+
use std::io;
|
|
7
|
+
use cli::{ Cli };
|
|
8
8
|
use clap::Parser;
|
|
9
9
|
use crate::{
|
|
10
10
|
cli::{
|
|
@@ -12,48 +12,46 @@ use crate::{
|
|
|
12
12
|
check::handle_check_command,
|
|
13
13
|
init::handle_init_command,
|
|
14
14
|
template::{ handle_template_info_command, handle_template_list_command },
|
|
15
|
+
Commands,
|
|
16
|
+
TemplateCommand,
|
|
15
17
|
},
|
|
16
|
-
|
|
17
|
-
utils::{ config::load_config, logger::log_message },
|
|
18
|
+
config::{ loader::load_config, Config },
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
fn main() -> io::Result<()> {
|
|
21
22
|
let cli: Cli = Cli::parse();
|
|
22
|
-
let mut config: Option<
|
|
23
|
+
let mut config: Option<Config> = None;
|
|
23
24
|
|
|
24
25
|
if !cli.no_config {
|
|
25
26
|
config = load_config(None);
|
|
26
27
|
} else {
|
|
27
|
-
|
|
28
|
+
println!("No configuration file loaded. Running with arguments only.");
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
match cli.command {
|
|
31
|
-
|
|
32
|
+
Commands::Init { name, template } => {
|
|
32
33
|
handle_init_command(name, template);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
Commands::Template { command } =>
|
|
36
37
|
match command {
|
|
37
|
-
|
|
38
|
+
TemplateCommand::List => {
|
|
38
39
|
handle_template_list_command();
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
TemplateCommand::Info { name } => {
|
|
41
42
|
handle_template_info_command(name);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
Commands::Check { entry, output, watch, compilation_mode, debug } => {
|
|
47
|
+
handle_check_command(config, entry, output, watch);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
Commands::Build { entry, output, watch, compilation_mode, debug, compress } => {
|
|
51
|
+
handle_build_command(config, entry, output, watch);
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
// CliCommands::Play {} => {
|
|
55
|
-
// log_message("Command 'play' is not implemented yet.", "WARNING");
|
|
56
|
-
// }
|
|
54
|
+
_ => {}
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
Ok(())
|
package/rust/utils/logger.rs
CHANGED
|
@@ -1,49 +1,84 @@
|
|
|
1
|
-
use crossterm::style::{Attribute, Color, ResetColor, SetAttribute, SetForegroundColor};
|
|
1
|
+
use crossterm::style::{ Attribute, Color, ResetColor, SetAttribute, SetForegroundColor };
|
|
2
2
|
use std::{ fmt::Write };
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
5
|
+
pub enum LogLevel {
|
|
6
|
+
Success,
|
|
7
|
+
Error,
|
|
8
|
+
Info,
|
|
9
|
+
Warning,
|
|
10
|
+
Watcher,
|
|
11
|
+
Debug,
|
|
7
12
|
}
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
#[derive(Debug, Clone)]
|
|
15
|
+
pub struct Logger {}
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
impl Logger {
|
|
18
|
+
pub fn new() -> Self {
|
|
19
|
+
Logger {}
|
|
20
|
+
}
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
pub fn log_message(&self, level: LogLevel, message: &str) {
|
|
23
|
+
let formatted_status = self.format_status(level);
|
|
24
|
+
println!("🦊 {} {} {}", self.language_signature(), formatted_status, message);
|
|
25
|
+
}
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
pub fn log_error_with_stacktrace(&self, message: &str, stacktrace: &str) {
|
|
28
|
+
let formatted_status = self.format_status(LogLevel::Error);
|
|
29
|
+
println!("🦊 {} {} {}", self.language_signature(), formatted_status, message);
|
|
30
|
+
println!(" ↳ {}", stacktrace);
|
|
31
|
+
}
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
fn language_signature(&self) -> String {
|
|
34
|
+
let mut s = String::new();
|
|
24
35
|
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
write!(&mut s, "{}", SetForegroundColor(Color::Grey)).unwrap();
|
|
37
|
+
s.push('[');
|
|
38
|
+
|
|
39
|
+
write!(&mut s, "{}", SetForegroundColor(Color::Rgb { r: 29, g: 211, b: 176 })).unwrap();
|
|
40
|
+
write!(&mut s, "{}", SetAttribute(Attribute::Bold)).unwrap();
|
|
41
|
+
s.push_str("Devalang");
|
|
42
|
+
write!(&mut s, "{}", SetAttribute(Attribute::Reset)).unwrap();
|
|
43
|
+
|
|
44
|
+
write!(&mut s, "{}", SetForegroundColor(Color::Grey)).unwrap();
|
|
45
|
+
s.push(']');
|
|
46
|
+
|
|
47
|
+
write!(&mut s, "{}", ResetColor).unwrap();
|
|
48
|
+
|
|
49
|
+
s
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fn format_status(&self, level: LogLevel) -> String {
|
|
53
|
+
let mut s = String::new();
|
|
27
54
|
|
|
28
|
-
|
|
29
|
-
|
|
55
|
+
let color = match level {
|
|
56
|
+
LogLevel::Success => Color::Rgb { r: 76, g: 175, b: 80 },
|
|
57
|
+
LogLevel::Error => Color::Rgb { r: 244, g: 67, b: 54 },
|
|
58
|
+
LogLevel::Info => Color::Rgb { r: 33, g: 150, b: 243 },
|
|
59
|
+
LogLevel::Warning => Color::Rgb { r: 255, g: 152, b: 0 },
|
|
60
|
+
LogLevel::Watcher => Color::Rgb { r: 156, g: 39, b: 176 },
|
|
61
|
+
LogLevel::Debug => Color::Rgb { r: 103, g: 58, b: 183 },
|
|
62
|
+
};
|
|
30
63
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
64
|
+
let status = match level {
|
|
65
|
+
LogLevel::Success => "SUCCESS",
|
|
66
|
+
LogLevel::Error => "ERROR",
|
|
67
|
+
LogLevel::Info => "INFO",
|
|
68
|
+
LogLevel::Warning => "WARNING",
|
|
69
|
+
LogLevel::Watcher => "WATCHER",
|
|
70
|
+
LogLevel::Debug => "DEBUG",
|
|
71
|
+
};
|
|
38
72
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
73
|
+
s.push('[');
|
|
74
|
+
write!(&mut s, "{}", SetForegroundColor(color)).unwrap();
|
|
75
|
+
write!(&mut s, "{}", SetAttribute(Attribute::Bold)).unwrap();
|
|
76
|
+
s.push_str(status);
|
|
77
|
+
write!(&mut s, "{}", SetAttribute(Attribute::Reset)).unwrap();
|
|
78
|
+
s.push(']');
|
|
45
79
|
|
|
46
|
-
|
|
80
|
+
write!(&mut s, "{}", ResetColor).unwrap();
|
|
47
81
|
|
|
48
|
-
|
|
82
|
+
s
|
|
83
|
+
}
|
|
49
84
|
}
|
package/rust/utils/mod.rs
CHANGED
package/rust/audio/mod.rs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// TODO Audio engine
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
use crate::core::types::token::{ Token, TokenKind };
|
|
2
|
-
|
|
3
|
-
pub fn handle_rbracket_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::RBracket,
|
|
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_lbracket_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::LBracket,
|
|
34
|
-
lexeme: char.to_string(),
|
|
35
|
-
line: *line,
|
|
36
|
-
column: *column,
|
|
37
|
-
indent: *current_indent,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
*column += 1;
|
|
41
|
-
}
|
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
use crate::core::{
|
|
4
|
-
lexer::{
|
|
5
|
-
at::handle_at_lexer,
|
|
6
|
-
brace::{ handle_lbrace_lexer, handle_rbrace_lexer },
|
|
7
|
-
colon::handle_colon_lexer,
|
|
8
|
-
comment::handle_comment_lexer,
|
|
9
|
-
equal::handle_equal_lexer,
|
|
10
|
-
newline::handle_newline_lexer,
|
|
11
|
-
bracket::{ handle_lbracket_lexer, handle_rbracket_lexer },
|
|
12
|
-
dot::handle_dot_lexer,
|
|
13
|
-
identifier::handle_identifier_lexer,
|
|
14
|
-
indent::handle_indent_lexer,
|
|
15
|
-
number::handle_number_lexer,
|
|
16
|
-
quote::{ handle_double_quote_lexer, handle_single_quote_lexer },
|
|
17
|
-
},
|
|
18
|
-
types::token::{ Token, TokenKind },
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
pub fn lex(input: String) -> Vec<Token> {
|
|
22
|
-
let mut tokens = Vec::new();
|
|
23
|
-
|
|
24
|
-
let mut line = 1;
|
|
25
|
-
let mut column = 1;
|
|
26
|
-
|
|
27
|
-
let mut indent_stack: Vec<usize> = vec![0];
|
|
28
|
-
let mut current_indent = 0;
|
|
29
|
-
let mut at_line_start = true;
|
|
30
|
-
|
|
31
|
-
let mut chars = input.chars().peekable();
|
|
32
|
-
|
|
33
|
-
while let Some(_) = chars.peek() {
|
|
34
|
-
if at_line_start {
|
|
35
|
-
let (new_tokens, new_indent_stack, new_line, new_column) = handle_indent_lexer(
|
|
36
|
-
&mut chars,
|
|
37
|
-
&mut current_indent,
|
|
38
|
-
&mut indent_stack,
|
|
39
|
-
&mut tokens,
|
|
40
|
-
&mut line,
|
|
41
|
-
&mut column
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Update the main tokens vector and indent stack
|
|
45
|
-
tokens = new_tokens;
|
|
46
|
-
indent_stack = new_indent_stack;
|
|
47
|
-
line = new_line;
|
|
48
|
-
column = new_column;
|
|
49
|
-
|
|
50
|
-
// Reset at_line_start flag
|
|
51
|
-
at_line_start = false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Read the next character
|
|
55
|
-
let Some(ch) = chars.next() else {
|
|
56
|
-
break;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// Newline handling
|
|
60
|
-
if ch == '\n' {
|
|
61
|
-
handle_newline_lexer(
|
|
62
|
-
ch,
|
|
63
|
-
&mut chars,
|
|
64
|
-
&mut tokens,
|
|
65
|
-
&mut line,
|
|
66
|
-
&mut column,
|
|
67
|
-
&mut at_line_start,
|
|
68
|
-
&mut current_indent
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if ch == ' ' || ch == '\t' {
|
|
75
|
-
column += if ch == '\t' { 4 } else { 1 };
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if ch == '#' {
|
|
80
|
-
handle_comment_lexer(
|
|
81
|
-
ch,
|
|
82
|
-
&mut chars,
|
|
83
|
-
&mut current_indent,
|
|
84
|
-
&mut indent_stack,
|
|
85
|
-
&mut tokens,
|
|
86
|
-
&mut line,
|
|
87
|
-
&mut column
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if ch == ':' {
|
|
94
|
-
handle_colon_lexer(
|
|
95
|
-
ch,
|
|
96
|
-
&mut chars,
|
|
97
|
-
&mut current_indent,
|
|
98
|
-
&mut indent_stack,
|
|
99
|
-
&mut tokens,
|
|
100
|
-
&mut line,
|
|
101
|
-
&mut column
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if ch == '=' {
|
|
108
|
-
handle_equal_lexer(
|
|
109
|
-
ch,
|
|
110
|
-
&mut chars,
|
|
111
|
-
&mut current_indent,
|
|
112
|
-
&mut indent_stack,
|
|
113
|
-
&mut tokens,
|
|
114
|
-
&mut line,
|
|
115
|
-
&mut column
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if ch == '[' {
|
|
122
|
-
handle_lbracket_lexer(
|
|
123
|
-
ch,
|
|
124
|
-
&mut chars,
|
|
125
|
-
&mut current_indent,
|
|
126
|
-
&mut indent_stack,
|
|
127
|
-
&mut tokens,
|
|
128
|
-
&mut line,
|
|
129
|
-
&mut column
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if ch == ']' {
|
|
136
|
-
handle_rbracket_lexer(
|
|
137
|
-
ch,
|
|
138
|
-
&mut chars,
|
|
139
|
-
&mut current_indent,
|
|
140
|
-
&mut indent_stack,
|
|
141
|
-
&mut tokens,
|
|
142
|
-
&mut line,
|
|
143
|
-
&mut column
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if ch == '{' {
|
|
150
|
-
handle_lbrace_lexer(
|
|
151
|
-
ch,
|
|
152
|
-
&mut chars,
|
|
153
|
-
&mut current_indent,
|
|
154
|
-
&mut indent_stack,
|
|
155
|
-
&mut tokens,
|
|
156
|
-
&mut line,
|
|
157
|
-
&mut column
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if ch == '}' {
|
|
164
|
-
handle_rbrace_lexer(
|
|
165
|
-
ch,
|
|
166
|
-
&mut chars,
|
|
167
|
-
&mut current_indent,
|
|
168
|
-
&mut indent_stack,
|
|
169
|
-
&mut tokens,
|
|
170
|
-
&mut line,
|
|
171
|
-
&mut column
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if ch == '"' {
|
|
178
|
-
handle_double_quote_lexer(
|
|
179
|
-
ch,
|
|
180
|
-
&mut chars,
|
|
181
|
-
&mut current_indent,
|
|
182
|
-
&mut indent_stack,
|
|
183
|
-
&mut tokens,
|
|
184
|
-
&mut line,
|
|
185
|
-
&mut column
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if ch == '\'' {
|
|
192
|
-
handle_single_quote_lexer(
|
|
193
|
-
ch,
|
|
194
|
-
&mut chars,
|
|
195
|
-
&mut current_indent,
|
|
196
|
-
&mut indent_stack,
|
|
197
|
-
&mut tokens,
|
|
198
|
-
&mut line,
|
|
199
|
-
&mut column
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if ch == '.' {
|
|
206
|
-
handle_dot_lexer(
|
|
207
|
-
ch,
|
|
208
|
-
&mut chars,
|
|
209
|
-
&mut current_indent,
|
|
210
|
-
&mut indent_stack,
|
|
211
|
-
&mut tokens,
|
|
212
|
-
&mut line,
|
|
213
|
-
&mut column
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if ch == '@' {
|
|
220
|
-
handle_at_lexer(
|
|
221
|
-
ch,
|
|
222
|
-
&mut chars,
|
|
223
|
-
&mut current_indent,
|
|
224
|
-
&mut indent_stack,
|
|
225
|
-
&mut tokens,
|
|
226
|
-
&mut line,
|
|
227
|
-
&mut column
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if ch.is_ascii_digit() {
|
|
234
|
-
handle_number_lexer(
|
|
235
|
-
ch,
|
|
236
|
-
&mut chars,
|
|
237
|
-
&mut current_indent,
|
|
238
|
-
&mut indent_stack,
|
|
239
|
-
&mut tokens,
|
|
240
|
-
&mut line,
|
|
241
|
-
&mut column
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if ch.is_ascii_alphabetic() {
|
|
248
|
-
handle_identifier_lexer(
|
|
249
|
-
ch,
|
|
250
|
-
&mut chars,
|
|
251
|
-
&mut current_indent,
|
|
252
|
-
&mut indent_stack,
|
|
253
|
-
&mut tokens,
|
|
254
|
-
&mut line,
|
|
255
|
-
&mut column
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// Skip unknown char
|
|
262
|
-
column += 1;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
while indent_stack.len() > 1 {
|
|
266
|
-
indent_stack.pop();
|
|
267
|
-
current_indent = *indent_stack.last().unwrap();
|
|
268
|
-
tokens.push(Token {
|
|
269
|
-
kind: TokenKind::Dedent,
|
|
270
|
-
lexeme: String::new(),
|
|
271
|
-
line,
|
|
272
|
-
column,
|
|
273
|
-
indent: current_indent,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
tokens.push(Token {
|
|
278
|
-
kind: TokenKind::EOF,
|
|
279
|
-
lexeme: String::new(),
|
|
280
|
-
line: line + 1, // EOF is considered to be on the next line
|
|
281
|
-
column: 0, // EOF has no column
|
|
282
|
-
indent: 0, // EOF has no indent
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
tokens
|
|
286
|
-
}
|
package/rust/core/lexer/quote.rs
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
use crate::core::types::token::{Token, TokenKind};
|
|
2
|
-
|
|
3
|
-
pub fn handle_single_quote_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 string_content = String::new();
|
|
13
|
-
*column += 1;
|
|
14
|
-
|
|
15
|
-
while let Some(next_ch) = chars.next() {
|
|
16
|
-
*column += 1;
|
|
17
|
-
if next_ch == '\'' {
|
|
18
|
-
break;
|
|
19
|
-
} else {
|
|
20
|
-
string_content.push(next_ch);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
tokens.push(Token {
|
|
25
|
-
kind: TokenKind::String,
|
|
26
|
-
lexeme: string_content,
|
|
27
|
-
line: *line,
|
|
28
|
-
column: *column,
|
|
29
|
-
indent: *current_indent,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
pub fn handle_double_quote_lexer(
|
|
34
|
-
char: char,
|
|
35
|
-
chars: &mut std::iter::Peekable<std::str::Chars>,
|
|
36
|
-
current_indent: &mut usize,
|
|
37
|
-
indent_stack: &mut Vec<usize>,
|
|
38
|
-
tokens: &mut Vec<Token>,
|
|
39
|
-
line: &mut usize,
|
|
40
|
-
column: &mut usize
|
|
41
|
-
) {
|
|
42
|
-
let mut string_content = String::new();
|
|
43
|
-
*column += 1; // skip the opening quote
|
|
44
|
-
|
|
45
|
-
while let Some(next_ch) = chars.next() {
|
|
46
|
-
*column += 1;
|
|
47
|
-
if next_ch == '"' {
|
|
48
|
-
break; // closing quote reached
|
|
49
|
-
} else {
|
|
50
|
-
string_content.push(next_ch);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
tokens.push(Token {
|
|
55
|
-
kind: TokenKind::String,
|
|
56
|
-
lexeme: string_content,
|
|
57
|
-
line: *line,
|
|
58
|
-
column: *column,
|
|
59
|
-
indent: *current_indent,
|
|
60
|
-
});
|
|
61
|
-
}
|