replace function <{ args } with function<args>
This commit is contained in:
parent
2574165cd1
commit
89e6eff198
5 changed files with 49 additions and 15 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -22,7 +22,7 @@ checksum = "b03f7fbd470aa8b3ad163c85cce8bccfc11cc9c44ef12da0a4eddd98bd307352"
|
|||
|
||||
[[package]]
|
||||
name = "spl"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"multicall",
|
||||
"once_cell",
|
||||
|
|
32
src/lexer.rs
32
src/lexer.rs
|
@ -24,6 +24,15 @@ pub fn lex(compat: bool, input: String) -> Result<Words, LexerError> {
|
|||
fn read_block(
|
||||
str_words: &[String],
|
||||
isfn: bool,
|
||||
compat: bool,
|
||||
) -> Result<(Option<u32>, Words, usize), LexerError> {
|
||||
read_block_dyn(str_words, isfn, "}".to_owned(), compat)
|
||||
}
|
||||
|
||||
fn read_block_dyn(
|
||||
str_words: &[String],
|
||||
isfn: bool,
|
||||
endword: String,
|
||||
mut compat: bool,
|
||||
) -> Result<(Option<u32>, Words, usize), LexerError> {
|
||||
if str_words.is_empty() {
|
||||
|
@ -111,8 +120,8 @@ fn read_block(
|
|||
x if x.len() >= 2 && &x[0..2] == "!{" => {
|
||||
words.push(Word::Const(Value::Str(x[2..].to_owned())));
|
||||
}
|
||||
"<{" => {
|
||||
let block = read_block(&str_words[i + 1..], false, compat)?;
|
||||
"<" => {
|
||||
let block = read_block_dyn(&str_words[i + 1..], false, ">".to_owned(), compat)?;
|
||||
i += block.2 + 1;
|
||||
let mut block = block.1.words;
|
||||
match words.remove(words.len() - 1) {
|
||||
|
@ -227,7 +236,7 @@ fn read_block(
|
|||
}
|
||||
words.push(Word::Key(Keyword::With(vars)));
|
||||
}
|
||||
"}" => {
|
||||
x if x == endword => {
|
||||
break;
|
||||
}
|
||||
x if x.starts_with('\"') => {
|
||||
|
@ -286,7 +295,11 @@ fn read_block(
|
|||
Ok((rem, Words { words }, i))
|
||||
}
|
||||
|
||||
fn parse(input: String) -> Vec<String> {
|
||||
pub fn parse(mut input: String) -> Vec<String> {
|
||||
if input.starts_with("#!") {
|
||||
input = input.split_off(input.find('\n').expect("cannot have #! without newline"));
|
||||
}
|
||||
|
||||
let mut words = Vec::new();
|
||||
let mut s = String::new();
|
||||
|
||||
|
@ -346,6 +359,17 @@ fn parse(input: String) -> Vec<String> {
|
|||
if c == '(' || c == ')' {
|
||||
continue;
|
||||
}
|
||||
if c == '<' || c == '>' {
|
||||
if s.is_empty() {
|
||||
words.push(c.to_string());
|
||||
continue;
|
||||
}
|
||||
words.push(s);
|
||||
s = String::new();
|
||||
was_in_string = false;
|
||||
words.push(c.to_string());
|
||||
continue;
|
||||
}
|
||||
if c == ' ' || c == '\t' {
|
||||
if s.is_empty() {
|
||||
continue;
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -1,4 +1,6 @@
|
|||
use spl::{lex, oxidizer::RustAppBuilder, start_file_in_runtime, Runtime, SetRuntime};
|
||||
use spl::{
|
||||
lex, oxidizer::RustAppBuilder, sasm::sasm_write, start_file_in_runtime, Runtime, SetRuntime,
|
||||
};
|
||||
|
||||
use std::{env::args, fs};
|
||||
|
||||
|
@ -6,9 +8,14 @@ fn main() {
|
|||
Runtime::new().set();
|
||||
let mut args = args().skip(1);
|
||||
let arg = &args.next().unwrap_or("#repl.spl".to_owned());
|
||||
if arg == "--build" || arg == "--run" || arg == "--buildrun" {
|
||||
if arg == "--build" || arg == "--run" || arg == "--buildrun" || arg == "--debug" {
|
||||
let file = args.next().unwrap();
|
||||
let data = fs::read_to_string(file.clone()).expect("unable to read specified file");
|
||||
if arg == "--debug" {
|
||||
println!("words: {}", spl::parse(data.clone()).join(" "));
|
||||
println!("{}", sasm_write(lex(false, data).unwrap()));
|
||||
return;
|
||||
}
|
||||
let build_only = arg == "--build";
|
||||
if build_only {
|
||||
println!("Building SPL with specified natives file...");
|
||||
|
|
7
std.spl
7
std.spl
|
@ -82,6 +82,9 @@ construct _str_ext {
|
|||
starts-with { bool | with beginning this ;
|
||||
beginning:to-bytes this:to-bytes:starts-with
|
||||
}
|
||||
_char { int | with this ;
|
||||
0 (this _array):get
|
||||
}
|
||||
} include _str_ext in str
|
||||
|
||||
construct _mega-ext {
|
||||
|
@ -398,9 +401,9 @@ func concat { str | with a b ;
|
|||
|
||||
func nconcat { str | with amt ;
|
||||
_array
|
||||
(amt 1 -):foreach <{ { | pop
|
||||
(amt 1 -):foreach<{ | pop
|
||||
swap _array swap aadd
|
||||
} }
|
||||
}>
|
||||
_str
|
||||
}
|
||||
|
||||
|
|
12
test.spl
12
test.spl
|
@ -142,10 +142,10 @@ func main { int | with args ;
|
|||
|
||||
"testing messages" println
|
||||
def bus messaging:Bus:new =bus
|
||||
bus:subscribe <{ "testmsg1" { | with message ; message:name print " called1 1" println } }
|
||||
bus:subscribe <{ "testmsg1" { | with message ; message:name print " called1 2" println } }
|
||||
bus:subscribe <{ "testmsg2" { | with message ; message:name print " called2 1" println } }
|
||||
bus:subscribe <{ "testmsg2" { | with message ; message:name print " called2 2" println } }
|
||||
bus:subscribe<"testmsg1" { | with message ; message:name print " called1 1" println }>
|
||||
bus:subscribe<"testmsg1" { | with message ; message:name print " called1 2" println }>
|
||||
bus:subscribe<"testmsg2" { | with message ; message:name print " called2 1" println }>
|
||||
bus:subscribe<"testmsg2" { | with message ; message:name print " called2 2" println }>
|
||||
"testmsg1" bus:publish
|
||||
"testmsg2" bus:publish
|
||||
"testmsg1" bus:publish
|
||||
|
@ -154,7 +154,7 @@ func main { int | with args ;
|
|||
100
|
||||
}
|
||||
|
||||
func cached-test { mega | 1 "cached-test" cache <{ { mega | with i ;
|
||||
func cached-test { mega | 1 "cached-test" cache< { mega | with i ;
|
||||
i 2 *
|
||||
"calculated " i _str concat println
|
||||
} } }
|
||||
}>}
|
||||
|
|
Loading…
Add table
Reference in a new issue