fix: fix string being splitted

replace/7746dba3cc6b3860afe1faf69e86ed84ee46988d
Natapat Samutpong 2022-01-24 04:49:27 +07:00
parent 6e674fdaa6
commit 8d88fc41ad
3 changed files with 15 additions and 15 deletions

View File

@ -2,30 +2,28 @@
another lisp dialect
```lisp
(fun factorial [x]
(fun factorial (x)
(if (<= x 1)
1
(* x (factorial (- x 1)))))
(def times 7)
(do
(print (factorial times)))
(print (factorial 7)))
```
Compliation flow:
```
Input(file) -> Lexer -> Parser -> Interpret
String Token Expr IO
|-> Compile(TODO)
File
Input(file) -> Parser -> Interpret(TODO)
String SExprs IO
|-> Compile(TODO)
File
```
Progress:
- [X] Lexer & Parser
- [ ] Syntax checker & Type checker
- [X] Interpreter
- [ ] Interpreter
- [ ] Compiler
Problems:
- Parser only detect the first error.
- Parser can't detect `(()))` syntax error.

View File

@ -1,2 +1,2 @@
(print "hi")
(print "hello")
(print "Hello, World!")

View File

@ -86,9 +86,11 @@ impl Parser {
}
pub fn tokenize(str: &str) -> Vec<String> {
str.replace("(", " ( ")
.replace(")", " ) ")
.split_whitespace()
.map(|s| s.to_string())
.collect()
let regex = Regex::new(r###"[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"?|;.*|[^\s\[\]{}('"`,;)]+)"###).unwrap();
let mut res = vec![];
for cap in regex.captures_iter(str) {
if cap[1].starts_with(";") { continue; }
res.push(String::from(&cap[1]));
}
res
}