diff --git a/Cargo.lock b/Cargo.lock index 7e76af9..9ab4369 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,73 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "bit-set" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "fancy-regex" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d6b8560a05112eb52f04b00e5d3790c0dd75d9d980eb8a122fb23b92a623ccf" +dependencies = [ + "bit-set", + "regex", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + [[package]] name = "strath" version = "0.1.0" +dependencies = [ + "fancy-regex", + "lazy_static", +] diff --git a/Cargo.toml b/Cargo.toml index 5851181..7659b21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +lazy_static="1.4.0" +fancy-regex="0.7.1" diff --git a/sm-test-files/actual-testing/io.sm b/sm-test-files/actual-testing/io.sm index e13b8e7..ee87a13 100644 --- a/sm-test-files/actual-testing/io.sm +++ b/sm-test-files/actual-testing/io.sm @@ -3,7 +3,7 @@ ¡<= /"Hello world!"\! -¡<= ]] inline comment example [[ /"inline cmmnts work"\! +¡<= ]] inline comment example [[ /"inline comments work"\! `` big ass block comment! @@ -19,7 +19,3 @@ && log out ¡<= /out\! - - - - diff --git a/src/main.rs b/src/main.rs index ccce34f..fe0c251 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ fn main() { println!("{:?}", preprocessor::preprocess(file)); } -fn parse_and_interpret(code: String) { +//fn parse_and_interpret(code: String) { -} +//} diff --git a/src/preprocessor.rs b/src/preprocessor.rs index ee0f7dc..ee88588 100644 --- a/src/preprocessor.rs +++ b/src/preprocessor.rs @@ -1,5 +1,28 @@ -pub fn preprocess(raw_code: String) -> String { - let lines = raw_code.split(' '); - for &line in lines { +use lazy_static::lazy_static; +use fancy_regex::Regex; + +pub fn preprocess(raw_code: String) { + lazy_static! { + static ref COMMENT_RE: Regex = Regex::new(r"(\]\].*?\[\[|&&.*\n|``(.|\n)*?´´)").unwrap(); } + + let code = COMMENT_RE.replace_all(&raw_code, ""); + let code = remove_empty_lines(code.to_string()); + println!("{}", &code) } + +pub fn remove_empty_lines(text: String) -> String { + let text: Vec<&str> = text.split('\n').collect(); + + let mut out = String::new(); + for line in text { + if !line.trim().is_empty() { + out += line; + out.push('\n'); + } + } + + out +} + +