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:
parent
6e674fdaa6
commit
8d88fc41ad
12
README.md
12
README.md
|
@ -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.
|
|
@ -1,2 +1,2 @@
|
||||||
(print "hi")
|
(print "hi")
|
||||||
(print "hello")
|
(print "Hello, World!")
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
Loading…
Reference in a new issue