diff --git a/Cargo.lock b/Cargo.lock index cbe05d0..38ed37d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ checksum = "b03f7fbd470aa8b3ad163c85cce8bccfc11cc9c44ef12da0a4eddd98bd307352" [[package]] name = "spl" -version = "0.1.8" +version = "0.2.1" dependencies = [ "multicall", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 932c5c7..2ac41d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spl" -version = "0.2.1" +version = "0.2.2" edition = "2021" description = "Stack Pogramming Language: A simple, concise scripting language." license = "MIT" diff --git a/iter.spl b/iter.spl index be56ef5..341c3ea 100644 --- a/iter.spl +++ b/iter.spl @@ -210,6 +210,7 @@ construct EnumerationIter { ; construct { this | with origin this ; origin this:=origin + 0 this:=idx this } next { [mega,any]|null | with this ; diff --git a/src/lexer.rs b/src/lexer.rs index e2501ff..d4cb88a 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -181,7 +181,6 @@ fn read_block(str_words: &[String], isfn: bool) -> Result<(Option, Words, u } let blk = read_block(&str_words[i + 1..], false)?; i += 2 + blk.2; - println!("{} {}", str_words[i], str_words[i+1]); let ctch = read_block(&str_words[i + 1..], false)?; i += 1 + ctch.2; words.push(Word::Key(Keyword::Catch(types, blk.1, ctch.1))) diff --git a/src/std_fns.rs b/src/std_fns.rs index 2a88a89..a243769 100644 --- a/src/std_fns.rs +++ b/src/std_fns.rs @@ -447,7 +447,7 @@ pub fn to_str(stack: &mut Stack) -> OError { )) }), _ => stack.err(ErrorKind::InvalidType( - "int".to_owned(), + "?".to_owned(), "__str-element".to_owned(), )), }) diff --git a/std.spl b/std.spl index 3301255..0ab3f48 100644 --- a/std.spl +++ b/std.spl @@ -56,6 +56,29 @@ construct _str_ext { ] _str } ] } + replace { str | with replacee replacement this ; + def bytes replacee:to-bytes =bytes + def iter this:to-bytes:iter =iter + def item 0 =item + [ while { item null eq not } { + def match 0 =match + while { match bytes:len eq not } { + iter:next =item + item null eq if { + 3 stop + } + item dup (match bytes:get) eq dup if { + match ++ =match + } not if { + 0 =match + } + } + { | pop pop } match:foreach + match bytes:len eq if { + replacement _array :to-stack + } + } ] _str + } } include _str_ext in str construct _mega-ext {