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

View file

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

View file

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