1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

fix: fix string being splitted

This commit is contained in:
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
}