mirror of
https://github.com/MeexReay/sustlang.git
synced 2025-06-24 10:33:01 +03:00
tabs and
This commit is contained in:
parent
e02528b2f1
commit
842ef24a60
40
src/lib.rs
40
src/lib.rs
@ -956,7 +956,13 @@ fn prepare_script(text: String) -> Vec<String> {
|
||||
Some(s) => s.0,
|
||||
None => s,
|
||||
})
|
||||
.map(|s| s.trim_end_matches(" ").to_string())
|
||||
.map(|s| {
|
||||
s.trim_end_matches(" ")
|
||||
.trim_end_matches("\t")
|
||||
.trim_start_matches(" ")
|
||||
.trim_start_matches("\t")
|
||||
.to_string()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -1226,6 +1232,8 @@ impl RunningScript {
|
||||
let mut var: Option<&mut Variable> = None;
|
||||
let parts: Vec<&str> = name.split('.').collect();
|
||||
|
||||
let global = global || (self.variables.contains_key(&name) && !locals.contains_key(&name));
|
||||
|
||||
if parts.len() == 1 {
|
||||
if global {
|
||||
self.variables.insert(name, value);
|
||||
@ -1457,6 +1465,21 @@ impl RunningScript {
|
||||
CommandType::Return => {
|
||||
return Ok(());
|
||||
}
|
||||
CommandType::For => {
|
||||
let func_name = command.args[0].clone();
|
||||
let start_index = self.get_var(command.args[1].clone(), locals)?.as_int()?;
|
||||
let end_index = self.get_var(command.args[2].clone(), locals)?.as_int()?;
|
||||
|
||||
let func = self.get_function(func_name).unwrap();
|
||||
|
||||
for index in start_index..=end_index {
|
||||
self.exec_function(
|
||||
func.clone(),
|
||||
"null".to_string(),
|
||||
vec![Variable::from_int(Some(index))],
|
||||
)?;
|
||||
}
|
||||
}
|
||||
CommandType::ToString => {}
|
||||
CommandType::ToBytes => {}
|
||||
CommandType::ToInteger => {}
|
||||
@ -1473,21 +1496,6 @@ impl RunningScript {
|
||||
CommandType::ReadAll => {}
|
||||
CommandType::ReadStr => {}
|
||||
CommandType::ReadStrAll => {}
|
||||
CommandType::For => {
|
||||
let func_name = command.args[0].clone();
|
||||
let start_index = self.get_var(command.args[1].clone(), locals)?.as_int()?;
|
||||
let end_index = self.get_var(command.args[2].clone(), locals)?.as_int()?;
|
||||
|
||||
let func = self.get_function(func_name).unwrap();
|
||||
|
||||
for index in start_index..=end_index {
|
||||
self.exec_function(
|
||||
func.clone(),
|
||||
"null".to_string(),
|
||||
vec![Variable::from_int(Some(index))],
|
||||
)?;
|
||||
}
|
||||
}
|
||||
CommandType::ForMap => {}
|
||||
CommandType::ForList => {}
|
||||
CommandType::While => {}
|
||||
|
12
src/main.rs
12
src/main.rs
@ -7,8 +7,16 @@ use std::{
|
||||
use sustlang::{RunningScript, Script};
|
||||
|
||||
fn main() {
|
||||
let script = Script::parse(fs::read_to_string("test.sus").unwrap()).unwrap();
|
||||
let args: Vec<String> = args().collect();
|
||||
|
||||
let filename = args[1].clone();
|
||||
let args = args[1..].to_vec();
|
||||
|
||||
let script = Script::parse(fs::read_to_string(filename).unwrap()).unwrap();
|
||||
|
||||
let mut running_script = RunningScript::new(script);
|
||||
running_script.set_standard_vars(args().collect(), Box::new(stdout()), Box::new(stdin()));
|
||||
running_script
|
||||
.set_standard_vars(args, Box::new(stdout()), Box::new(stdin()))
|
||||
.unwrap();
|
||||
running_script.run().unwrap();
|
||||
}
|
||||
|
23
test.sus
23
test.sus
@ -1,20 +1,21 @@
|
||||
FUNC null println text string # println command
|
||||
|
||||
TEMP_VAR char br 10 # line break var
|
||||
ADD_STR text br # add line break to text var
|
||||
WRITE text cout # write text var to console
|
||||
|
||||
TEMP_VAR char br 10 # line break var
|
||||
ADD_STR text br # add line break to text var
|
||||
WRITE text cout # write text var to console
|
||||
FUNC_END # end println command
|
||||
|
||||
FUNC null hello_world index integer
|
||||
USE_FUNC println null text
|
||||
FUNC_END
|
||||
|
||||
|
||||
|
||||
INIT_VAR string text
|
||||
SET_VAR text Hello World!
|
||||
|
||||
FUNC null hello_world index integer
|
||||
|
||||
USE_FUNC println null text
|
||||
|
||||
FUNC_END
|
||||
|
||||
TEMP_VAR integer start_index 0
|
||||
TEMP_VAR integer end_index 9
|
||||
|
||||
FOR hello_world start_index end_index
|
||||
|
||||
DROP_VAR text
|
||||
|
Loading…
x
Reference in New Issue
Block a user